@univerjs/sheets-find-replace 0.24.0 → 0.25.0-insiders.20260608-e4336f7

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.
Files changed (72) hide show
  1. package/lib/cjs/facade.js +6 -6
  2. package/lib/cjs/index.js +25 -27
  3. package/lib/es/facade.js +6 -6
  4. package/lib/es/index.js +24 -26
  5. package/lib/facade.js +6 -6
  6. package/lib/index.js +24 -26
  7. package/lib/types/facade/f-text-finder.d.ts +18 -9
  8. package/lib/types/facade/f-univer.d.ts +2 -1
  9. package/lib/umd/facade.js +1 -1
  10. package/lib/umd/index.js +1 -1
  11. package/package.json +8 -13
  12. package/LICENSE +0 -176
  13. package/lib/cjs/locale/ca-ES.js +0 -9
  14. package/lib/cjs/locale/en-US.js +0 -24
  15. package/lib/cjs/locale/es-ES.js +0 -9
  16. package/lib/cjs/locale/fa-IR.js +0 -9
  17. package/lib/cjs/locale/fr-FR.js +0 -9
  18. package/lib/cjs/locale/ja-JP.js +0 -9
  19. package/lib/cjs/locale/ko-KR.js +0 -9
  20. package/lib/cjs/locale/ru-RU.js +0 -9
  21. package/lib/cjs/locale/sk-SK.js +0 -9
  22. package/lib/cjs/locale/vi-VN.js +0 -9
  23. package/lib/cjs/locale/zh-CN.js +0 -24
  24. package/lib/cjs/locale/zh-TW.js +0 -9
  25. package/lib/es/locale/ca-ES.js +0 -8
  26. package/lib/es/locale/en-US.js +0 -23
  27. package/lib/es/locale/es-ES.js +0 -8
  28. package/lib/es/locale/fa-IR.js +0 -8
  29. package/lib/es/locale/fr-FR.js +0 -8
  30. package/lib/es/locale/ja-JP.js +0 -8
  31. package/lib/es/locale/ko-KR.js +0 -8
  32. package/lib/es/locale/ru-RU.js +0 -8
  33. package/lib/es/locale/sk-SK.js +0 -8
  34. package/lib/es/locale/vi-VN.js +0 -8
  35. package/lib/es/locale/zh-CN.js +0 -23
  36. package/lib/es/locale/zh-TW.js +0 -8
  37. package/lib/locale/ca-ES.js +0 -8
  38. package/lib/locale/en-US.js +0 -23
  39. package/lib/locale/es-ES.js +0 -8
  40. package/lib/locale/fa-IR.js +0 -8
  41. package/lib/locale/fr-FR.js +0 -8
  42. package/lib/locale/ja-JP.js +0 -8
  43. package/lib/locale/ko-KR.js +0 -8
  44. package/lib/locale/ru-RU.js +0 -8
  45. package/lib/locale/sk-SK.js +0 -8
  46. package/lib/locale/vi-VN.js +0 -8
  47. package/lib/locale/zh-CN.js +0 -23
  48. package/lib/locale/zh-TW.js +0 -8
  49. package/lib/types/locale/ca-ES.d.ts +0 -18
  50. package/lib/types/locale/en-US.d.ts +0 -24
  51. package/lib/types/locale/es-ES.d.ts +0 -18
  52. package/lib/types/locale/fa-IR.d.ts +0 -18
  53. package/lib/types/locale/fr-FR.d.ts +0 -18
  54. package/lib/types/locale/ja-JP.d.ts +0 -18
  55. package/lib/types/locale/ko-KR.d.ts +0 -18
  56. package/lib/types/locale/ru-RU.d.ts +0 -18
  57. package/lib/types/locale/sk-SK.d.ts +0 -18
  58. package/lib/types/locale/vi-VN.d.ts +0 -18
  59. package/lib/types/locale/zh-CN.d.ts +0 -24
  60. package/lib/types/locale/zh-TW.d.ts +0 -18
  61. package/lib/umd/locale/ca-ES.js +0 -1
  62. package/lib/umd/locale/en-US.js +0 -1
  63. package/lib/umd/locale/es-ES.js +0 -1
  64. package/lib/umd/locale/fa-IR.js +0 -1
  65. package/lib/umd/locale/fr-FR.js +0 -1
  66. package/lib/umd/locale/ja-JP.js +0 -1
  67. package/lib/umd/locale/ko-KR.js +0 -1
  68. package/lib/umd/locale/ru-RU.js +0 -1
  69. package/lib/umd/locale/sk-SK.js +0 -1
  70. package/lib/umd/locale/vi-VN.js +0 -1
  71. package/lib/umd/locale/zh-CN.js +0 -1
  72. package/lib/umd/locale/zh-TW.js +0 -1
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { ColorKit, CommandType, DependentOn, Disposable, EDITOR_ACTIVATED, ICommandService, IConfigService, IContextService, IUndoRedoService, IUniverInstanceService, Inject, Injector, ObjectMatrix, Plugin, Rectangle, ThemeService, Tools, UniverInstanceType, fromCallback, groupBy, merge, replaceInDocumentBody, rotate } from "@univerjs/core";
1
+ import { ColorKit, CommandType, DependentOn, Disposable, EDITOR_ACTIVATED, ICommandService, IConfigService, IContextService, IUndoRedoService, IUniverInstanceService, Inject, Injector, ObjectMatrix, Plugin, Rectangle, ThemeService, Tools, UniverInstanceType, escapeRegExp, fromCallback, groupBy, merge, replaceInDocumentBody, rotate } from "@univerjs/core";
2
2
  import { SelectRangeCommand, SetRangeValuesCommand, SetSelectionsOperation, SetWorksheetActivateCommand, SetWorksheetActiveOperation, SheetsSelectionsService, UniverSheetsPlugin } from "@univerjs/sheets";
3
3
  import { IRenderManagerService, RENDER_RAW_FORMULA_KEY, Rect, Shape } from "@univerjs/engine-render";
4
4
  import { FindBy, FindDirection, FindModel, FindReplaceController, FindScope, IFindReplaceService, UniverFindReplacePlugin } from "@univerjs/find-replace";
@@ -42,7 +42,7 @@ function getReplaceAllResult(results, replacements) {
42
42
  }
43
43
 
44
44
  //#endregion
45
- //#region \0@oxc-project+runtime@0.129.0/helpers/typeof.js
45
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/typeof.js
46
46
  function _typeof(o) {
47
47
  "@babel/helpers - typeof";
48
48
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -53,7 +53,7 @@ function _typeof(o) {
53
53
  }
54
54
 
55
55
  //#endregion
56
- //#region \0@oxc-project+runtime@0.129.0/helpers/toPrimitive.js
56
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/toPrimitive.js
57
57
  function toPrimitive(t, r) {
58
58
  if ("object" != _typeof(t) || !t) return t;
59
59
  var e = t[Symbol.toPrimitive];
@@ -66,14 +66,14 @@ function toPrimitive(t, r) {
66
66
  }
67
67
 
68
68
  //#endregion
69
- //#region \0@oxc-project+runtime@0.129.0/helpers/toPropertyKey.js
69
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/toPropertyKey.js
70
70
  function toPropertyKey(t) {
71
71
  var i = toPrimitive(t, "string");
72
72
  return "symbol" == _typeof(i) ? i : i + "";
73
73
  }
74
74
 
75
75
  //#endregion
76
- //#region \0@oxc-project+runtime@0.129.0/helpers/defineProperty.js
76
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/defineProperty.js
77
77
  function _defineProperty(e, r, t) {
78
78
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
79
79
  value: t,
@@ -161,7 +161,7 @@ function isSelectionSingleCell(selection, worksheet) {
161
161
  }
162
162
 
163
163
  //#endregion
164
- //#region \0@oxc-project+runtime@0.129.0/helpers/decorateParam.js
164
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/decorateParam.js
165
165
  function __decorateParam(paramIndex, decorator) {
166
166
  return function(target, key) {
167
167
  decorator(target, key, paramIndex);
@@ -169,7 +169,7 @@ function __decorateParam(paramIndex, decorator) {
169
169
  }
170
170
 
171
171
  //#endregion
172
- //#region \0@oxc-project+runtime@0.129.0/helpers/decorate.js
172
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/decorate.js
173
173
  function __decorate(decorators, target, key, desc) {
174
174
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
175
175
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -526,14 +526,17 @@ let SheetFindModel = class SheetFindModel extends FindModel {
526
526
  _getSheetObject() {
527
527
  return getSheetObject(this._univerInstanceService, this._renderManagerService);
528
528
  }
529
- _focusMatch(match) {
529
+ async _focusMatch(match) {
530
530
  var _this$_workbook$getAc;
531
- const subUnitId = match.range.subUnitId;
532
- if (subUnitId !== ((_this$_workbook$getAc = this._workbook.getActiveSheet()) === null || _this$_workbook$getAc === void 0 ? void 0 : _this$_workbook$getAc.getSheetId())) this._commandService.executeCommand(SetWorksheetActivateCommand.id, {
533
- unitId: this._workbook.getUnitId(),
534
- subUnitId
535
- }, { fromFindReplace: true });
536
- this._commandService.executeCommand(ScrollToCellCommand.id, { range: match.range.range }, { fromFindReplace: true });
531
+ const { subUnitId, range } = match.range;
532
+ if (subUnitId !== ((_this$_workbook$getAc = this._workbook.getActiveSheet()) === null || _this$_workbook$getAc === void 0 ? void 0 : _this$_workbook$getAc.getSheetId())) {
533
+ const unitId = this._workbook.getUnitId();
534
+ await this._commandService.executeCommand(SetWorksheetActivateCommand.id, {
535
+ unitId,
536
+ subUnitId
537
+ }, { fromFindReplace: true });
538
+ }
539
+ this._commandService.executeCommand(ScrollToCellCommand.id, { range }, { fromFindReplace: true });
537
540
  }
538
541
  _tryRestoreLastMatchesPosition(lastMatch, newMatches) {
539
542
  if (!lastMatch) return 0;
@@ -555,13 +558,12 @@ let SheetFindModel = class SheetFindModel extends FindModel {
555
558
  const ignoreSelection = (_params$ignoreSelecti = params === null || params === void 0 ? void 0 : params.ignoreSelection) !== null && _params$ignoreSelecti !== void 0 ? _params$ignoreSelecti : false;
556
559
  const matchToMove = this._findNextMatch(loop, stayIfOnMatch, ignoreSelection);
557
560
  if (matchToMove) {
558
- var _this$_workbook$getAc2;
559
561
  const [match, index] = matchToMove;
560
562
  this._matchesPosition = index + 1;
561
563
  if (this._query.findScope === FindScope.UNIT) this._activeHighlightIndex = this._matchesByWorksheet.get(match.range.subUnitId).findIndex((m) => m === match);
562
564
  else this._activeHighlightIndex = index;
563
565
  if (!noFocus) this._focusMatch(match);
564
- if (((_this$_workbook$getAc2 = this._workbook.getActiveSheet()) === null || _this$_workbook$getAc2 === void 0 ? void 0 : _this$_workbook$getAc2.getSheetId()) === match.range.subUnitId) this._updateCurrentHighlightShape(this._activeHighlightIndex);
566
+ this._updateCurrentHighlightShape(this._activeHighlightIndex);
565
567
  return match;
566
568
  }
567
569
  this._matchesPosition = 0;
@@ -577,13 +579,12 @@ let SheetFindModel = class SheetFindModel extends FindModel {
577
579
  const ignoreSelection = (_params$ignoreSelecti2 = params === null || params === void 0 ? void 0 : params.ignoreSelection) !== null && _params$ignoreSelecti2 !== void 0 ? _params$ignoreSelecti2 : false;
578
580
  const matchToMove = this._findPreviousMatch(loop, stayIfOnMatch, ignoreSelection);
579
581
  if (matchToMove) {
580
- var _this$_workbook$getAc3;
581
582
  const [match, index] = matchToMove;
582
583
  this._matchesPosition = index + 1;
583
584
  if (this._query.findScope === FindScope.UNIT) this._activeHighlightIndex = this._matchesByWorksheet.get(match.range.subUnitId).findIndex((m) => m === match);
584
585
  else this._activeHighlightIndex = index;
585
586
  if (!noFocus) this._focusMatch(match);
586
- if (((_this$_workbook$getAc3 = this._workbook.getActiveSheet()) === null || _this$_workbook$getAc3 === void 0 ? void 0 : _this$_workbook$getAc3.getSheetId()) === match.range.subUnitId) this._updateCurrentHighlightShape(this._activeHighlightIndex);
587
+ this._updateCurrentHighlightShape(this._activeHighlightIndex);
587
588
  return match;
588
589
  }
589
590
  this._matchesPosition = 0;
@@ -591,7 +592,7 @@ let SheetFindModel = class SheetFindModel extends FindModel {
591
592
  return null;
592
593
  }
593
594
  _findPreviousMatch(loop = false, stayIfOnMatch = false, ignoreSelection = false) {
594
- var _this$_workbook$getAc4;
595
+ var _this$_workbook$getAc2;
595
596
  if (this.currentMatch) {
596
597
  const currentMatchIndex = this._matches.findIndex((match) => match === this.currentMatch);
597
598
  if (stayIfOnMatch) return [this.currentMatch, currentMatchIndex];
@@ -607,14 +608,14 @@ let SheetFindModel = class SheetFindModel extends FindModel {
607
608
  return [this._matches[lastIndex], lastIndex];
608
609
  }
609
610
  if (this._query.findScope !== FindScope.UNIT) return this._findPreviousMatchByRange(this._matches, lastSelection.range);
610
- const currentSheetId = (_this$_workbook$getAc4 = this._workbook.getActiveSheet()) === null || _this$_workbook$getAc4 === void 0 ? void 0 : _this$_workbook$getAc4.getSheetId();
611
+ const currentSheetId = (_this$_workbook$getAc2 = this._workbook.getActiveSheet()) === null || _this$_workbook$getAc2 === void 0 ? void 0 : _this$_workbook$getAc2.getSheetId();
611
612
  if (!currentSheetId) return null;
612
613
  const worksheetThatHasMatch = this._findPreviousWorksheetThatHasAMatch(currentSheetId, loop);
613
614
  if (!worksheetThatHasMatch) return null;
614
615
  return this._findPreviousMatchByRange(this._matchesByWorksheet.get(worksheetThatHasMatch), lastSelection.range);
615
616
  }
616
617
  _findNextMatch(loop = false, stayIfOnMatch = false, ignoreSelection = false) {
617
- var _this$_workbook$getAc5;
618
+ var _this$_workbook$getAc3;
618
619
  if (this.currentMatch) {
619
620
  const currentMatchIndex = this._matches.findIndex((match) => match === this.currentMatch);
620
621
  if (stayIfOnMatch) return [this.currentMatch, currentMatchIndex];
@@ -627,7 +628,7 @@ let SheetFindModel = class SheetFindModel extends FindModel {
627
628
  const last = this._workbookSelections.getCurrentLastSelection();
628
629
  if (ignoreSelection || !last) return [this._matches[0], 0];
629
630
  if (this._query.findScope !== FindScope.UNIT) return this._findNextMatchByRange(this._matches, last.range, stayIfOnMatch);
630
- const currentSheetId = (_this$_workbook$getAc5 = this._workbook.getActiveSheet()) === null || _this$_workbook$getAc5 === void 0 ? void 0 : _this$_workbook$getAc5.getSheetId();
631
+ const currentSheetId = (_this$_workbook$getAc3 = this._workbook.getActiveSheet()) === null || _this$_workbook$getAc3 === void 0 ? void 0 : _this$_workbook$getAc3.getSheetId();
631
632
  if (!currentSheetId) return null;
632
633
  const worksheetThatHasMatch = this._findNextWorksheetThatHasAMatch(currentSheetId, loop);
633
634
  if (!worksheetThatHasMatch) return null;
@@ -741,9 +742,6 @@ SheetFindModel = __decorate([
741
742
  __decorateParam(6, Inject(ThemeService)),
742
743
  __decorateParam(7, Inject(SheetsSelectionsService))
743
744
  ], SheetFindModel);
744
- function escapeRegExp(text) {
745
- return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
746
- }
747
745
  /**
748
746
  * This module is responsible for searching and replacing in the sheets.
749
747
  * It also adds the search results to the search view by highlighting them.
@@ -869,7 +867,7 @@ function trimLeadingTrailingWhitespace(value) {
869
867
  //#endregion
870
868
  //#region package.json
871
869
  var name = "@univerjs/sheets-find-replace";
872
- var version = "0.24.0";
870
+ var version = "0.25.0-insiders.20260608-e4336f7";
873
871
 
874
872
  //#endregion
875
873
  //#region src/config/config.ts
@@ -31,7 +31,8 @@ export interface IFTextFinder {
31
31
  * ```typescript
32
32
  * // Assume the current sheet is empty sheet.
33
33
  * const fWorkbook = univerAPI.getActiveWorkbook();
34
- * const fWorksheet = fWorkbook.getActiveSheet();
34
+ * const fWorksheet = fWorkbook.getSheetByName('Sheet1');
35
+ * if (!fWorksheet) return;
35
36
  * const fRange = fWorksheet.getRange('A1:D10');
36
37
  * fRange.setValues([
37
38
  * [1, 2, 3, 4],
@@ -66,7 +67,8 @@ export interface IFTextFinder {
66
67
  * ```typescript
67
68
  * // Assume the current sheet is empty sheet.
68
69
  * const fWorkbook = univerAPI.getActiveWorkbook();
69
- * const fWorksheet = fWorkbook.getActiveSheet();
70
+ * const fWorksheet = fWorkbook.getSheetByName('Sheet1');
71
+ * if (!fWorksheet) return;
70
72
  * const fRange = fWorksheet.getRange('A1:D10');
71
73
  * fRange.setValues([
72
74
  * [1, 2, 3, 4],
@@ -101,7 +103,8 @@ export interface IFTextFinder {
101
103
  * ```typescript
102
104
  * // Assume the current sheet is empty sheet.
103
105
  * const fWorkbook = univerAPI.getActiveWorkbook();
104
- * const fWorksheet = fWorkbook.getActiveSheet();
106
+ * const fWorksheet = fWorkbook.getSheetByName('Sheet1');
107
+ * if (!fWorksheet) return;
105
108
  * const fRange = fWorksheet.getRange('A1:D10');
106
109
  * fRange.setValues([
107
110
  * [1, 2, 3, 4],
@@ -136,7 +139,8 @@ export interface IFTextFinder {
136
139
  * ```typescript
137
140
  * // Assume the current sheet is empty sheet.
138
141
  * const fWorkbook = univerAPI.getActiveWorkbook();
139
- * const fWorksheet = fWorkbook.getActiveSheet();
142
+ * const fWorksheet = fWorkbook.getSheetByName('Sheet1');
143
+ * if (!fWorksheet) return;
140
144
  * const fRange = fWorksheet.getRange('A1:D10');
141
145
  * fRange.setValues([
142
146
  * [1, 2, 3, 4],
@@ -169,7 +173,8 @@ export interface IFTextFinder {
169
173
  * ```typescript
170
174
  * // Assume the current sheet is empty sheet.
171
175
  * const fWorkbook = univerAPI.getActiveWorkbook();
172
- * const fWorksheet = fWorkbook.getActiveSheet();
176
+ * const fWorksheet = fWorkbook.getSheetByName('Sheet1');
177
+ * if (!fWorksheet) return;
173
178
  * const fRange = fWorksheet.getRange('A1:D1');
174
179
  * fRange.setValues([
175
180
  * ['hello univer', 'hello UNIVER', 'HELLO UNIVER', 'HELLO univer'],
@@ -200,7 +205,8 @@ export interface IFTextFinder {
200
205
  * ```typescript
201
206
  * // Assume the current sheet is empty sheet.
202
207
  * const fWorkbook = univerAPI.getActiveWorkbook();
203
- * const fWorksheet = fWorkbook.getActiveSheet();
208
+ * const fWorksheet = fWorkbook.getSheetByName('Sheet1');
209
+ * if (!fWorksheet) return;
204
210
  * const fRange = fWorksheet.getRange('A1:D1');
205
211
  * fRange.setValues([
206
212
  * ['hello univer', 'hello univer 1', 'hello univer 2', 'hello univer 3'],
@@ -231,7 +237,8 @@ export interface IFTextFinder {
231
237
  * ```typescript
232
238
  * // Assume the current sheet is empty sheet.
233
239
  * const fWorkbook = univerAPI.getActiveWorkbook();
234
- * const fWorksheet = fWorkbook.getActiveSheet();
240
+ * const fWorksheet = fWorkbook.getSheetByName('Sheet1');
241
+ * if (!fWorksheet) return;
235
242
  * const fRange = fWorksheet.getRange('A1:D1');
236
243
  * fRange.setValues([
237
244
  * ['sum', '1', '=SUM(2)', '3'],
@@ -263,7 +270,8 @@ export interface IFTextFinder {
263
270
  * ```typescript
264
271
  * // Assume the current sheet is empty sheet.
265
272
  * const fWorkbook = univerAPI.getActiveWorkbook();
266
- * const fWorksheet = fWorkbook.getActiveSheet();
273
+ * const fWorksheet = fWorkbook.getSheetByName('Sheet1');
274
+ * if (!fWorksheet) return;
267
275
  * const fRange = fWorksheet.getRange('A1:D1');
268
276
  * fRange.setValues([
269
277
  * ['hello', 'hello', 'hello', 'hello'],
@@ -289,7 +297,8 @@ export interface IFTextFinder {
289
297
  * ```typescript
290
298
  * // Assume the current sheet is empty sheet.
291
299
  * const fWorkbook = univerAPI.getActiveWorkbook();
292
- * const fWorksheet = fWorkbook.getActiveSheet();
300
+ * const fWorksheet = fWorkbook.getSheetByName('Sheet1');
301
+ * if (!fWorksheet) return;
293
302
  * const fRange = fWorksheet.getRange('B1:E1');
294
303
  * fRange.setValues([
295
304
  * ['hello', 'hello', 'hello', 'hello'],
@@ -27,7 +27,8 @@ export interface IFUniverSheetsFindReplaceMixin {
27
27
  * ```typescript
28
28
  * // Assume the current sheet is empty sheet.
29
29
  * const fWorkbook = univerAPI.getActiveWorkbook();
30
- * const fWorksheet = fWorkbook.getActiveSheet();
30
+ * const fWorksheet = fWorkbook.getSheetByName('Sheet1');
31
+ * if (!fWorksheet) return;
31
32
  *
32
33
  * // Set some values to the range A1:D10.
33
34
  * const fRange = fWorksheet.getRange('A1:D10');
package/lib/umd/facade.js CHANGED
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(require(`@univerjs/core`),require(`@univerjs/find-replace`),require(`@univerjs/sheets/facade`),require(`rxjs`),require(`@univerjs/core/facade`)):typeof define==`function`&&define.amd?define([`@univerjs/core`,`@univerjs/find-replace`,`@univerjs/sheets/facade`,`rxjs`,`@univerjs/core/facade`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverCore,e.UniverFindReplace,e.UniverSheetsFacade,e.rxjs,e.UniverCoreFacade))})(this,function(e,t,n,r,i){function a(e){"@babel/helpers - typeof";return a=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},a(e)}function o(e,t){if(a(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(a(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function s(e){var t=o(e,`string`);return a(t)==`symbol`?t:t+``}function c(e,t,n){return(t=s(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){return function(n,r){t(n,r,e)}}function u(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let d=class extends e.Disposable{constructor(e,n,r,i){super(),this._injector=n,this._univerInstanceService=r,this._findReplaceService=i,c(this,`_state`,new t.FindReplaceState),c(this,`_model`,void 0),c(this,`_complete`,void 0);let a=this._findReplaceService.getProviders();this._model=this._injector.createInstance(t.FindReplaceModel,this._state,a);let o={...(0,t.createInitFindReplaceState)(),...e};this._state.changeState(o)}findAll(){return!this._state.findCompleted||!this._complete?[]:this._complete.results.map(e=>this._findMatchToFRange(e))}findNext(){var e;if(!this._state.findCompleted||!this._complete)return null;let t=(e=this._model)==null?void 0:e.moveToNextMatch();return t?this._findMatchToFRange(t):null}findPrevious(){var e;let t=(e=this._model)==null?void 0:e.moveToPreviousMatch();return t?this._findMatchToFRange(t):null}getCurrentMatch(){var e;if(!this._state.findCompleted||!this._complete)throw Error(`Find operation is not completed.`);let t=(e=this._model)==null?void 0:e.currentMatch$.value;return t?this._findMatchToFRange(t):null}async matchCaseAsync(e){return this._state.changeState({caseSensitive:e,findCompleted:!1}),await(0,r.firstValueFrom)(this._state.stateUpdates$.pipe((0,r.filter)(e=>e.findCompleted===!0))),await this.ensureCompleteAsync(),this}async matchEntireCellAsync(e){return this._state.changeState({matchesTheWholeCell:e,findCompleted:!1}),await(0,r.firstValueFrom)(this._state.stateUpdates$.pipe((0,r.filter)(e=>e.findCompleted===!0))),await this.ensureCompleteAsync(),this}async matchFormulaTextAsync(e){return this._state.changeState({findBy:e?t.FindBy.FORMULA:t.FindBy.VALUE,findCompleted:!1}),await(0,r.firstValueFrom)(this._state.stateUpdates$.pipe((0,r.filter)(e=>e.findCompleted===!0))),await this.ensureCompleteAsync(),this}async replaceAllWithAsync(e){var t,n,r;await this._state.changeState({replaceRevealed:!0,replaceString:e});let i=(t=(n=await((r=this._model)==null?void 0:r.replaceAll()))==null?void 0:n.success)==null?0:t;return this._state.changeState({replaceRevealed:!1}),i}async replaceWithAsync(e){var t;return await this._state.changeState({replaceRevealed:!0,replaceString:e}),await((t=this._model)==null?void 0:t.replace()),this._state.changeState({replaceRevealed:!1}),!0}async ensureCompleteAsync(){var e;this._complete=await((e=this._model)==null?void 0:e.start())}_findMatchToFRange(e){let{unitId:t}=e,{subUnitId:r,range:i}=e.range,a=this._univerInstanceService.getUnit(t),o=a.getSheetBySheetId(r);return this._injector.createInstance(n.FRange,a,o,i)}};d=u([l(1,(0,e.Inject)(e.Injector)),l(2,e.IUniverInstanceService),l(3,t.IFindReplaceService)],d);var f=class extends i.FUniver{async createTextFinderAsync(e){let t={findString:e},n=this._injector.createInstance(d,t);return await n.ensureCompleteAsync(),n}};i.FUniver.extend(f)});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(require("@univerjs/core"),require("@univerjs/find-replace"),require("@univerjs/sheets/facade"),require("rxjs"),require("@univerjs/core/facade")):typeof define==`function`&&define.amd?define([`@univerjs/core`,`@univerjs/find-replace`,`@univerjs/sheets/facade`,`rxjs`,`@univerjs/core/facade`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverCore,e.UniverFindReplace,e.UniverSheetsFacade,e.rxjs,e.UniverCoreFacade))})(this,function(e,t,n,r,i){function a(e){"@babel/helpers - typeof";return a=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},a(e)}function o(e,t){if(a(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(a(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function s(e){var t=o(e,`string`);return a(t)==`symbol`?t:t+``}function c(e,t,n){return(t=s(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){return function(n,r){t(n,r,e)}}function u(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let d=class extends e.Disposable{constructor(e,n,r,i){super(),this._injector=n,this._univerInstanceService=r,this._findReplaceService=i,c(this,`_state`,new t.FindReplaceState),c(this,`_model`,void 0),c(this,`_complete`,void 0);let a=this._findReplaceService.getProviders();this._model=this._injector.createInstance(t.FindReplaceModel,this._state,a);let o={...(0,t.createInitFindReplaceState)(),...e};this._state.changeState(o)}findAll(){return!this._state.findCompleted||!this._complete?[]:this._complete.results.map(e=>this._findMatchToFRange(e))}findNext(){var e;if(!this._state.findCompleted||!this._complete)return null;let t=(e=this._model)==null?void 0:e.moveToNextMatch();return t?this._findMatchToFRange(t):null}findPrevious(){var e;let t=(e=this._model)==null?void 0:e.moveToPreviousMatch();return t?this._findMatchToFRange(t):null}getCurrentMatch(){var e;if(!this._state.findCompleted||!this._complete)throw Error(`Find operation is not completed.`);let t=(e=this._model)==null?void 0:e.currentMatch$.value;return t?this._findMatchToFRange(t):null}async matchCaseAsync(e){return this._state.changeState({caseSensitive:e,findCompleted:!1}),await(0,r.firstValueFrom)(this._state.stateUpdates$.pipe((0,r.filter)(e=>e.findCompleted===!0))),await this.ensureCompleteAsync(),this}async matchEntireCellAsync(e){return this._state.changeState({matchesTheWholeCell:e,findCompleted:!1}),await(0,r.firstValueFrom)(this._state.stateUpdates$.pipe((0,r.filter)(e=>e.findCompleted===!0))),await this.ensureCompleteAsync(),this}async matchFormulaTextAsync(e){return this._state.changeState({findBy:e?t.FindBy.FORMULA:t.FindBy.VALUE,findCompleted:!1}),await(0,r.firstValueFrom)(this._state.stateUpdates$.pipe((0,r.filter)(e=>e.findCompleted===!0))),await this.ensureCompleteAsync(),this}async replaceAllWithAsync(e){var t,n,r;await this._state.changeState({replaceRevealed:!0,replaceString:e});let i=(t=(n=await((r=this._model)==null?void 0:r.replaceAll()))==null?void 0:n.success)==null?0:t;return this._state.changeState({replaceRevealed:!1}),i}async replaceWithAsync(e){var t;return await this._state.changeState({replaceRevealed:!0,replaceString:e}),await((t=this._model)==null?void 0:t.replace()),this._state.changeState({replaceRevealed:!1}),!0}async ensureCompleteAsync(){var e;this._complete=await((e=this._model)==null?void 0:e.start())}_findMatchToFRange(e){let{unitId:t}=e,{subUnitId:r,range:i}=e.range,a=this._univerInstanceService.getUnit(t),o=a.getSheetBySheetId(r);return this._injector.createInstance(n.FRange,a,o,i)}};d=u([l(1,(0,e.Inject)(e.Injector)),l(2,e.IUniverInstanceService),l(3,t.IFindReplaceService)],d);var f=class extends i.FUniver{async createTextFinderAsync(e){let t={findString:e},n=this._injector.createInstance(d,t);return await n.ensureCompleteAsync(),n}};i.FUniver.extend(f)});
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/sheets`),require(`@univerjs/engine-render`),require(`@univerjs/find-replace`),require(`@univerjs/sheets-ui`),require(`rxjs`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets`,`@univerjs/engine-render`,`@univerjs/find-replace`,`@univerjs/sheets-ui`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsFindReplace={},e.UniverCore,e.UniverSheets,e.UniverEngineRender,e.UniverFindReplace,e.UniverSheetsUi,e.rxjs))})(this,function(e,t,n,r,i,a,o){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let s={id:`sheet.command.replace`,type:t.CommandType.COMMAND,handler:async(e,r)=>{let i=e.get(t.IUndoRedoService),a=e.get(t.ICommandService),{unitId:o,replacements:s}=r,l=i.__tempBatchingUndoRedo(o),u=await Promise.all(s.map(e=>a.executeCommand(n.SetRangeValuesCommand.id,{unitId:o,subUnitId:e.subUnitId,value:e.value})));return l.dispose(),c(u,s)}};function c(e,t){let n=0,r=0;return e.forEach((e,i)=>{let a=t[i].count;e?n+=a:r+=a}),{success:n,failure:r}}function l(e){"@babel/helpers - typeof";return l=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},l(e)}function u(e,t){if(l(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(l(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function d(e){var t=u(e,`string`);return l(t)==`symbol`?t:t+``}function f(e,t,n){return(t=d(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var p=class extends r.Shape{constructor(e,t){super(e,t),f(this,`_activated`,!1),f(this,`_inHiddenRange`,!1),f(this,`_color`,void 0),t&&this.setShapeProps(t)}setShapeProps(e){this._activated=!!e.activated,e.inHiddenRange!==void 0&&(this._inHiddenRange=e.inHiddenRange),e.color!==void 0&&(this._color=e.color),this.transformByState({width:e.width,height:e.height})}_draw(e){let t=this._activated,n=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 0.35)`,i=`rgb(${this._color.r}, ${this._color.g}, ${this._color.b})`;r.Rect.drawWith(e,{width:this.width,height:this.height,fill:n,stroke:t?i:void 0,strokeWidth:t?2:0,evented:!1})}};function m(e,t){return e.startRow===t.startRow&&e.startColumn===t.startColumn}function h(e,t){return e.startRow<t.startRow||e.startRow===t.startRow&&e.startColumn<=t.startColumn}function g(e,t){return e.startColumn<t.startColumn||e.startColumn===t.startColumn&&e.startRow<=t.startRow}function _(e,t){return e.startRow>t.startRow||e.startRow===t.startRow&&e.startColumn>=t.startColumn}function v(e,t){return e.startColumn>t.startColumn||e.startColumn===t.startColumn&&e.startRow>=t.startRow}function y(e,n){let{range:r}=e,{startRow:i,startColumn:a}=r,o=n.getMergedCell(i,a);return o?t.Rectangle.equals(r,o):r.endRow===r.startRow&&r.endColumn===r.startColumn}function b(e,t){return function(n,r){t(n,r,e)}}function x(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let S=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._injector=e,this._findReplaceController=t,this._contextService=n,this._findReplaceService=r,this._commandService=i,f(this,`_provider`,void 0),this._init(),this._initCommands()}dispose(){super.dispose(),this._findReplaceController.closePanel(),this._provider.dispose()}_init(){let e=this._injector.createInstance(T);this._provider=e,this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(e)),this.disposeWithMe(this._contextService.subscribeContextValue$(t.EDITOR_ACTIVATED).pipe((0,o.filter)(e=>!!e)).subscribe(()=>this._findReplaceController.closePanel()))}_initCommands(){[s].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}};S=x([b(0,(0,t.Inject)(t.Injector)),b(1,(0,t.Inject)(i.FindReplaceController)),b(2,t.IContextService),b(3,i.IFindReplaceService),b(4,t.ICommandService)],S);let C=class extends i.FindModel{get _matchesCount(){return this._matches.length}get unitId(){return this._workbook.getUnitId()}get matchesCount(){return this._matchesCount}get matchesPosition(){return this._matchesPosition}get currentMatch(){return this._matchesPosition>0?this._matches[this._matchesPosition-1]:null}constructor(e,t,n,r,i,a,s,c){super(),this._workbook=e,this._sheetSkeletonManagerService=t,this._univerInstanceService=n,this._renderManagerService=r,this._commandService=i,this._contextService=a,this._themeService=s,f(this,`_matchesUpdate$`,new o.Subject),f(this,`matchesUpdate$`,this._matchesUpdate$.asObservable()),f(this,`_activelyChangingMatch$`,new o.Subject),f(this,`activelyChangingMatch$`,this._activelyChangingMatch$.asObservable()),f(this,`_matchesByWorksheet`,new Map),f(this,`_matches`,[]),f(this,`_matchesPosition`,0),f(this,`_activeHighlightIndex`,-1),f(this,`_highlightShapes`,[]),f(this,`_currentHighlightShape`,null),f(this,`_query`,null),f(this,`_workbookSelections`,void 0),this._workbookSelections=c.getWorkbookSelections(this.unitId)}dispose(){super.dispose(),this._disposeHighlights(),this._toggleDisplayRawFormula(!1)}getMatches(){return this._matches}start(e){switch(this._query=e,e.findBy===i.FindBy.FORMULA?this._toggleDisplayRawFormula(!0):this._toggleDisplayRawFormula(!1),e.findScope){case i.FindScope.UNIT:this.findInWorkbook(e);break;case i.FindScope.SUBUNIT:default:this.findInActiveWorksheet(e);break}}focusSelection(){let e=this.currentMatch;e&&this._commandService.executeCommand(n.SelectRangeCommand.id,{unitId:e.unitId,subUnit:e.range.subUnitId,range:e.range.range})}_toggleDisplayRawFormula(e){this._contextService.setContextValue(r.RENDER_RAW_FORMULA_KEY,e)}findInWorkbook(e){let r=this._workbook.getUnitId(),i,a=!0,s=()=>{let t=this._workbook.getSheets().filter(e=>!e.isSheetHidden()).map(t=>{let n=this._findInWorksheet(t,e,r),i=t.getSheetId(),{results:a}=n;return a.length?this._matchesByWorksheet.set(i,n.results):this._matchesByWorksheet.delete(i),n});this._matches=t.map(e=>e.results).flat(),this._updateFindHighlight(),a?(i={results:this._matches},a=!1):this._matchesUpdate$.next(this._matches)};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>{this._updateFindHighlight(),this._updateCurrentHighlightShape(this._activeHighlightIndex)})),this.disposeWithMe((0,t.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0,o.filter)(([e,t])=>e.id===n.SetWorksheetActiveOperation.id&&!(t!=null&&t.fromFindReplace))).subscribe(()=>{let e=this._workbook.getActiveSheet();if(!e)return;let t=e.getSheetId();this._matchesByWorksheet.has(t)&&this._findNextMatchOnActiveSheetChange(e)})),this.disposeWithMe((0,t.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0,o.filter)(([e])=>e.type===t.CommandType.MUTATION&&e.params.unitId===this._workbook.getUnitId()),(0,o.throttleTime)(600,void 0,{leading:!1,trailing:!0})).subscribe(()=>s())),s(),i}_findNextMatchOnActiveSheetChange(e){let t,n,r=0,i=this._matchesByWorksheet.get(e.getSheetId()),a=this._workbookSelections.getCurrentSelections();a!=null&&a.length?([t,r]=this._findNextMatchByRange(i,a[0].range),n=i.findIndex(e=>e===t)):(t=i[0],n=0,r=this._matches.findIndex(e=>e===t)),this._matchesPosition=r+1,this._activelyChangingMatch$.next(t),this._activeHighlightIndex=n,this._updateFindHighlight(),this._updateCurrentHighlightShape(n)}findInActiveWorksheet(e){let r=this._workbook.getUnitId(),i=()=>{var e;let t=this._workbook.getActiveSheet();if(!t)return!1;let n=this._workbookSelections.getCurrentSelections();return(e=n==null?void 0:n.some(e=>!y(e,t)))==null?!1:e},a,s=!0,c=!1,l=()=>{let t=this._workbook.getActiveSheet();if(!t)return{results:[]};let n=this.currentMatch;c=i();let o=this._workbookSelections.getCurrentSelections(),l=c?this._findInSelections(t,o,e,r):this._findInWorksheet(t,e,r);return this._matches=l.results,this._matchesPosition=this._tryRestoreLastMatchesPosition(n,this._matches),s?(a=l,s=!1):this._matchesUpdate$.next(this._matches),this._updateFindHighlight(),l};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>this._updateFindHighlight())),this.disposeWithMe((0,o.merge)((0,t.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0,o.filter)(([e])=>{if(e.type===t.CommandType.MUTATION&&e.params.unitId===this._workbook.getUnitId())return!0;if(e.id===n.SetSelectionsOperation.id&&e.params.unitId===r){let e=i();return e===!1&&c===!1?!1:(c=e,!0)}return!1})),this._workbook.activeSheet$.pipe((0,o.skip)(1))).pipe((0,o.debounceTime)(200)).subscribe(()=>l())),l(),a}_findInRange(e,t,n,r,a){let o=[],s=e.getSheetId(),c=(t.findDirection===i.FindDirection.COLUMN?e.iterateByColumn:e.iterateByRow).bind(e)(n);for(let n of c){let{row:i,col:c,colSpan:l,rowSpan:u,value:d}=n;if(a!=null&&a(i,c)||!d||e.getRowFiltered(i))continue;let{hit:f,replaceable:p,isFormula:m}=D(e,i,c,t,d);if(f){let e={provider:`sheets-find-replace-provider`,unitId:r,replaceable:p,isFormula:m,range:{subUnitId:s,range:{startRow:i,startColumn:c,endColumn:c+(l==null?1:l)-1,endRow:i+(u==null?1:u)-1}}};o.push(e)}}return{results:o}}_findInSelections(e,t,n,r){let{findDirection:a}=n,o=a===i.FindDirection.ROW?h:g,s=new Set;return{results:t.map(t=>this._findInRange(e,n,t.range,r,(e,t)=>{let n=`${e}-${t}`;return s.has(n)?!0:(s.add(n),!1)}).results).flat().sort((e,t)=>o(e.range.range,t.range.range)?-1:1)}}_findInWorksheet(e,t,n){let r=e.getRowCount(),i=e.getColumnCount(),a={startRow:0,startColumn:0,endRow:r-1,endColumn:i-1};return this._findInRange(e,t,a,n)}_disposeHighlights(){var e;this._highlightShapes.forEach(e=>{var t;(t=e.getScene())==null||t.makeDirty(),e.dispose()}),this._highlightShapes=[],(e=this._currentHighlightShape)==null||e.dispose(),this._currentHighlightShape=null}_updateFindHighlight(){this._disposeHighlights();let e=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!e)return;let n=this._workbook.getUnitId(),r=this._renderManagerService.getRenderById(n);if(r==null)return;let{scene:i}=r,o=this._matches,s=new t.ColorKit(this._themeService.getColorFromTheme(`yellow.400`)).toRgb(),c=this._workbook.getActiveSheet();if(!c)return;let l=c.getSheetId(),u=o.filter(e=>e.range.subUnitId===l).map((t,n)=>{let{startColumn:r,startRow:o,endColumn:l,endRow:u}=t.range.range,d=(0,a.getCoordByCell)(o,r,i,e),f=(0,a.getCoordByCell)(u,l,i,e),{startX:m,startY:h}=d,{endX:g,endY:_}=f,v=!0;for(let e=o;e<=u;e++)if(c.getRowRawVisible(e)){v=!1;break}let y=!0;for(let e=r;e<=l;e++)if(c.getColVisible(e)){y=!1;break}let b=v||y,x={left:m,top:h,color:s,width:y?2:g-m,height:v?2:_-h,evented:!1,inHiddenRange:b,zIndex:1e4};return new p(`find-highlight-${n}`,x)});i.addObjects(u),this._highlightShapes=u,i.makeDirty()}_updateCurrentHighlightShape(e){var t;if((t=this._currentHighlightShape)==null||t.setShapeProps({activated:!1}),this._currentHighlightShape=null,e!==void 0){let t=this._highlightShapes[e];if(!t)return;this._currentHighlightShape=t,t.setShapeProps({activated:!0})}}_getSheetObject(){return(0,a.getSheetObject)(this._univerInstanceService,this._renderManagerService)}_focusMatch(e){var t;let r=e.range.subUnitId;r!==((t=this._workbook.getActiveSheet())==null?void 0:t.getSheetId())&&this._commandService.executeCommand(n.SetWorksheetActivateCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:r},{fromFindReplace:!0}),this._commandService.executeCommand(a.ScrollToCellCommand.id,{range:e.range.range},{fromFindReplace:!0})}_tryRestoreLastMatchesPosition(e,t){if(!e)return 0;let{subUnitId:n}=e.range,{startColumn:r,startRow:i}=e.range.range,a=t.findIndex(e=>{if(n!==e.range.subUnitId)return!1;let{startColumn:t,startRow:a}=e.range.range;return t===r&&a===i});return a>-1?a+1:0}moveToNextMatch(e){var t,n,r,a;if(!this._matches.length)return null;let o=(t=e==null?void 0:e.loop)==null?!1:t,s=(n=e==null?void 0:e.stayIfOnMatch)==null?!1:n,c=(r=e==null?void 0:e.noFocus)==null?!1:r,l=(a=e==null?void 0:e.ignoreSelection)==null?!1:a,u=this._findNextMatch(o,s,l);if(u){var d;let[e,t]=u;return this._matchesPosition=t+1,this._query.findScope===i.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(e.range.subUnitId).findIndex(t=>t===e):this._activeHighlightIndex=t,c||this._focusMatch(e),((d=this._workbook.getActiveSheet())==null?void 0:d.getSheetId())===e.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),e}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}moveToPreviousMatch(e){var t,n,r,a;if(!this._matches.length)return null;let o=(t=e==null?void 0:e.loop)==null?!1:t,s=(n=e==null?void 0:e.stayIfOnMatch)==null?!1:n,c=(r=e==null?void 0:e.noFocus)==null?!1:r,l=(a=e==null?void 0:e.ignoreSelection)==null?!1:a,u=this._findPreviousMatch(o,s,l);if(u){var d;let[e,t]=u;return this._matchesPosition=t+1,this._query.findScope===i.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(e.range.subUnitId).findIndex(t=>t===e):this._activeHighlightIndex=t,c||this._focusMatch(e),((d=this._workbook.getActiveSheet())==null?void 0:d.getSheetId())===e.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),e}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}_findPreviousMatch(e=!1,t=!1,n=!1){var r;if(this.currentMatch){let n=this._matches.findIndex(e=>e===this.currentMatch);if(t)return[this.currentMatch,n];let r=n-1;if(!e&&r<0)return null;let i=this._matches.length,a=(r+i)%i;return[this._matches[a],a]}let a=this._workbookSelections.getCurrentLastSelection();if(n||!a){let e=this._matches.length-1;return[this._matches[e],e]}if(this._query.findScope!==i.FindScope.UNIT)return this._findPreviousMatchByRange(this._matches,a.range);let o=(r=this._workbook.getActiveSheet())==null?void 0:r.getSheetId();if(!o)return null;let s=this._findPreviousWorksheetThatHasAMatch(o,e);return s?this._findPreviousMatchByRange(this._matchesByWorksheet.get(s),a.range):null}_findNextMatch(e=!1,t=!1,n=!1){var r;if(this.currentMatch){let n=this._matches.findIndex(e=>e===this.currentMatch);if(t)return[this.currentMatch,n];let r=n+1,i=this._matches.length;if(!e&&r>=i)return null;let a=r%i;return[this._matches[a],a]}let a=this._workbookSelections.getCurrentLastSelection();if(n||!a)return[this._matches[0],0];if(this._query.findScope!==i.FindScope.UNIT)return this._findNextMatchByRange(this._matches,a.range,t);let o=(r=this._workbook.getActiveSheet())==null?void 0:r.getSheetId();if(!o)return null;let s=this._findNextWorksheetThatHasAMatch(o,e);return s?this._findNextMatchByRange(this._matchesByWorksheet.get(s),a.range):null}_findPreviousWorksheetThatHasAMatch(e,n=!1){let r=this._workbook.getSheetOrders(),i=r.findIndex(t=>t===e),a=(n?(0,t.rotate)(r,i+1):r.slice(0,i+1)).findLast(e=>this._matchesByWorksheet.has(e));return a==null?null:a}_findNextWorksheetThatHasAMatch(e,n=!1){let r=this._workbook.getSheetOrders(),i=r.findIndex(t=>t===e),a=(n?(0,t.rotate)(r,i):r.slice(i)).find(e=>this._matchesByWorksheet.has(e));return a==null?null:a}_findNextMatchByRange(e,t,n=!1){let r=this._query.findDirection===i.FindDirection.ROW,a=e.findIndex(e=>{let i=e.range.range;if(!(r?h(t,i):g(t,i)))return!1;let a=m(t,i);return n?a:!a});a===-1&&(a=e.length-1);let o=e[a];return[o,this._matches.findIndex(e=>e===o)]}_findPreviousMatchByRange(e,t,n=!1){let r=this._query.findDirection===i.FindDirection.ROW,a=this._matches.findLastIndex(e=>{let i=e.range.range;if(!(r?_(t,i):v(t,i)))return!1;let a=m(t,i);return n?a:!a});a===-1&&(a=0);let o=e[a];return[o,this._matches.findIndex(e=>e===o)]}async replace(e){if(this._matchesCount===0||!this.currentMatch||!this._query||!this.currentMatch.replaceable)return!1;let t=this.currentMatch.range,r=this._workbook.getSheetBySheetId(this.currentMatch.range.subUnitId),a=this._getReplacedCellData(this.currentMatch,r,this._query.findBy===i.FindBy.FORMULA,this._query.findString,e,this._query.caseSensitive?`g`:`ig`),o={unitId:this.currentMatch.unitId,subUnitId:t.subUnitId,value:{[t.range.startRow]:{[t.range.startColumn]:a}}};return this._commandService.executeCommand(n.SetRangeValuesCommand.id,o)}async replaceAll(e){if(this._matchesCount===0||!this._query)return{success:0,failure:0};let n=this._workbook.getUnitId(),{findString:r,caseSensitive:a,findBy:o}=this._query,c=o===i.FindBy.FORMULA,l=a?`g`:`ig`,u=[];return(0,t.groupBy)(this._matches.filter(e=>e.replaceable),e=>e.range.subUnitId).forEach((n,i)=>{let a=new t.ObjectMatrix,o=this._workbook.getSheetBySheetId(i);n.forEach(t=>{let{startColumn:n,startRow:i}=t.range.range,s=this._getReplacedCellData(t,o,c,r,e,l);s&&a.setValue(i,n,s)}),u.push({count:n.length,subUnitId:i,value:a.getMatrix()})}),u?this._commandService.executeCommand(s.id,{unitId:n,replacements:u}):{success:0,failure:0}}_getReplacedCellData(e,n,r,i,a,o){var s;let{startRow:c,startColumn:l}=e.range.range,u=n.getCellRaw(c,l);if(e.isFormula)return r?{f:u.f.replace(new RegExp(w(i),o),a),v:null}:null;if((s=u.p)!=null&&s.body){let e=t.Tools.deepClone(u.p);return(0,t.replaceInDocumentBody)(e.body,i,a,this._query.caseSensitive),{p:e}}return{v:u.v.toString().replace(new RegExp(w(i),o),a)}}};C=x([b(2,t.IUniverInstanceService),b(3,r.IRenderManagerService),b(4,t.ICommandService),b(5,t.IContextService),b(6,(0,t.Inject)(t.ThemeService)),b(7,(0,t.Inject)(n.SheetsSelectionsService))],C);function w(e){return e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,`\\$&`)}let T=class extends t.Disposable{constructor(e,t,n){super(),this._univerInstanceService=e,this._renderManagerService=t,this._injector=n,f(this,`_findModelsByUnitId`,new Map)}async find(e){this._terminate();let n=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET);if(!n)return[];let r=this._preprocessQuery(e),i=this._renderManagerService.getRenderById(n.getUnitId()).with(a.SheetSkeletonManagerService),o=this._injector.createInstance(C,n,i);return this._findModelsByUnitId.set(n.getUnitId(),o),o.start(r),[o]}terminate(){this._terminate()}_terminate(){this._findModelsByUnitId.forEach(e=>e.dispose()),this._findModelsByUnitId.clear()}_preprocessQuery(e){let t=e.caseSensitive?e.findString:e.findString.toLowerCase();return t=t.trim(),{...e,findString:t}}};T=x([b(0,t.IUniverInstanceService),b(1,r.IRenderManagerService),b(2,(0,t.Inject)(t.Injector))],T);let E={hit:!1,replaceable:!1,isFormula:!1,rawData:null};function D(e,t,n,r,a){let{findBy:o}=r,s=o===i.FindBy.FORMULA,c=e.getCellRaw(t,n);return E.rawData=c,c!=null&&c.f?(E.isFormula=!0,s?O({v:c.f},r)?(E.hit=!0,E.replaceable=!0,E):(E.hit=!1,E.replaceable=!1,E):(E.replaceable=!1,O(a,r)?E.hit=!0:E.hit=!1,E)):(E.isFormula=!1,O(a,r)?c?(E.hit=!0,E.replaceable=!0):(E.hit=!0,E.replaceable=!1):(E.hit=!1,E.replaceable=!1),E)}function O(e,t){let n=k(e);return n?t.matchesTheWholeCell?(n=A(n),t.caseSensitive?n===t.findString:n.toLowerCase()===t.findString):t.caseSensitive?n.indexOf(t.findString)>-1:n.toLowerCase().indexOf(t.findString)>-1:!1}function k(e){var t,n;let r=(t=e==null||(n=e.p)==null||(n=n.body)==null?void 0:n.dataStream)==null?e==null?void 0:e.v:t;return typeof r==`number`?`${r}`:typeof r==`boolean`?r?`1`:`0`:r}function A(e){return e.replace(/^ +/g,``).replace(/ +$/g,``)}var j=`@univerjs/sheets-find-replace`,M=`0.24.0`;let N=`sheets-find-replace.config`;Symbol(N);let P={},F=class extends t.Plugin{constructor(e=P,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{...i}=(0,t.merge)({},P,this._config);this._configService.setConfig(N,i)}onStarting(){[[S]].forEach(e=>this._injector.add(e))}onSteady(){this._injector.get(S)}};f(F,`pluginName`,`SHEET_FIND_REPLACE_PLUGIN`),f(F,`packageName`,j),f(F,`version`,M),f(F,`type`,t.UniverInstanceType.UNIVER_SHEET),F=x([(0,t.DependentOn)(n.UniverSheetsPlugin,n.UniverSheetsPlugin,i.UniverFindReplacePlugin),b(1,(0,t.Inject)(t.Injector)),b(2,t.IConfigService)],F),e.SheetReplaceCommand=s,Object.defineProperty(e,`SheetsFindReplaceController`,{enumerable:!0,get:function(){return S}}),Object.defineProperty(e,`UniverSheetsFindReplacePlugin`,{enumerable:!0,get:function(){return F}})});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("@univerjs/engine-render"),require("@univerjs/find-replace"),require("@univerjs/sheets-ui"),require("rxjs")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets`,`@univerjs/engine-render`,`@univerjs/find-replace`,`@univerjs/sheets-ui`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsFindReplace={},e.UniverCore,e.UniverSheets,e.UniverEngineRender,e.UniverFindReplace,e.UniverSheetsUi,e.rxjs))})(this,function(e,t,n,r,i,a,o){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let s={id:`sheet.command.replace`,type:t.CommandType.COMMAND,handler:async(e,r)=>{let i=e.get(t.IUndoRedoService),a=e.get(t.ICommandService),{unitId:o,replacements:s}=r,l=i.__tempBatchingUndoRedo(o),u=await Promise.all(s.map(e=>a.executeCommand(n.SetRangeValuesCommand.id,{unitId:o,subUnitId:e.subUnitId,value:e.value})));return l.dispose(),c(u,s)}};function c(e,t){let n=0,r=0;return e.forEach((e,i)=>{let a=t[i].count;e?n+=a:r+=a}),{success:n,failure:r}}function l(e){"@babel/helpers - typeof";return l=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},l(e)}function u(e,t){if(l(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(l(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function d(e){var t=u(e,`string`);return l(t)==`symbol`?t:t+``}function f(e,t,n){return(t=d(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var p=class extends r.Shape{constructor(e,t){super(e,t),f(this,`_activated`,!1),f(this,`_inHiddenRange`,!1),f(this,`_color`,void 0),t&&this.setShapeProps(t)}setShapeProps(e){this._activated=!!e.activated,e.inHiddenRange!==void 0&&(this._inHiddenRange=e.inHiddenRange),e.color!==void 0&&(this._color=e.color),this.transformByState({width:e.width,height:e.height})}_draw(e){let t=this._activated,n=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 0.35)`,i=`rgb(${this._color.r}, ${this._color.g}, ${this._color.b})`;r.Rect.drawWith(e,{width:this.width,height:this.height,fill:n,stroke:t?i:void 0,strokeWidth:t?2:0,evented:!1})}};function m(e,t){return e.startRow===t.startRow&&e.startColumn===t.startColumn}function h(e,t){return e.startRow<t.startRow||e.startRow===t.startRow&&e.startColumn<=t.startColumn}function g(e,t){return e.startColumn<t.startColumn||e.startColumn===t.startColumn&&e.startRow<=t.startRow}function _(e,t){return e.startRow>t.startRow||e.startRow===t.startRow&&e.startColumn>=t.startColumn}function v(e,t){return e.startColumn>t.startColumn||e.startColumn===t.startColumn&&e.startRow>=t.startRow}function y(e,n){let{range:r}=e,{startRow:i,startColumn:a}=r,o=n.getMergedCell(i,a);return o?t.Rectangle.equals(r,o):r.endRow===r.startRow&&r.endColumn===r.startColumn}function b(e,t){return function(n,r){t(n,r,e)}}function x(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let S=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._injector=e,this._findReplaceController=t,this._contextService=n,this._findReplaceService=r,this._commandService=i,f(this,`_provider`,void 0),this._init(),this._initCommands()}dispose(){super.dispose(),this._findReplaceController.closePanel(),this._provider.dispose()}_init(){let e=this._injector.createInstance(w);this._provider=e,this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(e)),this.disposeWithMe(this._contextService.subscribeContextValue$(t.EDITOR_ACTIVATED).pipe((0,o.filter)(e=>!!e)).subscribe(()=>this._findReplaceController.closePanel()))}_initCommands(){[s].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}};S=x([b(0,(0,t.Inject)(t.Injector)),b(1,(0,t.Inject)(i.FindReplaceController)),b(2,t.IContextService),b(3,i.IFindReplaceService),b(4,t.ICommandService)],S);let C=class extends i.FindModel{get _matchesCount(){return this._matches.length}get unitId(){return this._workbook.getUnitId()}get matchesCount(){return this._matchesCount}get matchesPosition(){return this._matchesPosition}get currentMatch(){return this._matchesPosition>0?this._matches[this._matchesPosition-1]:null}constructor(e,t,n,r,i,a,s,c){super(),this._workbook=e,this._sheetSkeletonManagerService=t,this._univerInstanceService=n,this._renderManagerService=r,this._commandService=i,this._contextService=a,this._themeService=s,f(this,`_matchesUpdate$`,new o.Subject),f(this,`matchesUpdate$`,this._matchesUpdate$.asObservable()),f(this,`_activelyChangingMatch$`,new o.Subject),f(this,`activelyChangingMatch$`,this._activelyChangingMatch$.asObservable()),f(this,`_matchesByWorksheet`,new Map),f(this,`_matches`,[]),f(this,`_matchesPosition`,0),f(this,`_activeHighlightIndex`,-1),f(this,`_highlightShapes`,[]),f(this,`_currentHighlightShape`,null),f(this,`_query`,null),f(this,`_workbookSelections`,void 0),this._workbookSelections=c.getWorkbookSelections(this.unitId)}dispose(){super.dispose(),this._disposeHighlights(),this._toggleDisplayRawFormula(!1)}getMatches(){return this._matches}start(e){switch(this._query=e,e.findBy===i.FindBy.FORMULA?this._toggleDisplayRawFormula(!0):this._toggleDisplayRawFormula(!1),e.findScope){case i.FindScope.UNIT:this.findInWorkbook(e);break;case i.FindScope.SUBUNIT:default:this.findInActiveWorksheet(e);break}}focusSelection(){let e=this.currentMatch;e&&this._commandService.executeCommand(n.SelectRangeCommand.id,{unitId:e.unitId,subUnit:e.range.subUnitId,range:e.range.range})}_toggleDisplayRawFormula(e){this._contextService.setContextValue(r.RENDER_RAW_FORMULA_KEY,e)}findInWorkbook(e){let r=this._workbook.getUnitId(),i,a=!0,s=()=>{let t=this._workbook.getSheets().filter(e=>!e.isSheetHidden()).map(t=>{let n=this._findInWorksheet(t,e,r),i=t.getSheetId(),{results:a}=n;return a.length?this._matchesByWorksheet.set(i,n.results):this._matchesByWorksheet.delete(i),n});this._matches=t.map(e=>e.results).flat(),this._updateFindHighlight(),a?(i={results:this._matches},a=!1):this._matchesUpdate$.next(this._matches)};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>{this._updateFindHighlight(),this._updateCurrentHighlightShape(this._activeHighlightIndex)})),this.disposeWithMe((0,t.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0,o.filter)(([e,t])=>e.id===n.SetWorksheetActiveOperation.id&&!(t!=null&&t.fromFindReplace))).subscribe(()=>{let e=this._workbook.getActiveSheet();if(!e)return;let t=e.getSheetId();this._matchesByWorksheet.has(t)&&this._findNextMatchOnActiveSheetChange(e)})),this.disposeWithMe((0,t.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0,o.filter)(([e])=>e.type===t.CommandType.MUTATION&&e.params.unitId===this._workbook.getUnitId()),(0,o.throttleTime)(600,void 0,{leading:!1,trailing:!0})).subscribe(()=>s())),s(),i}_findNextMatchOnActiveSheetChange(e){let t,n,r=0,i=this._matchesByWorksheet.get(e.getSheetId()),a=this._workbookSelections.getCurrentSelections();a!=null&&a.length?([t,r]=this._findNextMatchByRange(i,a[0].range),n=i.findIndex(e=>e===t)):(t=i[0],n=0,r=this._matches.findIndex(e=>e===t)),this._matchesPosition=r+1,this._activelyChangingMatch$.next(t),this._activeHighlightIndex=n,this._updateFindHighlight(),this._updateCurrentHighlightShape(n)}findInActiveWorksheet(e){let r=this._workbook.getUnitId(),i=()=>{var e;let t=this._workbook.getActiveSheet();if(!t)return!1;let n=this._workbookSelections.getCurrentSelections();return(e=n==null?void 0:n.some(e=>!y(e,t)))==null?!1:e},a,s=!0,c=!1,l=()=>{let t=this._workbook.getActiveSheet();if(!t)return{results:[]};let n=this.currentMatch;c=i();let o=this._workbookSelections.getCurrentSelections(),l=c?this._findInSelections(t,o,e,r):this._findInWorksheet(t,e,r);return this._matches=l.results,this._matchesPosition=this._tryRestoreLastMatchesPosition(n,this._matches),s?(a=l,s=!1):this._matchesUpdate$.next(this._matches),this._updateFindHighlight(),l};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>this._updateFindHighlight())),this.disposeWithMe((0,o.merge)((0,t.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0,o.filter)(([e])=>{if(e.type===t.CommandType.MUTATION&&e.params.unitId===this._workbook.getUnitId())return!0;if(e.id===n.SetSelectionsOperation.id&&e.params.unitId===r){let e=i();return e===!1&&c===!1?!1:(c=e,!0)}return!1})),this._workbook.activeSheet$.pipe((0,o.skip)(1))).pipe((0,o.debounceTime)(200)).subscribe(()=>l())),l(),a}_findInRange(e,t,n,r,a){let o=[],s=e.getSheetId(),c=(t.findDirection===i.FindDirection.COLUMN?e.iterateByColumn:e.iterateByRow).bind(e)(n);for(let n of c){let{row:i,col:c,colSpan:l,rowSpan:u,value:d}=n;if(a!=null&&a(i,c)||!d||e.getRowFiltered(i))continue;let{hit:f,replaceable:p,isFormula:m}=E(e,i,c,t,d);if(f){let e={provider:`sheets-find-replace-provider`,unitId:r,replaceable:p,isFormula:m,range:{subUnitId:s,range:{startRow:i,startColumn:c,endColumn:c+(l==null?1:l)-1,endRow:i+(u==null?1:u)-1}}};o.push(e)}}return{results:o}}_findInSelections(e,t,n,r){let{findDirection:a}=n,o=a===i.FindDirection.ROW?h:g,s=new Set;return{results:t.map(t=>this._findInRange(e,n,t.range,r,(e,t)=>{let n=`${e}-${t}`;return s.has(n)?!0:(s.add(n),!1)}).results).flat().sort((e,t)=>o(e.range.range,t.range.range)?-1:1)}}_findInWorksheet(e,t,n){let r=e.getRowCount(),i=e.getColumnCount(),a={startRow:0,startColumn:0,endRow:r-1,endColumn:i-1};return this._findInRange(e,t,a,n)}_disposeHighlights(){var e;this._highlightShapes.forEach(e=>{var t;(t=e.getScene())==null||t.makeDirty(),e.dispose()}),this._highlightShapes=[],(e=this._currentHighlightShape)==null||e.dispose(),this._currentHighlightShape=null}_updateFindHighlight(){this._disposeHighlights();let e=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!e)return;let n=this._workbook.getUnitId(),r=this._renderManagerService.getRenderById(n);if(r==null)return;let{scene:i}=r,o=this._matches,s=new t.ColorKit(this._themeService.getColorFromTheme(`yellow.400`)).toRgb(),c=this._workbook.getActiveSheet();if(!c)return;let l=c.getSheetId(),u=o.filter(e=>e.range.subUnitId===l).map((t,n)=>{let{startColumn:r,startRow:o,endColumn:l,endRow:u}=t.range.range,d=(0,a.getCoordByCell)(o,r,i,e),f=(0,a.getCoordByCell)(u,l,i,e),{startX:m,startY:h}=d,{endX:g,endY:_}=f,v=!0;for(let e=o;e<=u;e++)if(c.getRowRawVisible(e)){v=!1;break}let y=!0;for(let e=r;e<=l;e++)if(c.getColVisible(e)){y=!1;break}let b=v||y,x={left:m,top:h,color:s,width:y?2:g-m,height:v?2:_-h,evented:!1,inHiddenRange:b,zIndex:1e4};return new p(`find-highlight-${n}`,x)});i.addObjects(u),this._highlightShapes=u,i.makeDirty()}_updateCurrentHighlightShape(e){var t;if((t=this._currentHighlightShape)==null||t.setShapeProps({activated:!1}),this._currentHighlightShape=null,e!==void 0){let t=this._highlightShapes[e];if(!t)return;this._currentHighlightShape=t,t.setShapeProps({activated:!0})}}_getSheetObject(){return(0,a.getSheetObject)(this._univerInstanceService,this._renderManagerService)}async _focusMatch(e){var t;let{subUnitId:r,range:i}=e.range;if(r!==((t=this._workbook.getActiveSheet())==null?void 0:t.getSheetId())){let e=this._workbook.getUnitId();await this._commandService.executeCommand(n.SetWorksheetActivateCommand.id,{unitId:e,subUnitId:r},{fromFindReplace:!0})}this._commandService.executeCommand(a.ScrollToCellCommand.id,{range:i},{fromFindReplace:!0})}_tryRestoreLastMatchesPosition(e,t){if(!e)return 0;let{subUnitId:n}=e.range,{startColumn:r,startRow:i}=e.range.range,a=t.findIndex(e=>{if(n!==e.range.subUnitId)return!1;let{startColumn:t,startRow:a}=e.range.range;return t===r&&a===i});return a>-1?a+1:0}moveToNextMatch(e){var t,n,r,a;if(!this._matches.length)return null;let o=(t=e==null?void 0:e.loop)==null?!1:t,s=(n=e==null?void 0:e.stayIfOnMatch)==null?!1:n,c=(r=e==null?void 0:e.noFocus)==null?!1:r,l=(a=e==null?void 0:e.ignoreSelection)==null?!1:a,u=this._findNextMatch(o,s,l);if(u){let[e,t]=u;return this._matchesPosition=t+1,this._query.findScope===i.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(e.range.subUnitId).findIndex(t=>t===e):this._activeHighlightIndex=t,c||this._focusMatch(e),this._updateCurrentHighlightShape(this._activeHighlightIndex),e}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}moveToPreviousMatch(e){var t,n,r,a;if(!this._matches.length)return null;let o=(t=e==null?void 0:e.loop)==null?!1:t,s=(n=e==null?void 0:e.stayIfOnMatch)==null?!1:n,c=(r=e==null?void 0:e.noFocus)==null?!1:r,l=(a=e==null?void 0:e.ignoreSelection)==null?!1:a,u=this._findPreviousMatch(o,s,l);if(u){let[e,t]=u;return this._matchesPosition=t+1,this._query.findScope===i.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(e.range.subUnitId).findIndex(t=>t===e):this._activeHighlightIndex=t,c||this._focusMatch(e),this._updateCurrentHighlightShape(this._activeHighlightIndex),e}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}_findPreviousMatch(e=!1,t=!1,n=!1){var r;if(this.currentMatch){let n=this._matches.findIndex(e=>e===this.currentMatch);if(t)return[this.currentMatch,n];let r=n-1;if(!e&&r<0)return null;let i=this._matches.length,a=(r+i)%i;return[this._matches[a],a]}let a=this._workbookSelections.getCurrentLastSelection();if(n||!a){let e=this._matches.length-1;return[this._matches[e],e]}if(this._query.findScope!==i.FindScope.UNIT)return this._findPreviousMatchByRange(this._matches,a.range);let o=(r=this._workbook.getActiveSheet())==null?void 0:r.getSheetId();if(!o)return null;let s=this._findPreviousWorksheetThatHasAMatch(o,e);return s?this._findPreviousMatchByRange(this._matchesByWorksheet.get(s),a.range):null}_findNextMatch(e=!1,t=!1,n=!1){var r;if(this.currentMatch){let n=this._matches.findIndex(e=>e===this.currentMatch);if(t)return[this.currentMatch,n];let r=n+1,i=this._matches.length;if(!e&&r>=i)return null;let a=r%i;return[this._matches[a],a]}let a=this._workbookSelections.getCurrentLastSelection();if(n||!a)return[this._matches[0],0];if(this._query.findScope!==i.FindScope.UNIT)return this._findNextMatchByRange(this._matches,a.range,t);let o=(r=this._workbook.getActiveSheet())==null?void 0:r.getSheetId();if(!o)return null;let s=this._findNextWorksheetThatHasAMatch(o,e);return s?this._findNextMatchByRange(this._matchesByWorksheet.get(s),a.range):null}_findPreviousWorksheetThatHasAMatch(e,n=!1){let r=this._workbook.getSheetOrders(),i=r.findIndex(t=>t===e),a=(n?(0,t.rotate)(r,i+1):r.slice(0,i+1)).findLast(e=>this._matchesByWorksheet.has(e));return a==null?null:a}_findNextWorksheetThatHasAMatch(e,n=!1){let r=this._workbook.getSheetOrders(),i=r.findIndex(t=>t===e),a=(n?(0,t.rotate)(r,i):r.slice(i)).find(e=>this._matchesByWorksheet.has(e));return a==null?null:a}_findNextMatchByRange(e,t,n=!1){let r=this._query.findDirection===i.FindDirection.ROW,a=e.findIndex(e=>{let i=e.range.range;if(!(r?h(t,i):g(t,i)))return!1;let a=m(t,i);return n?a:!a});a===-1&&(a=e.length-1);let o=e[a];return[o,this._matches.findIndex(e=>e===o)]}_findPreviousMatchByRange(e,t,n=!1){let r=this._query.findDirection===i.FindDirection.ROW,a=this._matches.findLastIndex(e=>{let i=e.range.range;if(!(r?_(t,i):v(t,i)))return!1;let a=m(t,i);return n?a:!a});a===-1&&(a=0);let o=e[a];return[o,this._matches.findIndex(e=>e===o)]}async replace(e){if(this._matchesCount===0||!this.currentMatch||!this._query||!this.currentMatch.replaceable)return!1;let t=this.currentMatch.range,r=this._workbook.getSheetBySheetId(this.currentMatch.range.subUnitId),a=this._getReplacedCellData(this.currentMatch,r,this._query.findBy===i.FindBy.FORMULA,this._query.findString,e,this._query.caseSensitive?`g`:`ig`),o={unitId:this.currentMatch.unitId,subUnitId:t.subUnitId,value:{[t.range.startRow]:{[t.range.startColumn]:a}}};return this._commandService.executeCommand(n.SetRangeValuesCommand.id,o)}async replaceAll(e){if(this._matchesCount===0||!this._query)return{success:0,failure:0};let n=this._workbook.getUnitId(),{findString:r,caseSensitive:a,findBy:o}=this._query,c=o===i.FindBy.FORMULA,l=a?`g`:`ig`,u=[];return(0,t.groupBy)(this._matches.filter(e=>e.replaceable),e=>e.range.subUnitId).forEach((n,i)=>{let a=new t.ObjectMatrix,o=this._workbook.getSheetBySheetId(i);n.forEach(t=>{let{startColumn:n,startRow:i}=t.range.range,s=this._getReplacedCellData(t,o,c,r,e,l);s&&a.setValue(i,n,s)}),u.push({count:n.length,subUnitId:i,value:a.getMatrix()})}),u?this._commandService.executeCommand(s.id,{unitId:n,replacements:u}):{success:0,failure:0}}_getReplacedCellData(e,n,r,i,a,o){var s;let{startRow:c,startColumn:l}=e.range.range,u=n.getCellRaw(c,l);if(e.isFormula)return r?{f:u.f.replace(new RegExp((0,t.escapeRegExp)(i),o),a),v:null}:null;if((s=u.p)!=null&&s.body){let e=t.Tools.deepClone(u.p);return(0,t.replaceInDocumentBody)(e.body,i,a,this._query.caseSensitive),{p:e}}return{v:u.v.toString().replace(new RegExp((0,t.escapeRegExp)(i),o),a)}}};C=x([b(2,t.IUniverInstanceService),b(3,r.IRenderManagerService),b(4,t.ICommandService),b(5,t.IContextService),b(6,(0,t.Inject)(t.ThemeService)),b(7,(0,t.Inject)(n.SheetsSelectionsService))],C);let w=class extends t.Disposable{constructor(e,t,n){super(),this._univerInstanceService=e,this._renderManagerService=t,this._injector=n,f(this,`_findModelsByUnitId`,new Map)}async find(e){this._terminate();let n=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET);if(!n)return[];let r=this._preprocessQuery(e),i=this._renderManagerService.getRenderById(n.getUnitId()).with(a.SheetSkeletonManagerService),o=this._injector.createInstance(C,n,i);return this._findModelsByUnitId.set(n.getUnitId(),o),o.start(r),[o]}terminate(){this._terminate()}_terminate(){this._findModelsByUnitId.forEach(e=>e.dispose()),this._findModelsByUnitId.clear()}_preprocessQuery(e){let t=e.caseSensitive?e.findString:e.findString.toLowerCase();return t=t.trim(),{...e,findString:t}}};w=x([b(0,t.IUniverInstanceService),b(1,r.IRenderManagerService),b(2,(0,t.Inject)(t.Injector))],w);let T={hit:!1,replaceable:!1,isFormula:!1,rawData:null};function E(e,t,n,r,a){let{findBy:o}=r,s=o===i.FindBy.FORMULA,c=e.getCellRaw(t,n);return T.rawData=c,c!=null&&c.f?(T.isFormula=!0,s?D({v:c.f},r)?(T.hit=!0,T.replaceable=!0,T):(T.hit=!1,T.replaceable=!1,T):(T.replaceable=!1,D(a,r)?T.hit=!0:T.hit=!1,T)):(T.isFormula=!1,D(a,r)?c?(T.hit=!0,T.replaceable=!0):(T.hit=!0,T.replaceable=!1):(T.hit=!1,T.replaceable=!1),T)}function D(e,t){let n=O(e);return n?t.matchesTheWholeCell?(n=k(n),t.caseSensitive?n===t.findString:n.toLowerCase()===t.findString):t.caseSensitive?n.indexOf(t.findString)>-1:n.toLowerCase().indexOf(t.findString)>-1:!1}function O(e){var t,n;let r=(t=e==null||(n=e.p)==null||(n=n.body)==null?void 0:n.dataStream)==null?e==null?void 0:e.v:t;return typeof r==`number`?`${r}`:typeof r==`boolean`?r?`1`:`0`:r}function k(e){return e.replace(/^ +/g,``).replace(/ +$/g,``)}var A=`@univerjs/sheets-find-replace`,j=`0.25.0-insiders.20260608-e4336f7`;let M={},N=class extends t.Plugin{constructor(e=M,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{...i}=(0,t.merge)({},M,this._config);this._configService.setConfig(`sheets-find-replace.config`,i)}onStarting(){[[S]].forEach(e=>this._injector.add(e))}onSteady(){this._injector.get(S)}};f(N,`pluginName`,`SHEET_FIND_REPLACE_PLUGIN`),f(N,`packageName`,A),f(N,`version`,j),f(N,`type`,t.UniverInstanceType.UNIVER_SHEET),N=x([(0,t.DependentOn)(n.UniverSheetsPlugin,n.UniverSheetsPlugin,i.UniverFindReplacePlugin),b(1,(0,t.Inject)(t.Injector)),b(2,t.IConfigService)],N),e.SheetReplaceCommand=s,Object.defineProperty(e,"SheetsFindReplaceController",{enumerable:!0,get:function(){return S}}),Object.defineProperty(e,"UniverSheetsFindReplacePlugin",{enumerable:!0,get:function(){return N}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-find-replace",
3
- "version": "0.24.0",
3
+ "version": "0.25.0-insiders.20260608-e4336f7",
4
4
  "private": false,
5
5
  "description": "Find and replace integration for Univer Sheets.",
6
6
  "author": "DreamNum Co., Ltd. <developer@univer.ai>",
@@ -35,11 +35,6 @@
35
35
  "require": "./lib/cjs/*",
36
36
  "types": "./lib/types/index.d.ts"
37
37
  },
38
- "./locale/*": {
39
- "import": "./lib/es/locale/*.js",
40
- "require": "./lib/cjs/locale/*.js",
41
- "types": "./lib/types/locale/*.d.ts"
42
- },
43
38
  "./facade": {
44
39
  "import": "./lib/es/facade.js",
45
40
  "require": "./lib/cjs/facade.js",
@@ -67,17 +62,17 @@
67
62
  "rxjs": ">=7.0.0"
68
63
  },
69
64
  "dependencies": {
70
- "@univerjs/core": "0.24.0",
71
- "@univerjs/find-replace": "0.24.0",
72
- "@univerjs/engine-render": "0.24.0",
73
- "@univerjs/sheets": "0.24.0",
74
- "@univerjs/sheets-ui": "0.24.0"
65
+ "@univerjs/core": "0.25.0-insiders.20260608-e4336f7",
66
+ "@univerjs/find-replace": "0.25.0-insiders.20260608-e4336f7",
67
+ "@univerjs/sheets": "0.25.0-insiders.20260608-e4336f7",
68
+ "@univerjs/engine-render": "0.25.0-insiders.20260608-e4336f7",
69
+ "@univerjs/sheets-ui": "0.25.0-insiders.20260608-e4336f7"
75
70
  },
76
71
  "devDependencies": {
77
72
  "rxjs": "^7.8.2",
78
73
  "typescript": "^6.0.3",
79
- "vitest": "^4.1.5",
80
- "@univerjs-infra/shared": "0.24.0"
74
+ "vitest": "^4.1.8",
75
+ "@univerjs-infra/shared": "0.25.0"
81
76
  },
82
77
  "scripts": {
83
78
  "test": "vitest run",
package/LICENSE DELETED
@@ -1,176 +0,0 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS
@@ -1,9 +0,0 @@
1
-
2
- //#region src/locale/ca-ES.ts
3
- const locale = { "sheet-find-replace": { replace: {
4
- "partial-failure": "No s’ha pogut substituir algunes cel·les",
5
- failure: "No s’ha pogut substituir cap cel·la"
6
- } } };
7
-
8
- //#endregion
9
- module.exports = locale;