@univerjs/sheets-find-replace 0.5.4 → 0.5.5-experimental.20250123-34738ff
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/facade.js +1 -1
- package/lib/cjs/index.js +1 -1
- package/lib/cjs/locale/en-US.js +1 -1
- package/lib/cjs/locale/fa-IR.js +1 -1
- package/lib/cjs/locale/fr-FR.js +1 -1
- package/lib/cjs/locale/ru-RU.js +1 -1
- package/lib/cjs/locale/vi-VN.js +1 -1
- package/lib/cjs/locale/zh-CN.js +1 -1
- package/lib/cjs/locale/zh-TW.js +1 -1
- package/lib/es/facade.js +73 -70
- package/lib/es/index.js +434 -416
- package/lib/es/locale/en-US.js +2 -2
- package/lib/es/locale/fa-IR.js +2 -2
- package/lib/es/locale/fr-FR.js +2 -2
- package/lib/es/locale/ru-RU.js +2 -2
- package/lib/es/locale/vi-VN.js +2 -2
- package/lib/es/locale/zh-CN.js +2 -2
- package/lib/es/locale/zh-TW.js +2 -2
- package/lib/types/facade/f-text-finder.d.ts +1 -0
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/lib/umd/locale/en-US.js +1 -1
- package/lib/umd/locale/fa-IR.js +1 -1
- package/lib/umd/locale/fr-FR.js +1 -1
- package/lib/umd/locale/ru-RU.js +1 -1
- package/lib/umd/locale/vi-VN.js +1 -1
- package/lib/umd/locale/zh-CN.js +1 -1
- package/lib/umd/locale/zh-TW.js +1 -1
- package/package.json +8 -8
- package/LICENSE +0 -176
- package/lib/types/controllers/__tests__/utils.spec.d.ts +0 -16
package/lib/es/index.js
CHANGED
|
@@ -1,127 +1,138 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
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 { CommandType, IUndoRedoService, ICommandService, Rectangle, Inject, Injector, ThemeService, Disposable, EDITOR_ACTIVATED, IContextService, IUniverInstanceService, UniverInstanceType, fromCallback, ColorKit, rotate, groupBy, ObjectMatrix, Tools, replaceInDocumentBody, DependentOn, Plugin, merge as merge$1, IConfigService } from "@univerjs/core";
|
|
6
|
+
import { FindReplaceController, IFindReplaceService, FindModel, FindBy, FindScope, FindDirection, UniverFindReplacePlugin } from "@univerjs/find-replace";
|
|
7
|
+
import { SetRangeValuesCommand, SheetsSelectionsService, SetWorksheetActiveOperation, SetSelectionsOperation, SetWorksheetActivateCommand, UniverSheetsPlugin } from "@univerjs/sheets";
|
|
8
|
+
import { Shape, Rect, IRenderManagerService, RENDER_RAW_FORMULA_KEY } from "@univerjs/engine-render";
|
|
9
|
+
import { SheetSkeletonManagerService, getCoordByCell, getSheetObject, ScrollToCellCommand } from "@univerjs/sheets-ui";
|
|
10
|
+
import { filter, Subject, throttleTime, merge, skip, debounceTime } from "rxjs";
|
|
11
|
+
const SHEETS_FIND_REPLACE_PLUGIN_CONFIG_KEY = "sheets-find-replace.config", defaultPluginConfig = {}, SheetReplaceCommand = {
|
|
11
12
|
id: "sheet.command.replace",
|
|
12
|
-
type:
|
|
13
|
-
handler: async (
|
|
14
|
-
const
|
|
15
|
-
unitId
|
|
16
|
-
subUnitId:
|
|
17
|
-
value:
|
|
13
|
+
type: CommandType.COMMAND,
|
|
14
|
+
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
15
|
+
const undoRedoService = accessor.get(IUndoRedoService), commandService = accessor.get(ICommandService), { unitId, replacements } = params, disposeBatchingHandler = undoRedoService.__tempBatchingUndoRedo(unitId), results = await Promise.all(replacements.map((replacement) => commandService.executeCommand(SetRangeValuesCommand.id, {
|
|
16
|
+
unitId,
|
|
17
|
+
subUnitId: replacement.subUnitId,
|
|
18
|
+
value: replacement.value
|
|
18
19
|
})));
|
|
19
|
-
return
|
|
20
|
-
}
|
|
20
|
+
return disposeBatchingHandler.dispose(), getReplaceAllResult(results, replacements);
|
|
21
|
+
}, "handler")
|
|
21
22
|
};
|
|
22
|
-
function
|
|
23
|
-
let
|
|
24
|
-
return
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
}), { success
|
|
23
|
+
function getReplaceAllResult(results, replacements) {
|
|
24
|
+
let success = 0, failure = 0;
|
|
25
|
+
return results.forEach((r, index) => {
|
|
26
|
+
const count = replacements[index].count;
|
|
27
|
+
r ? success += count : failure += count;
|
|
28
|
+
}), { success, failure };
|
|
28
29
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
30
|
+
__name(getReplaceAllResult, "getReplaceAllResult");
|
|
31
|
+
const _SheetFindReplaceHighlightShape = class _SheetFindReplaceHighlightShape extends Shape {
|
|
32
|
+
constructor(key, props) {
|
|
33
|
+
super(key, props);
|
|
34
|
+
__publicField(this, "_activated", !1);
|
|
35
|
+
__publicField(this, "_inHiddenRange", !1);
|
|
36
|
+
__publicField(this, "_color");
|
|
37
|
+
props && this.setShapeProps(props);
|
|
38
|
+
}
|
|
39
|
+
setShapeProps(props) {
|
|
40
|
+
this._activated = !!props.activated, typeof props.inHiddenRange < "u" && (this._inHiddenRange = props.inHiddenRange), typeof props.color < "u" && (this._color = props.color), this.transformByState({
|
|
41
|
+
width: props.width,
|
|
42
|
+
height: props.height
|
|
41
43
|
});
|
|
42
44
|
}
|
|
43
|
-
_draw(
|
|
44
|
-
const
|
|
45
|
-
|
|
45
|
+
_draw(ctx) {
|
|
46
|
+
const activated = this._activated, color = `rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 0.35)`, borderColor = `rgb(${this._color.r}, ${this._color.g}, ${this._color.b})`;
|
|
47
|
+
Rect.drawWith(ctx, {
|
|
46
48
|
width: this.width,
|
|
47
49
|
height: this.height,
|
|
48
|
-
fill:
|
|
49
|
-
stroke:
|
|
50
|
-
strokeWidth:
|
|
50
|
+
fill: color,
|
|
51
|
+
stroke: activated ? borderColor : void 0,
|
|
52
|
+
strokeWidth: activated ? 2 : 0,
|
|
51
53
|
evented: !1
|
|
52
54
|
});
|
|
53
55
|
}
|
|
56
|
+
};
|
|
57
|
+
__name(_SheetFindReplaceHighlightShape, "SheetFindReplaceHighlightShape");
|
|
58
|
+
let SheetFindReplaceHighlightShape = _SheetFindReplaceHighlightShape;
|
|
59
|
+
function isSamePosition(range1, range2) {
|
|
60
|
+
return range1.startRow === range2.startRow && range1.startColumn === range2.startColumn;
|
|
54
61
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
function K(h, e) {
|
|
59
|
-
return h.startRow < e.startRow || h.startRow === e.startRow && h.startColumn <= e.startColumn;
|
|
62
|
+
__name(isSamePosition, "isSamePosition");
|
|
63
|
+
function isBehindPositionWithRowPriority(range1, range2) {
|
|
64
|
+
return range1.startRow < range2.startRow || range1.startRow === range2.startRow && range1.startColumn <= range2.startColumn;
|
|
60
65
|
}
|
|
61
|
-
|
|
62
|
-
|
|
66
|
+
__name(isBehindPositionWithRowPriority, "isBehindPositionWithRowPriority");
|
|
67
|
+
function isBehindPositionWithColumnPriority(range1, range2) {
|
|
68
|
+
return range1.startColumn < range2.startColumn || range1.startColumn === range2.startColumn && range1.startRow <= range2.startRow;
|
|
63
69
|
}
|
|
64
|
-
|
|
65
|
-
|
|
70
|
+
__name(isBehindPositionWithColumnPriority, "isBehindPositionWithColumnPriority");
|
|
71
|
+
function isBeforePositionWithRowPriority(range1, range2) {
|
|
72
|
+
return range1.startRow > range2.startRow || range1.startRow === range2.startRow && range1.startColumn >= range2.startColumn;
|
|
66
73
|
}
|
|
67
|
-
|
|
68
|
-
|
|
74
|
+
__name(isBeforePositionWithRowPriority, "isBeforePositionWithRowPriority");
|
|
75
|
+
function isBeforePositionWithColumnPriority(range1, range2) {
|
|
76
|
+
return range1.startColumn > range2.startColumn || range1.startColumn === range2.startColumn && range1.startRow >= range2.startRow;
|
|
69
77
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
78
|
+
__name(isBeforePositionWithColumnPriority, "isBeforePositionWithColumnPriority");
|
|
79
|
+
function isSelectionSingleCell(selection, worksheet) {
|
|
80
|
+
const { range } = selection, { startRow, startColumn } = range, hasMergedCell = worksheet.getMergedCell(startRow, startColumn);
|
|
81
|
+
return hasMergedCell ? Rectangle.equals(range, hasMergedCell) : range.endRow === range.startRow && range.endColumn === range.startColumn;
|
|
73
82
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
83
|
+
__name(isSelectionSingleCell, "isSelectionSingleCell");
|
|
84
|
+
var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
85
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
86
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
87
|
+
return kind && result && __defProp$1(target, key, result), result;
|
|
88
|
+
}, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1"), _a;
|
|
89
|
+
let SheetsFindReplaceController = (_a = class extends Disposable {
|
|
90
|
+
constructor(_injector, _findReplaceController, _contextService, _findReplaceService, _commandService) {
|
|
81
91
|
super();
|
|
82
|
-
|
|
83
|
-
this._injector =
|
|
92
|
+
__publicField(this, "_provider");
|
|
93
|
+
this._injector = _injector, this._findReplaceController = _findReplaceController, this._contextService = _contextService, this._findReplaceService = _findReplaceService, this._commandService = _commandService, this._init(), this._initCommands();
|
|
84
94
|
}
|
|
85
95
|
dispose() {
|
|
86
96
|
super.dispose(), this._findReplaceController.closePanel(), this._provider.dispose();
|
|
87
97
|
}
|
|
88
98
|
_init() {
|
|
89
|
-
const
|
|
90
|
-
this._provider =
|
|
99
|
+
const provider = this._injector.createInstance(SheetsFindReplaceProvider);
|
|
100
|
+
this._provider = provider, this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(provider)), this.disposeWithMe(this._contextService.subscribeContextValue$(EDITOR_ACTIVATED).pipe(filter((v) => !!v)).subscribe(() => this._findReplaceController.closePanel()));
|
|
91
101
|
}
|
|
92
102
|
_initCommands() {
|
|
93
|
-
[
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
],
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
103
|
+
[SheetReplaceCommand].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
|
|
104
|
+
}
|
|
105
|
+
}, __name(_a, "SheetsFindReplaceController"), _a);
|
|
106
|
+
SheetsFindReplaceController = __decorateClass$1([
|
|
107
|
+
__decorateParam$1(0, Inject(Injector)),
|
|
108
|
+
__decorateParam$1(1, Inject(FindReplaceController)),
|
|
109
|
+
__decorateParam$1(2, IContextService),
|
|
110
|
+
__decorateParam$1(3, IFindReplaceService),
|
|
111
|
+
__decorateParam$1(4, ICommandService)
|
|
112
|
+
], SheetsFindReplaceController);
|
|
113
|
+
const SHEETS_FIND_REPLACE_PROVIDER_NAME = "sheets-find-replace-provider", FIND_REPLACE_Z_INDEX = 1e4;
|
|
114
|
+
var _a2;
|
|
115
|
+
let SheetFindModel = (_a2 = class extends FindModel {
|
|
116
|
+
constructor(_workbook, _sheetSkeletonManagerService, _univerInstanceService, _renderManagerService, _commandService, _contextService, _themeService, _selectionManagerService) {
|
|
106
117
|
super();
|
|
107
118
|
// We can directly inject the `FindReplaceService` here, and call its methods instead of using the observables.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
119
|
+
__publicField(this, "_matchesUpdate$", new Subject());
|
|
120
|
+
__publicField(this, "matchesUpdate$", this._matchesUpdate$.asObservable());
|
|
121
|
+
__publicField(this, "_activelyChangingMatch$", new Subject());
|
|
122
|
+
__publicField(this, "activelyChangingMatch$", this._activelyChangingMatch$.asObservable());
|
|
112
123
|
/** Hold matches by the worksheet they are in. Make it easier to track the next (or previous) match when searching in the whole workbook. */
|
|
113
|
-
|
|
124
|
+
__publicField(this, "_matchesByWorksheet", /* @__PURE__ */ new Map());
|
|
114
125
|
/** Hold all matches in the currently searching scope. */
|
|
115
|
-
|
|
126
|
+
__publicField(this, "_matches", []);
|
|
116
127
|
/** Position of the current focused ISheetCellMatch, starting from 1. */
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
128
|
+
__publicField(this, "_matchesPosition", 0);
|
|
129
|
+
__publicField(this, "_activeHighlightIndex", -1);
|
|
130
|
+
__publicField(this, "_highlightShapes", []);
|
|
131
|
+
__publicField(this, "_currentHighlightShape", null);
|
|
121
132
|
/** This properties holds the query params during this searching session. */
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
this._workbook =
|
|
133
|
+
__publicField(this, "_query", null);
|
|
134
|
+
__publicField(this, "_workbookSelections");
|
|
135
|
+
this._workbook = _workbook, this._sheetSkeletonManagerService = _sheetSkeletonManagerService, this._univerInstanceService = _univerInstanceService, this._renderManagerService = _renderManagerService, this._commandService = _commandService, this._contextService = _contextService, this._themeService = _themeService, this._workbookSelections = _selectionManagerService.getWorkbookSelections(this.unitId);
|
|
125
136
|
}
|
|
126
137
|
get _matchesCount() {
|
|
127
138
|
return this._matches.length;
|
|
@@ -144,475 +155,482 @@ let W = class extends Ue {
|
|
|
144
155
|
getMatches() {
|
|
145
156
|
return this._matches;
|
|
146
157
|
}
|
|
147
|
-
start(
|
|
148
|
-
switch (this._query =
|
|
149
|
-
case
|
|
150
|
-
this.findInWorkbook(
|
|
158
|
+
start(query) {
|
|
159
|
+
switch (this._query = query, query.findBy === FindBy.FORMULA ? this._toggleDisplayRawFormula(!0) : this._toggleDisplayRawFormula(!1), query.findScope) {
|
|
160
|
+
case FindScope.UNIT:
|
|
161
|
+
this.findInWorkbook(query);
|
|
151
162
|
break;
|
|
152
|
-
case
|
|
163
|
+
case FindScope.SUBUNIT:
|
|
153
164
|
default:
|
|
154
|
-
this.findInActiveWorksheet(
|
|
165
|
+
this.findInActiveWorksheet(query);
|
|
155
166
|
break;
|
|
156
167
|
}
|
|
157
168
|
}
|
|
158
|
-
_toggleDisplayRawFormula(
|
|
159
|
-
this._contextService.setContextValue(
|
|
169
|
+
_toggleDisplayRawFormula(force) {
|
|
170
|
+
this._contextService.setContextValue(RENDER_RAW_FORMULA_KEY, force);
|
|
160
171
|
}
|
|
161
172
|
/**
|
|
162
173
|
* Find all matches in the current workbook no matter which worksheet is activated.
|
|
163
174
|
* @param query the query object
|
|
164
175
|
* @returns the query complete event
|
|
165
176
|
*/
|
|
166
|
-
findInWorkbook(
|
|
167
|
-
const
|
|
168
|
-
let
|
|
169
|
-
const
|
|
170
|
-
const
|
|
171
|
-
const
|
|
172
|
-
return
|
|
177
|
+
findInWorkbook(query) {
|
|
178
|
+
const unitId = this._workbook.getUnitId();
|
|
179
|
+
let complete, firstSearch = !0;
|
|
180
|
+
const findInWorkbook = /* @__PURE__ */ __name(() => {
|
|
181
|
+
const allCompletes = this._workbook.getSheets().filter((worksheet) => !worksheet.isSheetHidden()).map((worksheet) => {
|
|
182
|
+
const complete2 = this._findInWorksheet(worksheet, query, unitId), sheetId = worksheet.getSheetId(), { results } = complete2;
|
|
183
|
+
return results.length ? this._matchesByWorksheet.set(sheetId, complete2.results) : this._matchesByWorksheet.delete(sheetId), complete2;
|
|
173
184
|
});
|
|
174
|
-
this._matches =
|
|
175
|
-
};
|
|
185
|
+
this._matches = allCompletes.map((c) => c.results).flat(), this._updateFindHighlight(), firstSearch ? (complete = { results: this._matches }, firstSearch = !1) : this._matchesUpdate$.next(this._matches);
|
|
186
|
+
}, "findInWorkbook");
|
|
176
187
|
return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(() => {
|
|
177
188
|
this._updateFindHighlight(), this._updateCurrentHighlightShape(this._activeHighlightIndex);
|
|
178
189
|
})), this.disposeWithMe(
|
|
179
|
-
|
|
180
|
-
const
|
|
181
|
-
if (!
|
|
190
|
+
fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(filter(([command, options]) => command.id === SetWorksheetActiveOperation.id && !(options != null && options.fromFindReplace))).subscribe(() => {
|
|
191
|
+
const activeSheet = this._workbook.getActiveSheet();
|
|
192
|
+
if (!activeSheet)
|
|
182
193
|
return;
|
|
183
|
-
const
|
|
184
|
-
this._matchesByWorksheet.has(
|
|
194
|
+
const activeSheetId = activeSheet.getSheetId();
|
|
195
|
+
this._matchesByWorksheet.has(activeSheetId) && this._findNextMatchOnActiveSheetChange(activeSheet);
|
|
185
196
|
})
|
|
186
197
|
), this.disposeWithMe(
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
([
|
|
198
|
+
fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(
|
|
199
|
+
filter(
|
|
200
|
+
([command]) => command.type === CommandType.MUTATION && command.params.unitId === this._workbook.getUnitId()
|
|
190
201
|
),
|
|
191
|
-
|
|
192
|
-
).subscribe(() =>
|
|
193
|
-
),
|
|
202
|
+
throttleTime(600, void 0, { leading: !1, trailing: !0 })
|
|
203
|
+
).subscribe(() => findInWorkbook())
|
|
204
|
+
), findInWorkbook(), complete;
|
|
194
205
|
}
|
|
195
206
|
/**
|
|
196
207
|
* This method is used in `findInWorkbook`. When the active sheet changes, this method helps to find the next match
|
|
197
208
|
* in the new worksheet.
|
|
198
209
|
*/
|
|
199
|
-
_findNextMatchOnActiveSheetChange(
|
|
200
|
-
let
|
|
201
|
-
const
|
|
202
|
-
|
|
210
|
+
_findNextMatchOnActiveSheetChange(activeSheet) {
|
|
211
|
+
let match, index, globalIndex = 0;
|
|
212
|
+
const matchesByWorksheet = this._matchesByWorksheet.get(activeSheet.getSheetId()), selections = this._workbookSelections.getCurrentSelections();
|
|
213
|
+
selections != null && selections.length ? ([match, globalIndex] = this._findNextMatchByRange(matchesByWorksheet, selections[0].range), index = matchesByWorksheet.findIndex((m) => m === match)) : (match = matchesByWorksheet[0], index = 0, globalIndex = this._matches.findIndex((m) => m === match)), this._matchesPosition = globalIndex + 1, this._activelyChangingMatch$.next(match), this._activeHighlightIndex = index, this._updateFindHighlight(), this._updateCurrentHighlightShape(index);
|
|
203
214
|
}
|
|
204
215
|
/**
|
|
205
216
|
* Find all matches (only) in the currently activated worksheet.
|
|
206
217
|
* @param query the query object
|
|
207
218
|
* @returns the query complete event
|
|
208
219
|
*/
|
|
209
|
-
findInActiveWorksheet(
|
|
210
|
-
const
|
|
211
|
-
var
|
|
212
|
-
const
|
|
213
|
-
if (!
|
|
214
|
-
const
|
|
215
|
-
return (
|
|
216
|
-
};
|
|
217
|
-
let
|
|
218
|
-
const
|
|
219
|
-
const
|
|
220
|
-
if (!
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
const
|
|
224
|
-
return this._matches =
|
|
225
|
-
};
|
|
220
|
+
findInActiveWorksheet(query) {
|
|
221
|
+
const unitId = this._workbook.getUnitId(), checkShouldFindInSelections = /* @__PURE__ */ __name(() => {
|
|
222
|
+
var _a5;
|
|
223
|
+
const currentWorksheet = this._workbook.getActiveSheet();
|
|
224
|
+
if (!currentWorksheet) return !1;
|
|
225
|
+
const currentSelections = this._workbookSelections.getCurrentSelections();
|
|
226
|
+
return (_a5 = currentSelections == null ? void 0 : currentSelections.some((selection) => !isSelectionSingleCell(selection, currentWorksheet))) != null ? _a5 : !1;
|
|
227
|
+
}, "checkShouldFindInSelections");
|
|
228
|
+
let complete, firstSearch = !0, findBySelections = !1;
|
|
229
|
+
const performFindInWorksheet = /* @__PURE__ */ __name(() => {
|
|
230
|
+
const currentWorksheet = this._workbook.getActiveSheet();
|
|
231
|
+
if (!currentWorksheet) return { results: [] };
|
|
232
|
+
const lastMatch = this.currentMatch;
|
|
233
|
+
findBySelections = checkShouldFindInSelections();
|
|
234
|
+
const currentSelections = this._workbookSelections.getCurrentSelections(), newComplete = findBySelections ? this._findInSelections(currentWorksheet, currentSelections, query, unitId) : this._findInWorksheet(currentWorksheet, query, unitId);
|
|
235
|
+
return this._matches = newComplete.results, this._matchesPosition = this._tryRestoreLastMatchesPosition(lastMatch, this._matches), firstSearch ? (complete = newComplete, firstSearch = !1) : this._matchesUpdate$.next(this._matches), this._updateFindHighlight(), newComplete;
|
|
236
|
+
}, "performFindInWorksheet");
|
|
226
237
|
return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(() => this._updateFindHighlight())), this.disposeWithMe(
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
if (
|
|
238
|
+
merge(
|
|
239
|
+
fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(
|
|
240
|
+
filter(([command]) => {
|
|
241
|
+
if (command.type === CommandType.MUTATION && command.params.unitId === this._workbook.getUnitId())
|
|
231
242
|
return !0;
|
|
232
|
-
if (
|
|
233
|
-
const
|
|
234
|
-
return
|
|
243
|
+
if (command.id === SetSelectionsOperation.id && command.params.unitId === unitId) {
|
|
244
|
+
const shouldFindBySelections = checkShouldFindInSelections();
|
|
245
|
+
return shouldFindBySelections === !1 && findBySelections === !1 ? !1 : (findBySelections = shouldFindBySelections, !0);
|
|
235
246
|
}
|
|
236
247
|
return !1;
|
|
237
248
|
})
|
|
238
249
|
),
|
|
239
250
|
// activeSheet$ is a BehaviorSubject, so we need to skip the first
|
|
240
|
-
this._workbook.activeSheet$.pipe(
|
|
241
|
-
).pipe(
|
|
242
|
-
),
|
|
243
|
-
}
|
|
244
|
-
_findInRange(
|
|
245
|
-
const
|
|
246
|
-
for (const
|
|
247
|
-
const { row
|
|
248
|
-
if (
|
|
251
|
+
this._workbook.activeSheet$.pipe(skip(1))
|
|
252
|
+
).pipe(debounceTime(200)).subscribe(() => performFindInWorksheet())
|
|
253
|
+
), performFindInWorksheet(), complete;
|
|
254
|
+
}
|
|
255
|
+
_findInRange(worksheet, query, range, unitId, dedupeFn) {
|
|
256
|
+
const results = [], subUnitId = worksheet.getSheetId(), iter = (query.findDirection === FindDirection.COLUMN ? worksheet.iterateByColumn : worksheet.iterateByRow).bind(worksheet)(range);
|
|
257
|
+
for (const value of iter) {
|
|
258
|
+
const { row, col, colSpan, rowSpan, value: cellData } = value;
|
|
259
|
+
if (dedupeFn != null && dedupeFn(row, col) || !cellData || worksheet.getRowFiltered(row))
|
|
249
260
|
continue;
|
|
250
|
-
const { hit
|
|
251
|
-
if (
|
|
252
|
-
const
|
|
253
|
-
provider:
|
|
254
|
-
unitId
|
|
255
|
-
replaceable
|
|
256
|
-
isFormula
|
|
261
|
+
const { hit, replaceable, isFormula } = hitCell(worksheet, row, col, query, cellData);
|
|
262
|
+
if (hit) {
|
|
263
|
+
const result = {
|
|
264
|
+
provider: SHEETS_FIND_REPLACE_PROVIDER_NAME,
|
|
265
|
+
unitId,
|
|
266
|
+
replaceable,
|
|
267
|
+
isFormula,
|
|
257
268
|
range: {
|
|
258
|
-
subUnitId
|
|
269
|
+
subUnitId,
|
|
259
270
|
range: {
|
|
260
|
-
startRow:
|
|
261
|
-
startColumn:
|
|
262
|
-
endColumn:
|
|
263
|
-
endRow:
|
|
271
|
+
startRow: row,
|
|
272
|
+
startColumn: col,
|
|
273
|
+
endColumn: col + (colSpan != null ? colSpan : 1) - 1,
|
|
274
|
+
endRow: row + (rowSpan != null ? rowSpan : 1) - 1
|
|
264
275
|
}
|
|
265
276
|
}
|
|
266
277
|
};
|
|
267
|
-
|
|
278
|
+
results.push(result);
|
|
268
279
|
}
|
|
269
280
|
}
|
|
270
|
-
return { results
|
|
271
|
-
}
|
|
272
|
-
_findInSelections(
|
|
273
|
-
const { findDirection
|
|
274
|
-
return { results:
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
(
|
|
280
|
-
const
|
|
281
|
-
return
|
|
281
|
+
return { results };
|
|
282
|
+
}
|
|
283
|
+
_findInSelections(worksheet, selections, query, unitId) {
|
|
284
|
+
const { findDirection } = query, sortFn = findDirection === FindDirection.ROW ? isBehindPositionWithRowPriority : isBehindPositionWithColumnPriority, dedupeSet = /* @__PURE__ */ new Set();
|
|
285
|
+
return { results: selections.map((selection) => this._findInRange(
|
|
286
|
+
worksheet,
|
|
287
|
+
query,
|
|
288
|
+
selection.range,
|
|
289
|
+
unitId,
|
|
290
|
+
(row, col) => {
|
|
291
|
+
const key = `${row}-${col}`;
|
|
292
|
+
return dedupeSet.has(key) ? !0 : (dedupeSet.add(key), !1);
|
|
282
293
|
}
|
|
283
|
-
).results).flat().sort((
|
|
294
|
+
).results).flat().sort((a, b) => sortFn(a.range.range, b.range.range) ? -1 : 1) };
|
|
284
295
|
}
|
|
285
296
|
/** Find matches in a given worksheet. */
|
|
286
|
-
_findInWorksheet(
|
|
287
|
-
const
|
|
288
|
-
return this._findInRange(
|
|
297
|
+
_findInWorksheet(worksheet, query, unitId) {
|
|
298
|
+
const rowCount = worksheet.getRowCount(), colCount = worksheet.getColumnCount(), range = { startRow: 0, startColumn: 0, endRow: rowCount - 1, endColumn: colCount - 1 };
|
|
299
|
+
return this._findInRange(worksheet, query, range, unitId);
|
|
289
300
|
}
|
|
290
301
|
_disposeHighlights() {
|
|
291
|
-
var
|
|
292
|
-
this._highlightShapes.forEach((
|
|
293
|
-
var
|
|
294
|
-
(
|
|
295
|
-
}), this._highlightShapes = [], (
|
|
302
|
+
var _a5;
|
|
303
|
+
this._highlightShapes.forEach((shape) => {
|
|
304
|
+
var _a6;
|
|
305
|
+
(_a6 = shape.getScene()) == null || _a6.makeDirty(), shape.dispose();
|
|
306
|
+
}), this._highlightShapes = [], (_a5 = this._currentHighlightShape) == null || _a5.dispose(), this._currentHighlightShape = null;
|
|
296
307
|
}
|
|
297
308
|
_updateFindHighlight() {
|
|
298
|
-
var
|
|
309
|
+
var _a5;
|
|
299
310
|
this._disposeHighlights();
|
|
300
|
-
const
|
|
301
|
-
if (!
|
|
311
|
+
const skeleton = (_a5 = this._sheetSkeletonManagerService.getCurrent()) == null ? void 0 : _a5.skeleton;
|
|
312
|
+
if (!skeleton)
|
|
302
313
|
return;
|
|
303
|
-
const
|
|
304
|
-
if (
|
|
314
|
+
const unitId = this._workbook.getUnitId(), currentRender = this._renderManagerService.getRenderById(unitId);
|
|
315
|
+
if (currentRender == null)
|
|
305
316
|
return;
|
|
306
|
-
const { scene
|
|
307
|
-
if (!
|
|
317
|
+
const { scene } = currentRender, matches = this._matches, searchBackgroundColor = this._themeService.getCurrentTheme().gold400, color = new ColorKit(searchBackgroundColor).toRgb(), worksheet = this._workbook.getActiveSheet();
|
|
318
|
+
if (!worksheet)
|
|
308
319
|
return;
|
|
309
|
-
const
|
|
310
|
-
const { startColumn
|
|
311
|
-
left:
|
|
312
|
-
top:
|
|
313
|
-
color
|
|
314
|
-
width
|
|
315
|
-
height
|
|
320
|
+
const activeSheetId = worksheet.getSheetId(), highlightShapes = matches.filter((match) => match.range.subUnitId === activeSheetId).map((find, index) => {
|
|
321
|
+
const { startColumn, startRow, endColumn, endRow } = find.range.range, startPosition = getCoordByCell(startRow, startColumn, scene, skeleton), endPosition = getCoordByCell(endRow, endColumn, scene, skeleton), { startX, startY } = startPosition, { endX, endY } = endPosition, rowHidden = !worksheet.getRowRawVisible(startRow), columnHidden = !worksheet.getColVisible(startColumn), inHiddenRange = rowHidden || columnHidden, width = columnHidden ? 2 : endX - startX, height = rowHidden ? 2 : endY - startY, props = {
|
|
322
|
+
left: startX,
|
|
323
|
+
top: startY,
|
|
324
|
+
color,
|
|
325
|
+
width,
|
|
326
|
+
height,
|
|
316
327
|
evented: !1,
|
|
317
|
-
inHiddenRange
|
|
318
|
-
zIndex:
|
|
328
|
+
inHiddenRange,
|
|
329
|
+
zIndex: FIND_REPLACE_Z_INDEX
|
|
319
330
|
};
|
|
320
|
-
return new
|
|
331
|
+
return new SheetFindReplaceHighlightShape(`find-highlight-${index}`, props);
|
|
321
332
|
});
|
|
322
|
-
|
|
333
|
+
scene.addObjects(highlightShapes), this._highlightShapes = highlightShapes, scene.makeDirty();
|
|
323
334
|
}
|
|
324
|
-
_updateCurrentHighlightShape(
|
|
325
|
-
var
|
|
326
|
-
if ((
|
|
327
|
-
const
|
|
328
|
-
if (!
|
|
335
|
+
_updateCurrentHighlightShape(matchIndex) {
|
|
336
|
+
var _a5;
|
|
337
|
+
if ((_a5 = this._currentHighlightShape) == null || _a5.setShapeProps({ activated: !1 }), this._currentHighlightShape = null, matchIndex !== void 0) {
|
|
338
|
+
const shape = this._highlightShapes[matchIndex];
|
|
339
|
+
if (!shape)
|
|
329
340
|
return;
|
|
330
|
-
this._currentHighlightShape =
|
|
341
|
+
this._currentHighlightShape = shape, shape.setShapeProps({ activated: !0 });
|
|
331
342
|
}
|
|
332
343
|
}
|
|
333
344
|
_getSheetObject() {
|
|
334
|
-
return
|
|
335
|
-
}
|
|
336
|
-
_focusMatch(
|
|
337
|
-
var
|
|
338
|
-
const
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
{ unitId: this._workbook.getUnitId(), subUnitId
|
|
345
|
+
return getSheetObject(this._univerInstanceService, this._renderManagerService);
|
|
346
|
+
}
|
|
347
|
+
_focusMatch(match) {
|
|
348
|
+
var _a5;
|
|
349
|
+
const subUnitId = match.range.subUnitId;
|
|
350
|
+
subUnitId !== ((_a5 = this._workbook.getActiveSheet()) == null ? void 0 : _a5.getSheetId()) && this._commandService.executeCommand(
|
|
351
|
+
SetWorksheetActivateCommand.id,
|
|
352
|
+
{ unitId: this._workbook.getUnitId(), subUnitId },
|
|
342
353
|
{ fromFindReplace: !0 }
|
|
343
354
|
), this._commandService.executeCommand(
|
|
344
|
-
|
|
345
|
-
{ range:
|
|
355
|
+
ScrollToCellCommand.id,
|
|
356
|
+
{ range: match.range.range },
|
|
346
357
|
{ fromFindReplace: !0 }
|
|
347
358
|
);
|
|
348
359
|
}
|
|
349
|
-
_tryRestoreLastMatchesPosition(
|
|
350
|
-
if (!
|
|
351
|
-
const { subUnitId:
|
|
352
|
-
if (
|
|
360
|
+
_tryRestoreLastMatchesPosition(lastMatch, newMatches) {
|
|
361
|
+
if (!lastMatch) return 0;
|
|
362
|
+
const { subUnitId: lastSubUnitId } = lastMatch.range, { startColumn: lastStartColumn, startRow: lastStartRow } = lastMatch.range.range, index = newMatches.findIndex((match) => {
|
|
363
|
+
if (lastSubUnitId !== match.range.subUnitId)
|
|
353
364
|
return !1;
|
|
354
|
-
const { startColumn
|
|
355
|
-
return
|
|
365
|
+
const { startColumn, startRow } = match.range.range;
|
|
366
|
+
return startColumn === lastStartColumn && startRow === lastStartRow;
|
|
356
367
|
});
|
|
357
|
-
return
|
|
368
|
+
return index > -1 ? index + 1 : 0;
|
|
358
369
|
}
|
|
359
|
-
moveToNextMatch(
|
|
360
|
-
var
|
|
370
|
+
moveToNextMatch(params) {
|
|
371
|
+
var _a5, _b, _c, _d, _e;
|
|
361
372
|
if (!this._matches.length)
|
|
362
373
|
return null;
|
|
363
|
-
const
|
|
364
|
-
if (
|
|
365
|
-
const [
|
|
366
|
-
return this._matchesPosition =
|
|
374
|
+
const loop = (_a5 = params == null ? void 0 : params.loop) != null ? _a5 : !1, stayIfOnMatch = (_b = params == null ? void 0 : params.stayIfOnMatch) != null ? _b : !1, noFocus = (_c = params == null ? void 0 : params.noFocus) != null ? _c : !1, ignoreSelection = (_d = params == null ? void 0 : params.ignoreSelection) != null ? _d : !1, matchToMove = this._findNextMatch(loop, stayIfOnMatch, ignoreSelection);
|
|
375
|
+
if (matchToMove) {
|
|
376
|
+
const [match, index] = matchToMove;
|
|
377
|
+
return this._matchesPosition = index + 1, this._query.findScope === FindScope.UNIT ? this._activeHighlightIndex = this._matchesByWorksheet.get(match.range.subUnitId).findIndex((m) => m === match) : this._activeHighlightIndex = index, noFocus || this._focusMatch(match), ((_e = this._workbook.getActiveSheet()) == null ? void 0 : _e.getSheetId()) === match.range.subUnitId && this._updateCurrentHighlightShape(this._activeHighlightIndex), match;
|
|
367
378
|
}
|
|
368
379
|
return this._matchesPosition = 0, this._updateCurrentHighlightShape(), null;
|
|
369
380
|
}
|
|
370
|
-
moveToPreviousMatch(
|
|
371
|
-
var
|
|
381
|
+
moveToPreviousMatch(params) {
|
|
382
|
+
var _a5, _b, _c, _d, _e;
|
|
372
383
|
if (!this._matches.length)
|
|
373
384
|
return null;
|
|
374
|
-
const
|
|
375
|
-
if (
|
|
376
|
-
const [
|
|
377
|
-
return this._matchesPosition =
|
|
385
|
+
const loop = (_a5 = params == null ? void 0 : params.loop) != null ? _a5 : !1, stayIfOnMatch = (_b = params == null ? void 0 : params.stayIfOnMatch) != null ? _b : !1, noFocus = (_c = params == null ? void 0 : params.noFocus) != null ? _c : !1, ignoreSelection = (_d = params == null ? void 0 : params.ignoreSelection) != null ? _d : !1, matchToMove = this._findPreviousMatch(loop, stayIfOnMatch, ignoreSelection);
|
|
386
|
+
if (matchToMove) {
|
|
387
|
+
const [match, index] = matchToMove;
|
|
388
|
+
return this._matchesPosition = index + 1, this._query.findScope === FindScope.UNIT ? this._activeHighlightIndex = this._matchesByWorksheet.get(match.range.subUnitId).findIndex((m) => m === match) : this._activeHighlightIndex = index, noFocus || this._focusMatch(match), ((_e = this._workbook.getActiveSheet()) == null ? void 0 : _e.getSheetId()) === match.range.subUnitId && this._updateCurrentHighlightShape(this._activeHighlightIndex), match;
|
|
378
389
|
}
|
|
379
390
|
return this._matchesPosition = 0, this._updateCurrentHighlightShape(), null;
|
|
380
391
|
}
|
|
381
|
-
_findPreviousMatch(
|
|
382
|
-
var
|
|
392
|
+
_findPreviousMatch(loop = !1, stayIfOnMatch = !1, ignoreSelection = !1) {
|
|
393
|
+
var _a5;
|
|
383
394
|
if (this.currentMatch) {
|
|
384
|
-
const
|
|
385
|
-
if (
|
|
386
|
-
return [this.currentMatch,
|
|
387
|
-
const
|
|
388
|
-
if (!
|
|
395
|
+
const currentMatchIndex = this._matches.findIndex((match) => match === this.currentMatch);
|
|
396
|
+
if (stayIfOnMatch)
|
|
397
|
+
return [this.currentMatch, currentMatchIndex];
|
|
398
|
+
const nextMatchIndex = currentMatchIndex - 1;
|
|
399
|
+
if (!loop && nextMatchIndex < 0)
|
|
389
400
|
return null;
|
|
390
|
-
const
|
|
391
|
-
return [this._matches[
|
|
401
|
+
const length = this._matches.length, modded = (nextMatchIndex + length) % length;
|
|
402
|
+
return [this._matches[modded], modded];
|
|
392
403
|
}
|
|
393
|
-
const
|
|
394
|
-
if (
|
|
395
|
-
const
|
|
396
|
-
return [this._matches[
|
|
404
|
+
const lastSelection = this._workbookSelections.getCurrentLastSelection();
|
|
405
|
+
if (ignoreSelection || !lastSelection) {
|
|
406
|
+
const lastIndex = this._matches.length - 1;
|
|
407
|
+
return [this._matches[lastIndex], lastIndex];
|
|
397
408
|
}
|
|
398
|
-
if (this._query.findScope !==
|
|
399
|
-
return this._findPreviousMatchByRange(this._matches,
|
|
400
|
-
const
|
|
401
|
-
if (!
|
|
409
|
+
if (this._query.findScope !== FindScope.UNIT)
|
|
410
|
+
return this._findPreviousMatchByRange(this._matches, lastSelection.range);
|
|
411
|
+
const currentSheetId = (_a5 = this._workbook.getActiveSheet()) == null ? void 0 : _a5.getSheetId();
|
|
412
|
+
if (!currentSheetId)
|
|
402
413
|
return null;
|
|
403
|
-
const
|
|
404
|
-
return
|
|
414
|
+
const worksheetThatHasMatch = this._findPreviousWorksheetThatHasAMatch(currentSheetId, loop);
|
|
415
|
+
return worksheetThatHasMatch ? this._findPreviousMatchByRange(this._matchesByWorksheet.get(worksheetThatHasMatch), lastSelection.range) : null;
|
|
405
416
|
}
|
|
406
|
-
_findNextMatch(
|
|
407
|
-
var
|
|
417
|
+
_findNextMatch(loop = !1, stayIfOnMatch = !1, ignoreSelection = !1) {
|
|
418
|
+
var _a5;
|
|
408
419
|
if (this.currentMatch) {
|
|
409
|
-
const
|
|
410
|
-
if (
|
|
411
|
-
return [this.currentMatch,
|
|
412
|
-
const
|
|
413
|
-
if (!
|
|
420
|
+
const currentMatchIndex = this._matches.findIndex((match) => match === this.currentMatch);
|
|
421
|
+
if (stayIfOnMatch)
|
|
422
|
+
return [this.currentMatch, currentMatchIndex];
|
|
423
|
+
const nextMatchIndex = currentMatchIndex + 1, length = this._matches.length;
|
|
424
|
+
if (!loop && nextMatchIndex >= length)
|
|
414
425
|
return null;
|
|
415
|
-
const
|
|
416
|
-
return [this._matches[
|
|
426
|
+
const modded = nextMatchIndex % length;
|
|
427
|
+
return [this._matches[modded], modded];
|
|
417
428
|
}
|
|
418
|
-
const
|
|
419
|
-
if (
|
|
429
|
+
const last = this._workbookSelections.getCurrentLastSelection();
|
|
430
|
+
if (ignoreSelection || !last)
|
|
420
431
|
return [this._matches[0], 0];
|
|
421
|
-
if (this._query.findScope !==
|
|
422
|
-
return this._findNextMatchByRange(this._matches,
|
|
423
|
-
const
|
|
424
|
-
if (!
|
|
432
|
+
if (this._query.findScope !== FindScope.UNIT)
|
|
433
|
+
return this._findNextMatchByRange(this._matches, last.range, stayIfOnMatch);
|
|
434
|
+
const currentSheetId = (_a5 = this._workbook.getActiveSheet()) == null ? void 0 : _a5.getSheetId();
|
|
435
|
+
if (!currentSheetId)
|
|
425
436
|
return null;
|
|
426
|
-
const
|
|
427
|
-
return
|
|
428
|
-
}
|
|
429
|
-
_findPreviousWorksheetThatHasAMatch(
|
|
430
|
-
const
|
|
431
|
-
return
|
|
432
|
-
}
|
|
433
|
-
_findNextWorksheetThatHasAMatch(
|
|
434
|
-
const
|
|
435
|
-
return
|
|
436
|
-
}
|
|
437
|
-
_findNextMatchByRange(
|
|
438
|
-
const
|
|
439
|
-
let
|
|
440
|
-
const
|
|
441
|
-
if (!(
|
|
437
|
+
const worksheetThatHasMatch = this._findNextWorksheetThatHasAMatch(currentSheetId, loop);
|
|
438
|
+
return worksheetThatHasMatch ? this._findNextMatchByRange(this._matchesByWorksheet.get(worksheetThatHasMatch), last.range) : null;
|
|
439
|
+
}
|
|
440
|
+
_findPreviousWorksheetThatHasAMatch(currentWorksheet, loop = !1) {
|
|
441
|
+
const rawWorksheetsInOrder = this._workbook.getSheetOrders(), currentSheetIndex = rawWorksheetsInOrder.findIndex((sheet) => sheet === currentWorksheet), first = (loop ? rotate(rawWorksheetsInOrder, currentSheetIndex + 1) : rawWorksheetsInOrder.slice(0, currentSheetIndex + 1)).findLast((worksheet) => this._matchesByWorksheet.has(worksheet));
|
|
442
|
+
return first != null ? first : null;
|
|
443
|
+
}
|
|
444
|
+
_findNextWorksheetThatHasAMatch(currentWorksheet, loop = !1) {
|
|
445
|
+
const rawWorksheetsInOrder = this._workbook.getSheetOrders(), currentSheetIndex = rawWorksheetsInOrder.findIndex((sheet) => sheet === currentWorksheet), first = (loop ? rotate(rawWorksheetsInOrder, currentSheetIndex) : rawWorksheetsInOrder.slice(currentSheetIndex)).find((worksheet) => this._matchesByWorksheet.has(worksheet));
|
|
446
|
+
return first != null ? first : null;
|
|
447
|
+
}
|
|
448
|
+
_findNextMatchByRange(matches, range, stayIfOnMatch = !1) {
|
|
449
|
+
const findByRow = this._query.findDirection === FindDirection.ROW;
|
|
450
|
+
let index = matches.findIndex((match2) => {
|
|
451
|
+
const matchRange = match2.range.range;
|
|
452
|
+
if (!(findByRow ? isBehindPositionWithRowPriority(range, matchRange) : isBehindPositionWithColumnPriority(range, matchRange)))
|
|
442
453
|
return !1;
|
|
443
|
-
const
|
|
444
|
-
return
|
|
454
|
+
const isSame = isSamePosition(range, matchRange);
|
|
455
|
+
return stayIfOnMatch ? isSame : !isSame;
|
|
445
456
|
});
|
|
446
|
-
|
|
447
|
-
const
|
|
448
|
-
return [
|
|
449
|
-
}
|
|
450
|
-
_findPreviousMatchByRange(
|
|
451
|
-
const
|
|
452
|
-
let
|
|
453
|
-
const
|
|
454
|
-
if (!(
|
|
457
|
+
index === -1 && (index = matches.length - 1);
|
|
458
|
+
const match = matches[index];
|
|
459
|
+
return [match, this._matches.findIndex((m) => m === match)];
|
|
460
|
+
}
|
|
461
|
+
_findPreviousMatchByRange(matches, range, stayIfOnMatch = !1) {
|
|
462
|
+
const findByRow = this._query.findDirection === FindDirection.ROW;
|
|
463
|
+
let index = this._matches.findLastIndex((match2) => {
|
|
464
|
+
const matchRange = match2.range.range;
|
|
465
|
+
if (!(findByRow ? isBeforePositionWithRowPriority(range, matchRange) : isBeforePositionWithColumnPriority(range, matchRange)))
|
|
455
466
|
return !1;
|
|
456
|
-
const
|
|
457
|
-
return
|
|
467
|
+
const isSame = isSamePosition(range, matchRange);
|
|
468
|
+
return stayIfOnMatch ? isSame : !isSame;
|
|
458
469
|
});
|
|
459
|
-
|
|
460
|
-
const
|
|
461
|
-
return [
|
|
470
|
+
index === -1 && (index = 0);
|
|
471
|
+
const match = matches[index];
|
|
472
|
+
return [match, this._matches.findIndex((m) => m === match)];
|
|
462
473
|
}
|
|
463
|
-
async replace(
|
|
474
|
+
async replace(replaceString) {
|
|
464
475
|
if (this._matchesCount === 0 || !this.currentMatch || !this._query || !this.currentMatch.replaceable)
|
|
465
476
|
return !1;
|
|
466
|
-
const
|
|
477
|
+
const range = this.currentMatch.range, targetWorksheet = this._workbook.getSheetBySheetId(this.currentMatch.range.subUnitId), newContent = this._getReplacedCellData(
|
|
467
478
|
this.currentMatch,
|
|
468
|
-
|
|
469
|
-
this._query.findBy ===
|
|
479
|
+
targetWorksheet,
|
|
480
|
+
this._query.findBy === FindBy.FORMULA,
|
|
470
481
|
this._query.findString,
|
|
471
|
-
|
|
482
|
+
replaceString,
|
|
472
483
|
this._query.caseSensitive ? "g" : "ig"
|
|
473
|
-
),
|
|
484
|
+
), params = {
|
|
474
485
|
unitId: this.currentMatch.unitId,
|
|
475
|
-
subUnitId:
|
|
486
|
+
subUnitId: range.subUnitId,
|
|
476
487
|
value: {
|
|
477
|
-
[
|
|
478
|
-
[
|
|
488
|
+
[range.range.startRow]: {
|
|
489
|
+
[range.range.startColumn]: newContent
|
|
479
490
|
}
|
|
480
491
|
}
|
|
481
492
|
};
|
|
482
|
-
return this._commandService.executeCommand(
|
|
493
|
+
return this._commandService.executeCommand(SetRangeValuesCommand.id, params);
|
|
483
494
|
}
|
|
484
|
-
async replaceAll(
|
|
495
|
+
async replaceAll(replaceString) {
|
|
485
496
|
if (this._matchesCount === 0 || !this._query)
|
|
486
497
|
return { success: 0, failure: 0 };
|
|
487
|
-
const
|
|
488
|
-
return
|
|
489
|
-
const
|
|
490
|
-
|
|
491
|
-
const { startColumn
|
|
492
|
-
|
|
493
|
-
}),
|
|
494
|
-
count:
|
|
495
|
-
subUnitId
|
|
496
|
-
value:
|
|
498
|
+
const unitId = this._workbook.getUnitId(), { findString, caseSensitive, findBy } = this._query, shouldReplaceFormula = findBy === FindBy.FORMULA, replaceFlag = caseSensitive ? "g" : "ig", replacements = [];
|
|
499
|
+
return groupBy(this._matches.filter((m) => m.replaceable), (match) => match.range.subUnitId).forEach((matches, subUnitId) => {
|
|
500
|
+
const matrix = new ObjectMatrix(), worksheet = this._workbook.getSheetBySheetId(subUnitId);
|
|
501
|
+
matches.forEach((match) => {
|
|
502
|
+
const { startColumn, startRow } = match.range.range, newCellData = this._getReplacedCellData(match, worksheet, shouldReplaceFormula, findString, replaceString, replaceFlag);
|
|
503
|
+
newCellData && matrix.setValue(startRow, startColumn, newCellData);
|
|
504
|
+
}), replacements.push({
|
|
505
|
+
count: matches.length,
|
|
506
|
+
subUnitId,
|
|
507
|
+
value: matrix.getMatrix()
|
|
497
508
|
});
|
|
498
|
-
}),
|
|
499
|
-
unitId
|
|
500
|
-
replacements
|
|
509
|
+
}), replacements ? this._commandService.executeCommand(SheetReplaceCommand.id, {
|
|
510
|
+
unitId,
|
|
511
|
+
replacements
|
|
501
512
|
}) : { success: 0, failure: 0 };
|
|
502
513
|
}
|
|
503
|
-
_getReplacedCellData(
|
|
504
|
-
var
|
|
505
|
-
const
|
|
506
|
-
if (
|
|
507
|
-
return
|
|
508
|
-
if (!!((
|
|
509
|
-
const
|
|
510
|
-
return
|
|
514
|
+
_getReplacedCellData(match, worksheet, shouldReplaceFormula, findString, replaceString, replaceFlag) {
|
|
515
|
+
var _a5;
|
|
516
|
+
const range = match.range.range, { startRow, startColumn } = range, currentContent = worksheet.getCellRaw(startRow, startColumn);
|
|
517
|
+
if (match.isFormula)
|
|
518
|
+
return shouldReplaceFormula ? { f: currentContent.f.replace(new RegExp(escapeRegExp(findString), replaceFlag), replaceString), v: null } : null;
|
|
519
|
+
if (!!((_a5 = currentContent.p) != null && _a5.body)) {
|
|
520
|
+
const clonedRichText = Tools.deepClone(currentContent.p);
|
|
521
|
+
return replaceInDocumentBody(clonedRichText.body, findString, replaceString, this._query.caseSensitive), { p: clonedRichText };
|
|
511
522
|
}
|
|
512
|
-
return { v:
|
|
513
|
-
}
|
|
514
|
-
};
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
],
|
|
523
|
-
function
|
|
524
|
-
return
|
|
523
|
+
return { v: currentContent.v.toString().replace(new RegExp(escapeRegExp(findString), replaceFlag), replaceString) };
|
|
524
|
+
}
|
|
525
|
+
}, __name(_a2, "SheetFindModel"), _a2);
|
|
526
|
+
SheetFindModel = __decorateClass$1([
|
|
527
|
+
__decorateParam$1(2, IUniverInstanceService),
|
|
528
|
+
__decorateParam$1(3, IRenderManagerService),
|
|
529
|
+
__decorateParam$1(4, ICommandService),
|
|
530
|
+
__decorateParam$1(5, IContextService),
|
|
531
|
+
__decorateParam$1(6, Inject(ThemeService)),
|
|
532
|
+
__decorateParam$1(7, Inject(SheetsSelectionsService))
|
|
533
|
+
], SheetFindModel);
|
|
534
|
+
function escapeRegExp(text) {
|
|
535
|
+
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
|
525
536
|
}
|
|
526
|
-
|
|
527
|
-
|
|
537
|
+
__name(escapeRegExp, "escapeRegExp");
|
|
538
|
+
var _a3;
|
|
539
|
+
let SheetsFindReplaceProvider = (_a3 = class extends Disposable {
|
|
540
|
+
constructor(_univerInstanceService, _renderManagerService, _injector) {
|
|
528
541
|
super();
|
|
529
542
|
/**
|
|
530
543
|
* Hold all find results in this kind of univer business instances (Workbooks).
|
|
531
544
|
*/
|
|
532
|
-
|
|
533
|
-
this._univerInstanceService =
|
|
545
|
+
__publicField(this, "_findModelsByUnitId", /* @__PURE__ */ new Map());
|
|
546
|
+
this._univerInstanceService = _univerInstanceService, this._renderManagerService = _renderManagerService, this._injector = _injector;
|
|
534
547
|
}
|
|
535
|
-
async find(
|
|
548
|
+
async find(query) {
|
|
536
549
|
this._terminate();
|
|
537
|
-
const
|
|
538
|
-
return
|
|
539
|
-
const
|
|
540
|
-
return this._findModelsByUnitId.set(
|
|
550
|
+
const allWorkbooks = this._univerInstanceService.getAllUnitsForType(UniverInstanceType.UNIVER_SHEET), parsedQuery = this._preprocessQuery(query);
|
|
551
|
+
return allWorkbooks.map((workbook) => {
|
|
552
|
+
const skeletonManagerService = this._renderManagerService.getRenderById(workbook.getUnitId()).with(SheetSkeletonManagerService), sheetFind = this._injector.createInstance(SheetFindModel, workbook, skeletonManagerService);
|
|
553
|
+
return this._findModelsByUnitId.set(workbook.getUnitId(), sheetFind), sheetFind.start(parsedQuery), sheetFind;
|
|
541
554
|
});
|
|
542
555
|
}
|
|
543
556
|
terminate() {
|
|
544
557
|
this._terminate();
|
|
545
558
|
}
|
|
546
559
|
_terminate() {
|
|
547
|
-
this._findModelsByUnitId.forEach((
|
|
560
|
+
this._findModelsByUnitId.forEach((model) => model.dispose()), this._findModelsByUnitId.clear();
|
|
548
561
|
}
|
|
549
562
|
/**
|
|
550
563
|
* Parsed the query object before do actual searching in favor of performance.
|
|
551
564
|
* @param query the raw query object
|
|
552
565
|
* @returns the parsed query object
|
|
553
566
|
*/
|
|
554
|
-
_preprocessQuery(
|
|
555
|
-
let
|
|
556
|
-
return
|
|
557
|
-
...
|
|
558
|
-
findString
|
|
567
|
+
_preprocessQuery(query) {
|
|
568
|
+
let findString = query.caseSensitive ? query.findString : query.findString.toLowerCase();
|
|
569
|
+
return findString = findString.trim(), {
|
|
570
|
+
...query,
|
|
571
|
+
findString
|
|
559
572
|
};
|
|
560
573
|
}
|
|
561
|
-
};
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
],
|
|
567
|
-
const
|
|
568
|
-
function
|
|
569
|
-
const { findBy
|
|
570
|
-
return
|
|
574
|
+
}, __name(_a3, "SheetsFindReplaceProvider"), _a3);
|
|
575
|
+
SheetsFindReplaceProvider = __decorateClass$1([
|
|
576
|
+
__decorateParam$1(0, IUniverInstanceService),
|
|
577
|
+
__decorateParam$1(1, IRenderManagerService),
|
|
578
|
+
__decorateParam$1(2, Inject(Injector))
|
|
579
|
+
], SheetsFindReplaceProvider);
|
|
580
|
+
const VALUE_PASSING_OBJECT = { hit: !1, replaceable: !1, isFormula: !1, rawData: null };
|
|
581
|
+
function hitCell(worksheet, row, col, query, cellData) {
|
|
582
|
+
const { findBy } = query, findByFormula = findBy === FindBy.FORMULA, rawData = worksheet.getCellRaw(row, col);
|
|
583
|
+
return VALUE_PASSING_OBJECT.rawData = rawData, !(rawData != null && rawData.f) ? (VALUE_PASSING_OBJECT.isFormula = !1, matchCellData(cellData, query) ? rawData ? (VALUE_PASSING_OBJECT.hit = !0, VALUE_PASSING_OBJECT.replaceable = !0) : (VALUE_PASSING_OBJECT.hit = !0, VALUE_PASSING_OBJECT.replaceable = !1) : (VALUE_PASSING_OBJECT.hit = !1, VALUE_PASSING_OBJECT.replaceable = !1), VALUE_PASSING_OBJECT) : (VALUE_PASSING_OBJECT.isFormula = !0, findByFormula ? matchCellData({ v: rawData.f }, query) ? (VALUE_PASSING_OBJECT.hit = !0, VALUE_PASSING_OBJECT.replaceable = !0, VALUE_PASSING_OBJECT) : (VALUE_PASSING_OBJECT.hit = !1, VALUE_PASSING_OBJECT.replaceable = !1, VALUE_PASSING_OBJECT) : (VALUE_PASSING_OBJECT.replaceable = !1, matchCellData(cellData, query) ? VALUE_PASSING_OBJECT.hit = !0 : VALUE_PASSING_OBJECT.hit = !1, VALUE_PASSING_OBJECT));
|
|
571
584
|
}
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
585
|
+
__name(hitCell, "hitCell");
|
|
586
|
+
function matchCellData(cellData, query) {
|
|
587
|
+
let value = extractPureValue(cellData);
|
|
588
|
+
return value ? query.matchesTheWholeCell ? (value = trimLeadingTrailingWhitespace(value), query.caseSensitive ? value === query.findString : value.toLowerCase() === query.findString) : query.caseSensitive ? value.indexOf(query.findString) > -1 : value.toLowerCase().indexOf(query.findString) > -1 : !1;
|
|
575
589
|
}
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
590
|
+
__name(matchCellData, "matchCellData");
|
|
591
|
+
function extractPureValue(cell) {
|
|
592
|
+
var _a5, _b, _c;
|
|
593
|
+
const rawValue = (_c = (_b = (_a5 = cell == null ? void 0 : cell.p) == null ? void 0 : _a5.body) == null ? void 0 : _b.dataStream) != null ? _c : cell == null ? void 0 : cell.v;
|
|
594
|
+
return typeof rawValue == "number" ? `${rawValue}` : typeof rawValue == "boolean" ? rawValue ? "1" : "0" : rawValue;
|
|
580
595
|
}
|
|
581
|
-
|
|
582
|
-
|
|
596
|
+
__name(extractPureValue, "extractPureValue");
|
|
597
|
+
function trimLeadingTrailingWhitespace(value) {
|
|
598
|
+
return value.replace(/^ +/g, "").replace(/ +$/g, "");
|
|
583
599
|
}
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
600
|
+
__name(trimLeadingTrailingWhitespace, "trimLeadingTrailingWhitespace");
|
|
601
|
+
var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __defNormalProp2 = /* @__PURE__ */ __name((obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, "__defNormalProp"), __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
602
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
603
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
604
|
+
return kind && result && __defProp2(target, key, result), result;
|
|
605
|
+
}, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), __publicField2 = /* @__PURE__ */ __name((obj, key, value) => __defNormalProp2(obj, typeof key != "symbol" ? key + "" : key, value), "__publicField");
|
|
606
|
+
const NAME = "SHEET_FIND_REPLACE_PLUGIN";
|
|
607
|
+
var _a4;
|
|
608
|
+
let UniverSheetsFindReplacePlugin = (_a4 = class extends Plugin {
|
|
609
|
+
constructor(_config = defaultPluginConfig, _injector, _configService) {
|
|
610
|
+
super(), this._config = _config, this._injector = _injector, this._configService = _configService;
|
|
611
|
+
const { ...rest } = merge$1(
|
|
594
612
|
{},
|
|
595
|
-
|
|
613
|
+
defaultPluginConfig,
|
|
596
614
|
this._config
|
|
597
615
|
);
|
|
598
|
-
this._configService.setConfig(
|
|
616
|
+
this._configService.setConfig(SHEETS_FIND_REPLACE_PLUGIN_CONFIG_KEY, rest);
|
|
599
617
|
}
|
|
600
618
|
onStarting() {
|
|
601
|
-
[[
|
|
619
|
+
[[SheetsFindReplaceController]].forEach((d) => this._injector.add(d));
|
|
602
620
|
}
|
|
603
621
|
onSteady() {
|
|
604
|
-
this._injector.get(
|
|
605
|
-
}
|
|
606
|
-
};
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
],
|
|
622
|
+
this._injector.get(SheetsFindReplaceController);
|
|
623
|
+
}
|
|
624
|
+
}, __name(_a4, "UniverSheetsFindReplacePlugin"), _a4);
|
|
625
|
+
__publicField2(UniverSheetsFindReplacePlugin, "pluginName", NAME);
|
|
626
|
+
__publicField2(UniverSheetsFindReplacePlugin, "type", UniverInstanceType.UNIVER_SHEET);
|
|
627
|
+
UniverSheetsFindReplacePlugin = __decorateClass([
|
|
628
|
+
DependentOn(UniverSheetsPlugin, UniverSheetsPlugin, UniverFindReplacePlugin),
|
|
629
|
+
__decorateParam(1, Inject(Injector)),
|
|
630
|
+
__decorateParam(2, IConfigService)
|
|
631
|
+
], UniverSheetsFindReplacePlugin);
|
|
614
632
|
export {
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
633
|
+
SheetReplaceCommand,
|
|
634
|
+
SheetsFindReplaceController,
|
|
635
|
+
UniverSheetsFindReplacePlugin
|
|
618
636
|
};
|