@univerjs/sheets-find-replace 0.4.2 → 0.5.0-beta.0

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