@univerjs/sheets-find-replace 0.23.0 → 0.24.0-insiders.20260528-29f582d

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 (68) hide show
  1. package/lib/cjs/index.js +19 -21
  2. package/lib/es/index.js +18 -20
  3. package/lib/index.js +18 -20
  4. package/lib/types/facade/f-text-finder.d.ts +18 -9
  5. package/lib/types/facade/f-univer.d.ts +2 -1
  6. package/lib/umd/index.js +1 -1
  7. package/package.json +7 -12
  8. package/LICENSE +0 -176
  9. package/lib/cjs/locale/ca-ES.js +0 -9
  10. package/lib/cjs/locale/en-US.js +0 -24
  11. package/lib/cjs/locale/es-ES.js +0 -9
  12. package/lib/cjs/locale/fa-IR.js +0 -9
  13. package/lib/cjs/locale/fr-FR.js +0 -9
  14. package/lib/cjs/locale/ja-JP.js +0 -9
  15. package/lib/cjs/locale/ko-KR.js +0 -9
  16. package/lib/cjs/locale/ru-RU.js +0 -9
  17. package/lib/cjs/locale/sk-SK.js +0 -9
  18. package/lib/cjs/locale/vi-VN.js +0 -9
  19. package/lib/cjs/locale/zh-CN.js +0 -24
  20. package/lib/cjs/locale/zh-TW.js +0 -9
  21. package/lib/es/locale/ca-ES.js +0 -8
  22. package/lib/es/locale/en-US.js +0 -23
  23. package/lib/es/locale/es-ES.js +0 -8
  24. package/lib/es/locale/fa-IR.js +0 -8
  25. package/lib/es/locale/fr-FR.js +0 -8
  26. package/lib/es/locale/ja-JP.js +0 -8
  27. package/lib/es/locale/ko-KR.js +0 -8
  28. package/lib/es/locale/ru-RU.js +0 -8
  29. package/lib/es/locale/sk-SK.js +0 -8
  30. package/lib/es/locale/vi-VN.js +0 -8
  31. package/lib/es/locale/zh-CN.js +0 -23
  32. package/lib/es/locale/zh-TW.js +0 -8
  33. package/lib/locale/ca-ES.js +0 -8
  34. package/lib/locale/en-US.js +0 -23
  35. package/lib/locale/es-ES.js +0 -8
  36. package/lib/locale/fa-IR.js +0 -8
  37. package/lib/locale/fr-FR.js +0 -8
  38. package/lib/locale/ja-JP.js +0 -8
  39. package/lib/locale/ko-KR.js +0 -8
  40. package/lib/locale/ru-RU.js +0 -8
  41. package/lib/locale/sk-SK.js +0 -8
  42. package/lib/locale/vi-VN.js +0 -8
  43. package/lib/locale/zh-CN.js +0 -23
  44. package/lib/locale/zh-TW.js +0 -8
  45. package/lib/types/locale/ca-ES.d.ts +0 -18
  46. package/lib/types/locale/en-US.d.ts +0 -24
  47. package/lib/types/locale/es-ES.d.ts +0 -18
  48. package/lib/types/locale/fa-IR.d.ts +0 -18
  49. package/lib/types/locale/fr-FR.d.ts +0 -18
  50. package/lib/types/locale/ja-JP.d.ts +0 -18
  51. package/lib/types/locale/ko-KR.d.ts +0 -18
  52. package/lib/types/locale/ru-RU.d.ts +0 -18
  53. package/lib/types/locale/sk-SK.d.ts +0 -18
  54. package/lib/types/locale/vi-VN.d.ts +0 -18
  55. package/lib/types/locale/zh-CN.d.ts +0 -24
  56. package/lib/types/locale/zh-TW.d.ts +0 -18
  57. package/lib/umd/locale/ca-ES.js +0 -1
  58. package/lib/umd/locale/en-US.js +0 -1
  59. package/lib/umd/locale/es-ES.js +0 -1
  60. package/lib/umd/locale/fa-IR.js +0 -1
  61. package/lib/umd/locale/fr-FR.js +0 -1
  62. package/lib/umd/locale/ja-JP.js +0 -1
  63. package/lib/umd/locale/ko-KR.js +0 -1
  64. package/lib/umd/locale/ru-RU.js +0 -1
  65. package/lib/umd/locale/sk-SK.js +0 -1
  66. package/lib/umd/locale/vi-VN.js +0 -1
  67. package/lib/umd/locale/zh-CN.js +0 -1
  68. package/lib/umd/locale/zh-TW.js +0 -1
package/lib/cjs/index.js CHANGED
@@ -527,14 +527,17 @@ let SheetFindModel = class SheetFindModel extends _univerjs_find_replace.FindMod
527
527
  _getSheetObject() {
528
528
  return (0, _univerjs_sheets_ui.getSheetObject)(this._univerInstanceService, this._renderManagerService);
529
529
  }
530
- _focusMatch(match) {
530
+ async _focusMatch(match) {
531
531
  var _this$_workbook$getAc;
532
- const subUnitId = match.range.subUnitId;
533
- if (subUnitId !== ((_this$_workbook$getAc = this._workbook.getActiveSheet()) === null || _this$_workbook$getAc === void 0 ? void 0 : _this$_workbook$getAc.getSheetId())) this._commandService.executeCommand(_univerjs_sheets.SetWorksheetActivateCommand.id, {
534
- unitId: this._workbook.getUnitId(),
535
- subUnitId
536
- }, { fromFindReplace: true });
537
- this._commandService.executeCommand(_univerjs_sheets_ui.ScrollToCellCommand.id, { range: match.range.range }, { fromFindReplace: true });
532
+ const { subUnitId, range } = match.range;
533
+ if (subUnitId !== ((_this$_workbook$getAc = this._workbook.getActiveSheet()) === null || _this$_workbook$getAc === void 0 ? void 0 : _this$_workbook$getAc.getSheetId())) {
534
+ const unitId = this._workbook.getUnitId();
535
+ await this._commandService.executeCommand(_univerjs_sheets.SetWorksheetActivateCommand.id, {
536
+ unitId,
537
+ subUnitId
538
+ }, { fromFindReplace: true });
539
+ }
540
+ this._commandService.executeCommand(_univerjs_sheets_ui.ScrollToCellCommand.id, { range }, { fromFindReplace: true });
538
541
  }
539
542
  _tryRestoreLastMatchesPosition(lastMatch, newMatches) {
540
543
  if (!lastMatch) return 0;
@@ -556,13 +559,12 @@ let SheetFindModel = class SheetFindModel extends _univerjs_find_replace.FindMod
556
559
  const ignoreSelection = (_params$ignoreSelecti = params === null || params === void 0 ? void 0 : params.ignoreSelection) !== null && _params$ignoreSelecti !== void 0 ? _params$ignoreSelecti : false;
557
560
  const matchToMove = this._findNextMatch(loop, stayIfOnMatch, ignoreSelection);
558
561
  if (matchToMove) {
559
- var _this$_workbook$getAc2;
560
562
  const [match, index] = matchToMove;
561
563
  this._matchesPosition = index + 1;
562
564
  if (this._query.findScope === _univerjs_find_replace.FindScope.UNIT) this._activeHighlightIndex = this._matchesByWorksheet.get(match.range.subUnitId).findIndex((m) => m === match);
563
565
  else this._activeHighlightIndex = index;
564
566
  if (!noFocus) this._focusMatch(match);
565
- 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);
567
+ this._updateCurrentHighlightShape(this._activeHighlightIndex);
566
568
  return match;
567
569
  }
568
570
  this._matchesPosition = 0;
@@ -578,13 +580,12 @@ let SheetFindModel = class SheetFindModel extends _univerjs_find_replace.FindMod
578
580
  const ignoreSelection = (_params$ignoreSelecti2 = params === null || params === void 0 ? void 0 : params.ignoreSelection) !== null && _params$ignoreSelecti2 !== void 0 ? _params$ignoreSelecti2 : false;
579
581
  const matchToMove = this._findPreviousMatch(loop, stayIfOnMatch, ignoreSelection);
580
582
  if (matchToMove) {
581
- var _this$_workbook$getAc3;
582
583
  const [match, index] = matchToMove;
583
584
  this._matchesPosition = index + 1;
584
585
  if (this._query.findScope === _univerjs_find_replace.FindScope.UNIT) this._activeHighlightIndex = this._matchesByWorksheet.get(match.range.subUnitId).findIndex((m) => m === match);
585
586
  else this._activeHighlightIndex = index;
586
587
  if (!noFocus) this._focusMatch(match);
587
- 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);
588
+ this._updateCurrentHighlightShape(this._activeHighlightIndex);
588
589
  return match;
589
590
  }
590
591
  this._matchesPosition = 0;
@@ -592,7 +593,7 @@ let SheetFindModel = class SheetFindModel extends _univerjs_find_replace.FindMod
592
593
  return null;
593
594
  }
594
595
  _findPreviousMatch(loop = false, stayIfOnMatch = false, ignoreSelection = false) {
595
- var _this$_workbook$getAc4;
596
+ var _this$_workbook$getAc2;
596
597
  if (this.currentMatch) {
597
598
  const currentMatchIndex = this._matches.findIndex((match) => match === this.currentMatch);
598
599
  if (stayIfOnMatch) return [this.currentMatch, currentMatchIndex];
@@ -608,14 +609,14 @@ let SheetFindModel = class SheetFindModel extends _univerjs_find_replace.FindMod
608
609
  return [this._matches[lastIndex], lastIndex];
609
610
  }
610
611
  if (this._query.findScope !== _univerjs_find_replace.FindScope.UNIT) return this._findPreviousMatchByRange(this._matches, lastSelection.range);
611
- const currentSheetId = (_this$_workbook$getAc4 = this._workbook.getActiveSheet()) === null || _this$_workbook$getAc4 === void 0 ? void 0 : _this$_workbook$getAc4.getSheetId();
612
+ const currentSheetId = (_this$_workbook$getAc2 = this._workbook.getActiveSheet()) === null || _this$_workbook$getAc2 === void 0 ? void 0 : _this$_workbook$getAc2.getSheetId();
612
613
  if (!currentSheetId) return null;
613
614
  const worksheetThatHasMatch = this._findPreviousWorksheetThatHasAMatch(currentSheetId, loop);
614
615
  if (!worksheetThatHasMatch) return null;
615
616
  return this._findPreviousMatchByRange(this._matchesByWorksheet.get(worksheetThatHasMatch), lastSelection.range);
616
617
  }
617
618
  _findNextMatch(loop = false, stayIfOnMatch = false, ignoreSelection = false) {
618
- var _this$_workbook$getAc5;
619
+ var _this$_workbook$getAc3;
619
620
  if (this.currentMatch) {
620
621
  const currentMatchIndex = this._matches.findIndex((match) => match === this.currentMatch);
621
622
  if (stayIfOnMatch) return [this.currentMatch, currentMatchIndex];
@@ -628,7 +629,7 @@ let SheetFindModel = class SheetFindModel extends _univerjs_find_replace.FindMod
628
629
  const last = this._workbookSelections.getCurrentLastSelection();
629
630
  if (ignoreSelection || !last) return [this._matches[0], 0];
630
631
  if (this._query.findScope !== _univerjs_find_replace.FindScope.UNIT) return this._findNextMatchByRange(this._matches, last.range, stayIfOnMatch);
631
- const currentSheetId = (_this$_workbook$getAc5 = this._workbook.getActiveSheet()) === null || _this$_workbook$getAc5 === void 0 ? void 0 : _this$_workbook$getAc5.getSheetId();
632
+ const currentSheetId = (_this$_workbook$getAc3 = this._workbook.getActiveSheet()) === null || _this$_workbook$getAc3 === void 0 ? void 0 : _this$_workbook$getAc3.getSheetId();
632
633
  if (!currentSheetId) return null;
633
634
  const worksheetThatHasMatch = this._findNextWorksheetThatHasAMatch(currentSheetId, loop);
634
635
  if (!worksheetThatHasMatch) return null;
@@ -722,7 +723,7 @@ let SheetFindModel = class SheetFindModel extends _univerjs_find_replace.FindMod
722
723
  if (match.isFormula) {
723
724
  if (!shouldReplaceFormula) return null;
724
725
  return {
725
- f: currentContent.f.replace(new RegExp(escapeRegExp(findString), replaceFlag), replaceString),
726
+ f: currentContent.f.replace(new RegExp((0, _univerjs_core.escapeRegExp)(findString), replaceFlag), replaceString),
726
727
  v: null
727
728
  };
728
729
  }
@@ -731,7 +732,7 @@ let SheetFindModel = class SheetFindModel extends _univerjs_find_replace.FindMod
731
732
  (0, _univerjs_core.replaceInDocumentBody)(clonedRichText.body, findString, replaceString, this._query.caseSensitive);
732
733
  return { p: clonedRichText };
733
734
  }
734
- return { v: currentContent.v.toString().replace(new RegExp(escapeRegExp(findString), replaceFlag), replaceString) };
735
+ return { v: currentContent.v.toString().replace(new RegExp((0, _univerjs_core.escapeRegExp)(findString), replaceFlag), replaceString) };
735
736
  }
736
737
  };
737
738
  SheetFindModel = __decorate([
@@ -742,9 +743,6 @@ SheetFindModel = __decorate([
742
743
  __decorateParam(6, (0, _univerjs_core.Inject)(_univerjs_core.ThemeService)),
743
744
  __decorateParam(7, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetsSelectionsService))
744
745
  ], SheetFindModel);
745
- function escapeRegExp(text) {
746
- return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
747
- }
748
746
  /**
749
747
  * This module is responsible for searching and replacing in the sheets.
750
748
  * It also adds the search results to the search view by highlighting them.
@@ -870,7 +868,7 @@ function trimLeadingTrailingWhitespace(value) {
870
868
  //#endregion
871
869
  //#region package.json
872
870
  var name = "@univerjs/sheets-find-replace";
873
- var version = "0.23.0";
871
+ var version = "0.24.0-insiders.20260528-29f582d";
874
872
 
875
873
  //#endregion
876
874
  //#region src/config/config.ts
package/lib/es/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";
@@ -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.23.0";
870
+ var version = "0.24.0-insiders.20260528-29f582d";
873
871
 
874
872
  //#endregion
875
873
  //#region src/config/config.ts
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";
@@ -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.23.0";
870
+ var version = "0.24.0-insiders.20260528-29f582d";
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/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.23.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.24.0-insiders.20260528-29f582d`;let M=`sheets-find-replace.config`;Symbol(M);let N={},P=class extends t.Plugin{constructor(e=N,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{...i}=(0,t.merge)({},N,this._config);this._configService.setConfig(M,i)}onStarting(){[[S]].forEach(e=>this._injector.add(e))}onSteady(){this._injector.get(S)}};f(P,`pluginName`,`SHEET_FIND_REPLACE_PLUGIN`),f(P,`packageName`,A),f(P,`version`,j),f(P,`type`,t.UniverInstanceType.UNIVER_SHEET),P=x([(0,t.DependentOn)(n.UniverSheetsPlugin,n.UniverSheetsPlugin,i.UniverFindReplacePlugin),b(1,(0,t.Inject)(t.Injector)),b(2,t.IConfigService)],P),e.SheetReplaceCommand=s,Object.defineProperty(e,`SheetsFindReplaceController`,{enumerable:!0,get:function(){return S}}),Object.defineProperty(e,`UniverSheetsFindReplacePlugin`,{enumerable:!0,get:function(){return P}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-find-replace",
3
- "version": "0.23.0",
3
+ "version": "0.24.0-insiders.20260528-29f582d",
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.23.0",
71
- "@univerjs/engine-render": "0.23.0",
72
- "@univerjs/sheets": "0.23.0",
73
- "@univerjs/sheets-ui": "0.23.0",
74
- "@univerjs/find-replace": "0.23.0"
65
+ "@univerjs/core": "0.24.0-insiders.20260528-29f582d",
66
+ "@univerjs/find-replace": "0.24.0-insiders.20260528-29f582d",
67
+ "@univerjs/sheets": "0.24.0-insiders.20260528-29f582d",
68
+ "@univerjs/sheets-ui": "0.24.0-insiders.20260528-29f582d",
69
+ "@univerjs/engine-render": "0.24.0-insiders.20260528-29f582d"
75
70
  },
76
71
  "devDependencies": {
77
72
  "rxjs": "^7.8.2",
78
73
  "typescript": "^6.0.3",
79
74
  "vitest": "^4.1.5",
80
- "@univerjs-infra/shared": "0.23.0"
75
+ "@univerjs-infra/shared": "0.24.0"
81
76
  },
82
77
  "scripts": {
83
78
  "test": "vitest run",