@univerjs/sheets-find-replace 1.0.0-insiders.20260809-70eefdd → 1.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,176 @@
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
package/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  | Package | UMD global | CSS | Locales | Facade entry |
12
12
  | --- | --- | :---: | :---: | :---: |
13
- | `@univerjs/sheets-find-replace` | `UniverSheetsFindReplace` | No | Yes | Yes |
13
+ | `@univerjs/sheets-find-replace` | `UniverSheetsFindReplace` | No | No | Yes |
14
14
 
15
15
  ## Installation
16
16
 
@@ -25,12 +25,9 @@ Keep all `@univerjs/*` packages on the same version.
25
25
  ## Usage
26
26
 
27
27
  ```ts
28
- import EnUS from '@univerjs/sheets-find-replace/locale/en-US';
29
28
  import { UniverSheetsFindReplacePlugin } from '@univerjs/sheets-find-replace';
30
29
 
31
30
  univer.registerPlugin(UniverSheetsFindReplacePlugin);
32
-
33
- // Merge EnUS into your Univer locale map when this package contributes UI text.
34
31
  ```
35
32
 
36
33
  ## Integration Notes
@@ -42,4 +39,3 @@ Use this package with `@univerjs/find-replace` to share find and replace infrast
42
39
  - [Documentation](https://docs.univer.ai)
43
40
  - [NPM package](https://npmjs.com/package/@univerjs/sheets-find-replace)
44
41
  - [GitHub repository](https://github.com/dream-num/univer)
45
-
package/lib/cjs/index.js CHANGED
@@ -181,10 +181,9 @@ function __decorate(decorators, target, key, desc) {
181
181
  //#endregion
182
182
  //#region src/controllers/sheet-find-replace.controller.ts
183
183
  let SheetsFindReplaceController = class SheetsFindReplaceController extends _univerjs_core.Disposable {
184
- constructor(_injector, _findReplaceController, _contextService, _findReplaceService, _commandService) {
184
+ constructor(_injector, _contextService, _findReplaceService, _commandService) {
185
185
  super();
186
186
  this._injector = _injector;
187
- this._findReplaceController = _findReplaceController;
188
187
  this._contextService = _contextService;
189
188
  this._findReplaceService = _findReplaceService;
190
189
  this._commandService = _commandService;
@@ -194,14 +193,16 @@ let SheetsFindReplaceController = class SheetsFindReplaceController extends _uni
194
193
  }
195
194
  dispose() {
196
195
  super.dispose();
197
- this._findReplaceController.closePanel();
196
+ this._findReplaceService.terminate();
198
197
  this._provider.dispose();
199
198
  }
200
199
  _init() {
201
200
  const provider = this._injector.createInstance(SheetsFindReplaceProvider);
202
201
  this._provider = provider;
203
202
  this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(provider));
204
- this.disposeWithMe(this._contextService.subscribeContextValue$(_univerjs_core.EDITOR_ACTIVATED).pipe((0, rxjs.filter)((v) => !!v)).subscribe(() => this._findReplaceController.closePanel()));
203
+ this.disposeWithMe(this._contextService.subscribeContextValue$(_univerjs_core.EDITOR_ACTIVATED).pipe((0, rxjs.filter)((v) => !!v)).subscribe(() => {
204
+ this._commandService.executeCommand(_univerjs_find_replace.CloseFindDialogOperation.id).catch(() => void 0);
205
+ }));
205
206
  }
206
207
  _initCommands() {
207
208
  [SheetReplaceCommand].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
@@ -209,10 +210,9 @@ let SheetsFindReplaceController = class SheetsFindReplaceController extends _uni
209
210
  };
210
211
  SheetsFindReplaceController = __decorate([
211
212
  __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
212
- __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_find_replace.FindReplaceController)),
213
- __decorateParam(2, _univerjs_core.IContextService),
214
- __decorateParam(3, _univerjs_find_replace.IFindReplaceService),
215
- __decorateParam(4, _univerjs_core.ICommandService)
213
+ __decorateParam(1, _univerjs_core.IContextService),
214
+ __decorateParam(2, _univerjs_find_replace.IFindReplaceService),
215
+ __decorateParam(3, _univerjs_core.ICommandService)
216
216
  ], SheetsFindReplaceController);
217
217
  const SHEETS_FIND_REPLACE_PROVIDER_NAME = "sheets-find-replace-provider";
218
218
  const FIND_REPLACE_Z_INDEX = 1e4;
@@ -650,7 +650,7 @@ let SheetFindModel = class SheetFindModel extends _univerjs_find_replace.FindMod
650
650
  const matchRange = match.range.range;
651
651
  if (!(findByRow ? isBehindPositionWithRowPriority(range, matchRange) : isBehindPositionWithColumnPriority(range, matchRange))) return false;
652
652
  const isSame = isSamePosition(range, matchRange);
653
- return stayIfOnMatch ? isSame : !isSame;
653
+ return stayIfOnMatch || !isSame;
654
654
  });
655
655
  if (index === -1) index = matches.length - 1;
656
656
  const match = matches[index];
@@ -876,7 +876,7 @@ function trimLeadingTrailingWhitespace(value) {
876
876
  //#endregion
877
877
  //#region package.json
878
878
  var name = "@univerjs/sheets-find-replace";
879
- var version = "1.0.0-insiders.20260809-70eefdd";
879
+ var version = "1.0.0-rc.0";
880
880
 
881
881
  //#endregion
882
882
  //#region src/config/config.ts
@@ -899,6 +899,103 @@ const SHEETS_FIND_REPLACE_PLUGIN_CONFIG_KEY = "sheets-find-replace.config";
899
899
  const configSymbol = Symbol(SHEETS_FIND_REPLACE_PLUGIN_CONFIG_KEY);
900
900
  const defaultPluginConfig = {};
901
901
 
902
+ //#endregion
903
+ //#region src/controllers/mobile/sheet-find-replace-mobile.controller.ts
904
+ const MOBILE_FIND_REPLACE_BAR_SELECTOR = "[data-u-comp=\"mobile-find-replace-bar\"]";
905
+ const MOBILE_FIND_MATCH_SAFE_PADDING = 8;
906
+ function getMobileFindMatchScrollOffset(cellBottom, barTop, safePadding) {
907
+ return Math.max(0, cellBottom - barTop + safePadding);
908
+ }
909
+ let SheetsFindReplaceMobileController = class SheetsFindReplaceMobileController extends _univerjs_core.Disposable {
910
+ constructor(_commandService, _univerInstanceService, _renderManagerService) {
911
+ super();
912
+ this._commandService = _commandService;
913
+ this._univerInstanceService = _univerInstanceService;
914
+ this._renderManagerService = _renderManagerService;
915
+ _defineProperty(this, "_pendingFrameId", null);
916
+ this.disposeWithMe(this._commandService.onCommandExecuted((command, options) => {
917
+ var _command$params;
918
+ if (command.id !== _univerjs_sheets_ui.ScrollToCellCommand.id || (options === null || options === void 0 ? void 0 : options.fromFindReplace) !== true) return;
919
+ const range = (_command$params = command.params) === null || _command$params === void 0 ? void 0 : _command$params.range;
920
+ if (!range) return;
921
+ const workbook = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
922
+ const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getActiveSheet();
923
+ if (!workbook || !worksheet) return;
924
+ this._scheduleReveal(workbook.getUnitId(), worksheet.getSheetId(), range.endRow, range.endColumn);
925
+ }));
926
+ }
927
+ dispose() {
928
+ if (this._pendingFrameId !== null) {
929
+ cancelAnimationFrame(this._pendingFrameId);
930
+ this._pendingFrameId = null;
931
+ }
932
+ super.dispose();
933
+ }
934
+ _scheduleReveal(unitId, subUnitId, row, column) {
935
+ if (this._pendingFrameId !== null) cancelAnimationFrame(this._pendingFrameId);
936
+ this._pendingFrameId = requestAnimationFrame(() => {
937
+ this._pendingFrameId = null;
938
+ this._revealMatch(unitId, subUnitId, row, column);
939
+ });
940
+ }
941
+ _revealMatch(unitId, subUnitId, row, column) {
942
+ const bar = document.querySelector(MOBILE_FIND_REPLACE_BAR_SELECTOR);
943
+ if (!bar) return;
944
+ const workbook = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
945
+ const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getActiveSheet();
946
+ if (!workbook || !worksheet || workbook.getUnitId() !== unitId || worksheet.getSheetId() !== subUnitId) return;
947
+ const render = this._renderManagerService.getRenderUnitById(workbook.getUnitId());
948
+ const sheetObject = (0, _univerjs_sheets_ui.getSheetObject)(workbook, this._renderManagerService);
949
+ const skeleton = render === null || render === void 0 ? void 0 : render.with(_univerjs_sheets_ui.SheetSkeletonManagerService).getSkeleton(worksheet.getSheetId());
950
+ if (!sheetObject || !skeleton) return;
951
+ const { scene, engine } = sheetObject;
952
+ const viewport = (0, _univerjs_sheets_ui.getViewportByCell)(row, column, scene, worksheet);
953
+ if (!viewport) return;
954
+ const { endY } = (0, _univerjs_sheets_ui.getCoordByCell)(row, column, scene, skeleton);
955
+ const { scaleY } = scene.getAncestorScale();
956
+ const scrollXY = scene.getViewportScrollXY(viewport);
957
+ const offsetY = getMobileFindMatchScrollOffset(engine.getCanvasElement().getBoundingClientRect().top + (0, _univerjs_engine_render.convertTransformToOffsetY)(endY, scaleY, scrollXY), bar.getBoundingClientRect().top, MOBILE_FIND_MATCH_SAFE_PADDING);
958
+ if (offsetY === 0) return;
959
+ this._commandService.executeCommand(_univerjs_sheets_ui.SetScrollRelativeCommand.id, { offsetY }).catch(() => void 0);
960
+ }
961
+ };
962
+ SheetsFindReplaceMobileController = __decorate([
963
+ __decorateParam(0, _univerjs_core.ICommandService),
964
+ __decorateParam(1, _univerjs_core.IUniverInstanceService),
965
+ __decorateParam(2, _univerjs_engine_render.IRenderManagerService)
966
+ ], SheetsFindReplaceMobileController);
967
+
968
+ //#endregion
969
+ //#region src/mobile-plugin.ts
970
+ let UniverSheetsFindReplaceMobileUIPlugin = class UniverSheetsFindReplaceMobileUIPlugin extends _univerjs_core.Plugin {
971
+ constructor(_config = defaultPluginConfig, _injector, _configService) {
972
+ super();
973
+ this._config = _config;
974
+ this._injector = _injector;
975
+ this._configService = _configService;
976
+ const { ...rest } = (0, _univerjs_core.merge)({}, defaultPluginConfig, this._config);
977
+ this._configService.setConfig(SHEETS_FIND_REPLACE_PLUGIN_CONFIG_KEY, rest);
978
+ }
979
+ onStarting() {
980
+ [[SheetsFindReplaceController], [SheetsFindReplaceMobileController]].forEach((dependency) => this._injector.add(dependency));
981
+ }
982
+ onRendered() {
983
+ this._injector.get(SheetsFindReplaceMobileController);
984
+ }
985
+ onSteady() {
986
+ this._injector.get(SheetsFindReplaceController);
987
+ }
988
+ };
989
+ _defineProperty(UniverSheetsFindReplaceMobileUIPlugin, "pluginName", "SHEET_FIND_REPLACE_PLUGIN");
990
+ _defineProperty(UniverSheetsFindReplaceMobileUIPlugin, "packageName", name);
991
+ _defineProperty(UniverSheetsFindReplaceMobileUIPlugin, "version", version);
992
+ _defineProperty(UniverSheetsFindReplaceMobileUIPlugin, "type", _univerjs_core.UniverInstanceType.UNIVER_SHEET);
993
+ UniverSheetsFindReplaceMobileUIPlugin = __decorate([
994
+ (0, _univerjs_core.DependentOn)(_univerjs_engine_render.UniverRenderEnginePlugin, _univerjs_sheets.UniverSheetsPlugin, _univerjs_find_replace.UniverFindReplaceMobileUIPlugin, _univerjs_sheets_ui.UniverSheetsMobileUIPlugin),
995
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
996
+ __decorateParam(2, _univerjs_core.IConfigService)
997
+ ], UniverSheetsFindReplaceMobileUIPlugin);
998
+
902
999
  //#endregion
903
1000
  //#region src/plugin.ts
904
1001
  let UniverSheetsFindReplacePlugin = class UniverSheetsFindReplacePlugin extends _univerjs_core.Plugin {
@@ -935,6 +1032,12 @@ Object.defineProperty(exports, 'SheetsFindReplaceController', {
935
1032
  return SheetsFindReplaceController;
936
1033
  }
937
1034
  });
1035
+ Object.defineProperty(exports, 'UniverSheetsFindReplaceMobileUIPlugin', {
1036
+ enumerable: true,
1037
+ get: function () {
1038
+ return UniverSheetsFindReplaceMobileUIPlugin;
1039
+ }
1040
+ });
938
1041
  Object.defineProperty(exports, 'UniverSheetsFindReplacePlugin', {
939
1042
  enumerable: true,
940
1043
  get: function () {
package/lib/es/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { ColorKit, CommandType, DependentOn, Disposable, EDITOR_ACTIVATED, ICommandService, IConfigService, IContextService, IUndoRedoService, IUniverInstanceService, Inject, Injector, ObjectMatrix, Plugin, Rectangle, ThemeService, Tools, UniverInstanceType, fromCallback, groupBy, merge, regexp, replaceInDocumentBody, rotate } from "@univerjs/core";
2
2
  import { SelectRangeCommand, SetRangeValuesCommand, SetSelectionsOperation, SetWorksheetActivateCommand, SetWorksheetActiveOperation, SheetsSelectionsService, UniverSheetsPlugin } from "@univerjs/sheets";
3
- import { IRenderManagerService, RENDER_RAW_FORMULA_KEY, Rect, Shape, UniverRenderEnginePlugin } from "@univerjs/engine-render";
4
- import { FindBy, FindDirection, FindModel, FindReplaceController, FindScope, IFindReplaceService, UniverFindReplacePlugin } from "@univerjs/find-replace";
5
- import { ScrollToCellCommand, SheetSkeletonManagerService, UniverSheetsUIPlugin, getCoordByCell, getSheetObject } from "@univerjs/sheets-ui";
3
+ import { IRenderManagerService, RENDER_RAW_FORMULA_KEY, Rect, Shape, UniverRenderEnginePlugin, convertTransformToOffsetY } from "@univerjs/engine-render";
4
+ import { CloseFindDialogOperation, FindBy, FindDirection, FindModel, FindScope, IFindReplaceService, UniverFindReplaceMobileUIPlugin, UniverFindReplacePlugin } from "@univerjs/find-replace";
5
+ import { ScrollToCellCommand, SetScrollRelativeCommand, SheetSkeletonManagerService, UniverSheetsMobileUIPlugin, UniverSheetsUIPlugin, getCoordByCell, getSheetObject, getViewportByCell } from "@univerjs/sheets-ui";
6
6
  import { Subject, debounceTime, filter, merge as merge$1, skip, throttleTime } from "rxjs";
7
7
 
8
8
  //#region src/commands/commands/sheet-replace.command.ts
@@ -180,10 +180,9 @@ function __decorate(decorators, target, key, desc) {
180
180
  //#endregion
181
181
  //#region src/controllers/sheet-find-replace.controller.ts
182
182
  let SheetsFindReplaceController = class SheetsFindReplaceController extends Disposable {
183
- constructor(_injector, _findReplaceController, _contextService, _findReplaceService, _commandService) {
183
+ constructor(_injector, _contextService, _findReplaceService, _commandService) {
184
184
  super();
185
185
  this._injector = _injector;
186
- this._findReplaceController = _findReplaceController;
187
186
  this._contextService = _contextService;
188
187
  this._findReplaceService = _findReplaceService;
189
188
  this._commandService = _commandService;
@@ -193,14 +192,16 @@ let SheetsFindReplaceController = class SheetsFindReplaceController extends Disp
193
192
  }
194
193
  dispose() {
195
194
  super.dispose();
196
- this._findReplaceController.closePanel();
195
+ this._findReplaceService.terminate();
197
196
  this._provider.dispose();
198
197
  }
199
198
  _init() {
200
199
  const provider = this._injector.createInstance(SheetsFindReplaceProvider);
201
200
  this._provider = provider;
202
201
  this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(provider));
203
- this.disposeWithMe(this._contextService.subscribeContextValue$(EDITOR_ACTIVATED).pipe(filter((v) => !!v)).subscribe(() => this._findReplaceController.closePanel()));
202
+ this.disposeWithMe(this._contextService.subscribeContextValue$(EDITOR_ACTIVATED).pipe(filter((v) => !!v)).subscribe(() => {
203
+ this._commandService.executeCommand(CloseFindDialogOperation.id).catch(() => void 0);
204
+ }));
204
205
  }
205
206
  _initCommands() {
206
207
  [SheetReplaceCommand].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
@@ -208,10 +209,9 @@ let SheetsFindReplaceController = class SheetsFindReplaceController extends Disp
208
209
  };
209
210
  SheetsFindReplaceController = __decorate([
210
211
  __decorateParam(0, Inject(Injector)),
211
- __decorateParam(1, Inject(FindReplaceController)),
212
- __decorateParam(2, IContextService),
213
- __decorateParam(3, IFindReplaceService),
214
- __decorateParam(4, ICommandService)
212
+ __decorateParam(1, IContextService),
213
+ __decorateParam(2, IFindReplaceService),
214
+ __decorateParam(3, ICommandService)
215
215
  ], SheetsFindReplaceController);
216
216
  const SHEETS_FIND_REPLACE_PROVIDER_NAME = "sheets-find-replace-provider";
217
217
  const FIND_REPLACE_Z_INDEX = 1e4;
@@ -649,7 +649,7 @@ let SheetFindModel = class SheetFindModel extends FindModel {
649
649
  const matchRange = match.range.range;
650
650
  if (!(findByRow ? isBehindPositionWithRowPriority(range, matchRange) : isBehindPositionWithColumnPriority(range, matchRange))) return false;
651
651
  const isSame = isSamePosition(range, matchRange);
652
- return stayIfOnMatch ? isSame : !isSame;
652
+ return stayIfOnMatch || !isSame;
653
653
  });
654
654
  if (index === -1) index = matches.length - 1;
655
655
  const match = matches[index];
@@ -875,7 +875,7 @@ function trimLeadingTrailingWhitespace(value) {
875
875
  //#endregion
876
876
  //#region package.json
877
877
  var name = "@univerjs/sheets-find-replace";
878
- var version = "1.0.0-insiders.20260809-70eefdd";
878
+ var version = "1.0.0-rc.0";
879
879
 
880
880
  //#endregion
881
881
  //#region src/config/config.ts
@@ -898,6 +898,103 @@ const SHEETS_FIND_REPLACE_PLUGIN_CONFIG_KEY = "sheets-find-replace.config";
898
898
  const configSymbol = Symbol(SHEETS_FIND_REPLACE_PLUGIN_CONFIG_KEY);
899
899
  const defaultPluginConfig = {};
900
900
 
901
+ //#endregion
902
+ //#region src/controllers/mobile/sheet-find-replace-mobile.controller.ts
903
+ const MOBILE_FIND_REPLACE_BAR_SELECTOR = "[data-u-comp=\"mobile-find-replace-bar\"]";
904
+ const MOBILE_FIND_MATCH_SAFE_PADDING = 8;
905
+ function getMobileFindMatchScrollOffset(cellBottom, barTop, safePadding) {
906
+ return Math.max(0, cellBottom - barTop + safePadding);
907
+ }
908
+ let SheetsFindReplaceMobileController = class SheetsFindReplaceMobileController extends Disposable {
909
+ constructor(_commandService, _univerInstanceService, _renderManagerService) {
910
+ super();
911
+ this._commandService = _commandService;
912
+ this._univerInstanceService = _univerInstanceService;
913
+ this._renderManagerService = _renderManagerService;
914
+ _defineProperty(this, "_pendingFrameId", null);
915
+ this.disposeWithMe(this._commandService.onCommandExecuted((command, options) => {
916
+ var _command$params;
917
+ if (command.id !== ScrollToCellCommand.id || (options === null || options === void 0 ? void 0 : options.fromFindReplace) !== true) return;
918
+ const range = (_command$params = command.params) === null || _command$params === void 0 ? void 0 : _command$params.range;
919
+ if (!range) return;
920
+ const workbook = this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET);
921
+ const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getActiveSheet();
922
+ if (!workbook || !worksheet) return;
923
+ this._scheduleReveal(workbook.getUnitId(), worksheet.getSheetId(), range.endRow, range.endColumn);
924
+ }));
925
+ }
926
+ dispose() {
927
+ if (this._pendingFrameId !== null) {
928
+ cancelAnimationFrame(this._pendingFrameId);
929
+ this._pendingFrameId = null;
930
+ }
931
+ super.dispose();
932
+ }
933
+ _scheduleReveal(unitId, subUnitId, row, column) {
934
+ if (this._pendingFrameId !== null) cancelAnimationFrame(this._pendingFrameId);
935
+ this._pendingFrameId = requestAnimationFrame(() => {
936
+ this._pendingFrameId = null;
937
+ this._revealMatch(unitId, subUnitId, row, column);
938
+ });
939
+ }
940
+ _revealMatch(unitId, subUnitId, row, column) {
941
+ const bar = document.querySelector(MOBILE_FIND_REPLACE_BAR_SELECTOR);
942
+ if (!bar) return;
943
+ const workbook = this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET);
944
+ const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getActiveSheet();
945
+ if (!workbook || !worksheet || workbook.getUnitId() !== unitId || worksheet.getSheetId() !== subUnitId) return;
946
+ const render = this._renderManagerService.getRenderUnitById(workbook.getUnitId());
947
+ const sheetObject = getSheetObject(workbook, this._renderManagerService);
948
+ const skeleton = render === null || render === void 0 ? void 0 : render.with(SheetSkeletonManagerService).getSkeleton(worksheet.getSheetId());
949
+ if (!sheetObject || !skeleton) return;
950
+ const { scene, engine } = sheetObject;
951
+ const viewport = getViewportByCell(row, column, scene, worksheet);
952
+ if (!viewport) return;
953
+ const { endY } = getCoordByCell(row, column, scene, skeleton);
954
+ const { scaleY } = scene.getAncestorScale();
955
+ const scrollXY = scene.getViewportScrollXY(viewport);
956
+ const offsetY = getMobileFindMatchScrollOffset(engine.getCanvasElement().getBoundingClientRect().top + convertTransformToOffsetY(endY, scaleY, scrollXY), bar.getBoundingClientRect().top, MOBILE_FIND_MATCH_SAFE_PADDING);
957
+ if (offsetY === 0) return;
958
+ this._commandService.executeCommand(SetScrollRelativeCommand.id, { offsetY }).catch(() => void 0);
959
+ }
960
+ };
961
+ SheetsFindReplaceMobileController = __decorate([
962
+ __decorateParam(0, ICommandService),
963
+ __decorateParam(1, IUniverInstanceService),
964
+ __decorateParam(2, IRenderManagerService)
965
+ ], SheetsFindReplaceMobileController);
966
+
967
+ //#endregion
968
+ //#region src/mobile-plugin.ts
969
+ let UniverSheetsFindReplaceMobileUIPlugin = class UniverSheetsFindReplaceMobileUIPlugin extends Plugin {
970
+ constructor(_config = defaultPluginConfig, _injector, _configService) {
971
+ super();
972
+ this._config = _config;
973
+ this._injector = _injector;
974
+ this._configService = _configService;
975
+ const { ...rest } = merge({}, defaultPluginConfig, this._config);
976
+ this._configService.setConfig(SHEETS_FIND_REPLACE_PLUGIN_CONFIG_KEY, rest);
977
+ }
978
+ onStarting() {
979
+ [[SheetsFindReplaceController], [SheetsFindReplaceMobileController]].forEach((dependency) => this._injector.add(dependency));
980
+ }
981
+ onRendered() {
982
+ this._injector.get(SheetsFindReplaceMobileController);
983
+ }
984
+ onSteady() {
985
+ this._injector.get(SheetsFindReplaceController);
986
+ }
987
+ };
988
+ _defineProperty(UniverSheetsFindReplaceMobileUIPlugin, "pluginName", "SHEET_FIND_REPLACE_PLUGIN");
989
+ _defineProperty(UniverSheetsFindReplaceMobileUIPlugin, "packageName", name);
990
+ _defineProperty(UniverSheetsFindReplaceMobileUIPlugin, "version", version);
991
+ _defineProperty(UniverSheetsFindReplaceMobileUIPlugin, "type", UniverInstanceType.UNIVER_SHEET);
992
+ UniverSheetsFindReplaceMobileUIPlugin = __decorate([
993
+ DependentOn(UniverRenderEnginePlugin, UniverSheetsPlugin, UniverFindReplaceMobileUIPlugin, UniverSheetsMobileUIPlugin),
994
+ __decorateParam(1, Inject(Injector)),
995
+ __decorateParam(2, IConfigService)
996
+ ], UniverSheetsFindReplaceMobileUIPlugin);
997
+
901
998
  //#endregion
902
999
  //#region src/plugin.ts
903
1000
  let UniverSheetsFindReplacePlugin = class UniverSheetsFindReplacePlugin extends Plugin {
@@ -927,4 +1024,4 @@ UniverSheetsFindReplacePlugin = __decorate([
927
1024
  ], UniverSheetsFindReplacePlugin);
928
1025
 
929
1026
  //#endregion
930
- export { SheetReplaceCommand, SheetsFindReplaceController, UniverSheetsFindReplacePlugin };
1027
+ export { SheetReplaceCommand, SheetsFindReplaceController, UniverSheetsFindReplaceMobileUIPlugin, UniverSheetsFindReplacePlugin };
package/lib/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { ColorKit, CommandType, DependentOn, Disposable, EDITOR_ACTIVATED, ICommandService, IConfigService, IContextService, IUndoRedoService, IUniverInstanceService, Inject, Injector, ObjectMatrix, Plugin, Rectangle, ThemeService, Tools, UniverInstanceType, fromCallback, groupBy, merge, regexp, replaceInDocumentBody, rotate } from "@univerjs/core";
2
2
  import { SelectRangeCommand, SetRangeValuesCommand, SetSelectionsOperation, SetWorksheetActivateCommand, SetWorksheetActiveOperation, SheetsSelectionsService, UniverSheetsPlugin } from "@univerjs/sheets";
3
- import { IRenderManagerService, RENDER_RAW_FORMULA_KEY, Rect, Shape, UniverRenderEnginePlugin } from "@univerjs/engine-render";
4
- import { FindBy, FindDirection, FindModel, FindReplaceController, FindScope, IFindReplaceService, UniverFindReplacePlugin } from "@univerjs/find-replace";
5
- import { ScrollToCellCommand, SheetSkeletonManagerService, UniverSheetsUIPlugin, getCoordByCell, getSheetObject } from "@univerjs/sheets-ui";
3
+ import { IRenderManagerService, RENDER_RAW_FORMULA_KEY, Rect, Shape, UniverRenderEnginePlugin, convertTransformToOffsetY } from "@univerjs/engine-render";
4
+ import { CloseFindDialogOperation, FindBy, FindDirection, FindModel, FindScope, IFindReplaceService, UniverFindReplaceMobileUIPlugin, UniverFindReplacePlugin } from "@univerjs/find-replace";
5
+ import { ScrollToCellCommand, SetScrollRelativeCommand, SheetSkeletonManagerService, UniverSheetsMobileUIPlugin, UniverSheetsUIPlugin, getCoordByCell, getSheetObject, getViewportByCell } from "@univerjs/sheets-ui";
6
6
  import { Subject, debounceTime, filter, merge as merge$1, skip, throttleTime } from "rxjs";
7
7
 
8
8
  //#region src/commands/commands/sheet-replace.command.ts
@@ -180,10 +180,9 @@ function __decorate(decorators, target, key, desc) {
180
180
  //#endregion
181
181
  //#region src/controllers/sheet-find-replace.controller.ts
182
182
  let SheetsFindReplaceController = class SheetsFindReplaceController extends Disposable {
183
- constructor(_injector, _findReplaceController, _contextService, _findReplaceService, _commandService) {
183
+ constructor(_injector, _contextService, _findReplaceService, _commandService) {
184
184
  super();
185
185
  this._injector = _injector;
186
- this._findReplaceController = _findReplaceController;
187
186
  this._contextService = _contextService;
188
187
  this._findReplaceService = _findReplaceService;
189
188
  this._commandService = _commandService;
@@ -193,14 +192,16 @@ let SheetsFindReplaceController = class SheetsFindReplaceController extends Disp
193
192
  }
194
193
  dispose() {
195
194
  super.dispose();
196
- this._findReplaceController.closePanel();
195
+ this._findReplaceService.terminate();
197
196
  this._provider.dispose();
198
197
  }
199
198
  _init() {
200
199
  const provider = this._injector.createInstance(SheetsFindReplaceProvider);
201
200
  this._provider = provider;
202
201
  this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(provider));
203
- this.disposeWithMe(this._contextService.subscribeContextValue$(EDITOR_ACTIVATED).pipe(filter((v) => !!v)).subscribe(() => this._findReplaceController.closePanel()));
202
+ this.disposeWithMe(this._contextService.subscribeContextValue$(EDITOR_ACTIVATED).pipe(filter((v) => !!v)).subscribe(() => {
203
+ this._commandService.executeCommand(CloseFindDialogOperation.id).catch(() => void 0);
204
+ }));
204
205
  }
205
206
  _initCommands() {
206
207
  [SheetReplaceCommand].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
@@ -208,10 +209,9 @@ let SheetsFindReplaceController = class SheetsFindReplaceController extends Disp
208
209
  };
209
210
  SheetsFindReplaceController = __decorate([
210
211
  __decorateParam(0, Inject(Injector)),
211
- __decorateParam(1, Inject(FindReplaceController)),
212
- __decorateParam(2, IContextService),
213
- __decorateParam(3, IFindReplaceService),
214
- __decorateParam(4, ICommandService)
212
+ __decorateParam(1, IContextService),
213
+ __decorateParam(2, IFindReplaceService),
214
+ __decorateParam(3, ICommandService)
215
215
  ], SheetsFindReplaceController);
216
216
  const SHEETS_FIND_REPLACE_PROVIDER_NAME = "sheets-find-replace-provider";
217
217
  const FIND_REPLACE_Z_INDEX = 1e4;
@@ -649,7 +649,7 @@ let SheetFindModel = class SheetFindModel extends FindModel {
649
649
  const matchRange = match.range.range;
650
650
  if (!(findByRow ? isBehindPositionWithRowPriority(range, matchRange) : isBehindPositionWithColumnPriority(range, matchRange))) return false;
651
651
  const isSame = isSamePosition(range, matchRange);
652
- return stayIfOnMatch ? isSame : !isSame;
652
+ return stayIfOnMatch || !isSame;
653
653
  });
654
654
  if (index === -1) index = matches.length - 1;
655
655
  const match = matches[index];
@@ -875,7 +875,7 @@ function trimLeadingTrailingWhitespace(value) {
875
875
  //#endregion
876
876
  //#region package.json
877
877
  var name = "@univerjs/sheets-find-replace";
878
- var version = "1.0.0-insiders.20260809-70eefdd";
878
+ var version = "1.0.0-rc.0";
879
879
 
880
880
  //#endregion
881
881
  //#region src/config/config.ts
@@ -898,6 +898,103 @@ const SHEETS_FIND_REPLACE_PLUGIN_CONFIG_KEY = "sheets-find-replace.config";
898
898
  const configSymbol = Symbol(SHEETS_FIND_REPLACE_PLUGIN_CONFIG_KEY);
899
899
  const defaultPluginConfig = {};
900
900
 
901
+ //#endregion
902
+ //#region src/controllers/mobile/sheet-find-replace-mobile.controller.ts
903
+ const MOBILE_FIND_REPLACE_BAR_SELECTOR = "[data-u-comp=\"mobile-find-replace-bar\"]";
904
+ const MOBILE_FIND_MATCH_SAFE_PADDING = 8;
905
+ function getMobileFindMatchScrollOffset(cellBottom, barTop, safePadding) {
906
+ return Math.max(0, cellBottom - barTop + safePadding);
907
+ }
908
+ let SheetsFindReplaceMobileController = class SheetsFindReplaceMobileController extends Disposable {
909
+ constructor(_commandService, _univerInstanceService, _renderManagerService) {
910
+ super();
911
+ this._commandService = _commandService;
912
+ this._univerInstanceService = _univerInstanceService;
913
+ this._renderManagerService = _renderManagerService;
914
+ _defineProperty(this, "_pendingFrameId", null);
915
+ this.disposeWithMe(this._commandService.onCommandExecuted((command, options) => {
916
+ var _command$params;
917
+ if (command.id !== ScrollToCellCommand.id || (options === null || options === void 0 ? void 0 : options.fromFindReplace) !== true) return;
918
+ const range = (_command$params = command.params) === null || _command$params === void 0 ? void 0 : _command$params.range;
919
+ if (!range) return;
920
+ const workbook = this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET);
921
+ const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getActiveSheet();
922
+ if (!workbook || !worksheet) return;
923
+ this._scheduleReveal(workbook.getUnitId(), worksheet.getSheetId(), range.endRow, range.endColumn);
924
+ }));
925
+ }
926
+ dispose() {
927
+ if (this._pendingFrameId !== null) {
928
+ cancelAnimationFrame(this._pendingFrameId);
929
+ this._pendingFrameId = null;
930
+ }
931
+ super.dispose();
932
+ }
933
+ _scheduleReveal(unitId, subUnitId, row, column) {
934
+ if (this._pendingFrameId !== null) cancelAnimationFrame(this._pendingFrameId);
935
+ this._pendingFrameId = requestAnimationFrame(() => {
936
+ this._pendingFrameId = null;
937
+ this._revealMatch(unitId, subUnitId, row, column);
938
+ });
939
+ }
940
+ _revealMatch(unitId, subUnitId, row, column) {
941
+ const bar = document.querySelector(MOBILE_FIND_REPLACE_BAR_SELECTOR);
942
+ if (!bar) return;
943
+ const workbook = this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET);
944
+ const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getActiveSheet();
945
+ if (!workbook || !worksheet || workbook.getUnitId() !== unitId || worksheet.getSheetId() !== subUnitId) return;
946
+ const render = this._renderManagerService.getRenderUnitById(workbook.getUnitId());
947
+ const sheetObject = getSheetObject(workbook, this._renderManagerService);
948
+ const skeleton = render === null || render === void 0 ? void 0 : render.with(SheetSkeletonManagerService).getSkeleton(worksheet.getSheetId());
949
+ if (!sheetObject || !skeleton) return;
950
+ const { scene, engine } = sheetObject;
951
+ const viewport = getViewportByCell(row, column, scene, worksheet);
952
+ if (!viewport) return;
953
+ const { endY } = getCoordByCell(row, column, scene, skeleton);
954
+ const { scaleY } = scene.getAncestorScale();
955
+ const scrollXY = scene.getViewportScrollXY(viewport);
956
+ const offsetY = getMobileFindMatchScrollOffset(engine.getCanvasElement().getBoundingClientRect().top + convertTransformToOffsetY(endY, scaleY, scrollXY), bar.getBoundingClientRect().top, MOBILE_FIND_MATCH_SAFE_PADDING);
957
+ if (offsetY === 0) return;
958
+ this._commandService.executeCommand(SetScrollRelativeCommand.id, { offsetY }).catch(() => void 0);
959
+ }
960
+ };
961
+ SheetsFindReplaceMobileController = __decorate([
962
+ __decorateParam(0, ICommandService),
963
+ __decorateParam(1, IUniverInstanceService),
964
+ __decorateParam(2, IRenderManagerService)
965
+ ], SheetsFindReplaceMobileController);
966
+
967
+ //#endregion
968
+ //#region src/mobile-plugin.ts
969
+ let UniverSheetsFindReplaceMobileUIPlugin = class UniverSheetsFindReplaceMobileUIPlugin extends Plugin {
970
+ constructor(_config = defaultPluginConfig, _injector, _configService) {
971
+ super();
972
+ this._config = _config;
973
+ this._injector = _injector;
974
+ this._configService = _configService;
975
+ const { ...rest } = merge({}, defaultPluginConfig, this._config);
976
+ this._configService.setConfig(SHEETS_FIND_REPLACE_PLUGIN_CONFIG_KEY, rest);
977
+ }
978
+ onStarting() {
979
+ [[SheetsFindReplaceController], [SheetsFindReplaceMobileController]].forEach((dependency) => this._injector.add(dependency));
980
+ }
981
+ onRendered() {
982
+ this._injector.get(SheetsFindReplaceMobileController);
983
+ }
984
+ onSteady() {
985
+ this._injector.get(SheetsFindReplaceController);
986
+ }
987
+ };
988
+ _defineProperty(UniverSheetsFindReplaceMobileUIPlugin, "pluginName", "SHEET_FIND_REPLACE_PLUGIN");
989
+ _defineProperty(UniverSheetsFindReplaceMobileUIPlugin, "packageName", name);
990
+ _defineProperty(UniverSheetsFindReplaceMobileUIPlugin, "version", version);
991
+ _defineProperty(UniverSheetsFindReplaceMobileUIPlugin, "type", UniverInstanceType.UNIVER_SHEET);
992
+ UniverSheetsFindReplaceMobileUIPlugin = __decorate([
993
+ DependentOn(UniverRenderEnginePlugin, UniverSheetsPlugin, UniverFindReplaceMobileUIPlugin, UniverSheetsMobileUIPlugin),
994
+ __decorateParam(1, Inject(Injector)),
995
+ __decorateParam(2, IConfigService)
996
+ ], UniverSheetsFindReplaceMobileUIPlugin);
997
+
901
998
  //#endregion
902
999
  //#region src/plugin.ts
903
1000
  let UniverSheetsFindReplacePlugin = class UniverSheetsFindReplacePlugin extends Plugin {
@@ -927,4 +1024,4 @@ UniverSheetsFindReplacePlugin = __decorate([
927
1024
  ], UniverSheetsFindReplacePlugin);
928
1025
 
929
1026
  //#endregion
930
- export { SheetReplaceCommand, SheetsFindReplaceController, UniverSheetsFindReplacePlugin };
1027
+ export { SheetReplaceCommand, SheetsFindReplaceController, UniverSheetsFindReplaceMobileUIPlugin, UniverSheetsFindReplacePlugin };
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { Disposable, ICommandService, IUniverInstanceService } from '@univerjs/core';
17
+ import { IRenderManagerService } from '@univerjs/engine-render';
18
+ export declare function getMobileFindMatchScrollOffset(cellBottom: number, barTop: number, safePadding: number): number;
19
+ export declare class SheetsFindReplaceMobileController extends Disposable {
20
+ private readonly _commandService;
21
+ private readonly _univerInstanceService;
22
+ private readonly _renderManagerService;
23
+ private _pendingFrameId;
24
+ constructor(_commandService: ICommandService, _univerInstanceService: IUniverInstanceService, _renderManagerService: IRenderManagerService);
25
+ dispose(): void;
26
+ private _scheduleReveal;
27
+ private _revealMatch;
28
+ }
@@ -17,17 +17,16 @@ import type { ICellData, IDisposable, IRange, Nullable, Workbook, Worksheet } fr
17
17
  import type { IFindComplete, IFindMatch, IFindMoveParams, IFindQuery, IReplaceAllResult } from '@univerjs/find-replace';
18
18
  import { Disposable, ICommandService, IContextService, Injector, IUniverInstanceService, ThemeService } from '@univerjs/core';
19
19
  import { IRenderManagerService } from '@univerjs/engine-render';
20
- import { FindModel, FindReplaceController, IFindReplaceService } from '@univerjs/find-replace';
20
+ import { FindModel, IFindReplaceService } from '@univerjs/find-replace';
21
21
  import { SheetsSelectionsService } from '@univerjs/sheets';
22
22
  import { SheetSkeletonManagerService } from '@univerjs/sheets-ui';
23
23
  export declare class SheetsFindReplaceController extends Disposable implements IDisposable {
24
24
  private readonly _injector;
25
- private readonly _findReplaceController;
26
25
  private readonly _contextService;
27
26
  private readonly _findReplaceService;
28
27
  private readonly _commandService;
29
28
  private _provider;
30
- constructor(_injector: Injector, _findReplaceController: FindReplaceController, _contextService: IContextService, _findReplaceService: IFindReplaceService, _commandService: ICommandService);
29
+ constructor(_injector: Injector, _contextService: IContextService, _findReplaceService: IFindReplaceService, _commandService: ICommandService);
31
30
  dispose(): void;
32
31
  private _init;
33
32
  private _initCommands;
@@ -16,4 +16,5 @@
16
16
  export { SheetReplaceCommand } from './commands/commands/sheet-replace.command';
17
17
  export type { IUniverSheetsFindReplaceConfig } from './config/config';
18
18
  export { SheetsFindReplaceController } from './controllers/sheet-find-replace.controller';
19
+ export { UniverSheetsFindReplaceMobileUIPlugin } from './mobile-plugin';
19
20
  export { UniverSheetsFindReplacePlugin } from './plugin';
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { IUniverSheetsFindReplaceConfig } from './config/config';
17
+ import { IConfigService, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
18
+ export declare class UniverSheetsFindReplaceMobileUIPlugin extends Plugin {
19
+ private readonly _config;
20
+ protected readonly _injector: Injector;
21
+ private readonly _configService;
22
+ static pluginName: string;
23
+ static packageName: string;
24
+ static version: string;
25
+ static type: UniverInstanceType;
26
+ constructor(_config: Partial<IUniverSheetsFindReplaceConfig> | undefined, _injector: Injector, _configService: IConfigService);
27
+ onStarting(): void;
28
+ onRendered(): void;
29
+ onSteady(): void;
30
+ }
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(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=()=>{let e=this._workbook.getActiveSheet();if(!e)return!1;let t=this._workbookSelections.getCurrentSelections();return(t==null?void 0:t.some(t=>!y(t,e)))??!1},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??1)-1,endRow:i+(u??1)-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.getRenderUnitById(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=y?2:g-m,S=v?2:_-h,C={left:m,top:h,color:s,width:x,height:S,evented:!1,inHiddenRange:b,zIndex:1e4};return new p(`find-highlight-${n}`,C)});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){if(!this._matches.length)return null;let t=(e==null?void 0:e.loop)??!1,n=(e==null?void 0:e.stayIfOnMatch)??!1,r=(e==null?void 0:e.noFocus)??!1,a=(e==null?void 0:e.ignoreSelection)??!1,o=this._findNextMatch(t,n,a);if(o){let[e,t]=o;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,r||this._focusMatch(e),this._updateCurrentHighlightShape(this._activeHighlightIndex),e}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}moveToPreviousMatch(e){if(!this._matches.length)return null;let t=(e==null?void 0:e.loop)??!1,n=(e==null?void 0:e.stayIfOnMatch)??!1,r=(e==null?void 0:e.noFocus)??!1,a=(e==null?void 0:e.ignoreSelection)??!1,o=this._findPreviousMatch(t,n,a);if(o){let[e,t]=o;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,r||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);return(n?(0,t.rotate)(r,i+1):r.slice(0,i+1)).findLast(e=>this._matchesByWorksheet.has(e))??null}_findNextWorksheetThatHasAMatch(e,n=!1){let r=this._workbook.getSheetOrders(),i=r.findIndex(t=>t===e);return(n?(0,t.rotate)(r,i):r.slice(i)).find(e=>this._matchesByWorksheet.has(e))??null}_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(t.regexp.createLiteralRegExp(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(t.regexp.createLiteralRegExp(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,`capabilities`,{caseSensitive:!0,matchesTheWholeWord:!1,matchesTheWholeCell:!0,findDirection:!0,findScope:!0,findBy:!0}),f(this,`_findModelsByUnitId`,new Map)}isSupported(e){return e.type===t.UniverInstanceType.UNIVER_SHEET}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.getRenderUnitById(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;let n=(e==null||(t=e.p)==null||(t=t.body)==null?void 0:t.dataStream)??(e==null?void 0:e.v);return typeof n==`number`?`${n}`:typeof n==`boolean`?n?`1`:`0`:n}function k(e){return e.replace(/^ +/g,``).replace(/ +$/g,``)}var A=`@univerjs/sheets-find-replace`,j=`1.0.0-insiders.20260809-70eefdd`;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)(r.UniverRenderEnginePlugin,n.UniverSheetsPlugin,i.UniverFindReplacePlugin,a.UniverSheetsUIPlugin),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}})});
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){super(),this._injector=e,this._contextService=t,this._findReplaceService=n,this._commandService=r,f(this,`_provider`,void 0),this._init(),this._initCommands()}dispose(){super.dispose(),this._findReplaceService.terminate(),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._commandService.executeCommand(i.CloseFindDialogOperation.id).catch(()=>void 0)}))}_initCommands(){[s].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}};S=x([b(0,(0,t.Inject)(t.Injector)),b(1,t.IContextService),b(2,i.IFindReplaceService),b(3,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=()=>{let e=this._workbook.getActiveSheet();if(!e)return!1;let t=this._workbookSelections.getCurrentSelections();return(t==null?void 0:t.some(t=>!y(t,e)))??!1},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??1)-1,endRow:i+(u??1)-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.getRenderUnitById(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=y?2:g-m,S=v?2:_-h,C={left:m,top:h,color:s,width:x,height:S,evented:!1,inHiddenRange:b,zIndex:1e4};return new p(`find-highlight-${n}`,C)});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){if(!this._matches.length)return null;let t=(e==null?void 0:e.loop)??!1,n=(e==null?void 0:e.stayIfOnMatch)??!1,r=(e==null?void 0:e.noFocus)??!1,a=(e==null?void 0:e.ignoreSelection)??!1,o=this._findNextMatch(t,n,a);if(o){let[e,t]=o;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,r||this._focusMatch(e),this._updateCurrentHighlightShape(this._activeHighlightIndex),e}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}moveToPreviousMatch(e){if(!this._matches.length)return null;let t=(e==null?void 0:e.loop)??!1,n=(e==null?void 0:e.stayIfOnMatch)??!1,r=(e==null?void 0:e.noFocus)??!1,a=(e==null?void 0:e.ignoreSelection)??!1,o=this._findPreviousMatch(t,n,a);if(o){let[e,t]=o;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,r||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);return(n?(0,t.rotate)(r,i+1):r.slice(0,i+1)).findLast(e=>this._matchesByWorksheet.has(e))??null}_findNextWorksheetThatHasAMatch(e,n=!1){let r=this._workbook.getSheetOrders(),i=r.findIndex(t=>t===e);return(n?(0,t.rotate)(r,i):r.slice(i)).find(e=>this._matchesByWorksheet.has(e))??null}_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===-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(t.regexp.createLiteralRegExp(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(t.regexp.createLiteralRegExp(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,`capabilities`,{caseSensitive:!0,matchesTheWholeWord:!1,matchesTheWholeCell:!0,findDirection:!0,findScope:!0,findBy:!0}),f(this,`_findModelsByUnitId`,new Map)}isSupported(e){return e.type===t.UniverInstanceType.UNIVER_SHEET}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.getRenderUnitById(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;let n=(e==null||(t=e.p)==null||(t=t.body)==null?void 0:t.dataStream)??(e==null?void 0:e.v);return typeof n==`number`?`${n}`:typeof n==`boolean`?n?`1`:`0`:n}function k(e){return e.replace(/^ +/g,``).replace(/ +$/g,``)}var A=`@univerjs/sheets-find-replace`,j=`1.0.0-rc.0`;let M=`sheets-find-replace.config`,N={};function P(e,t,n){return Math.max(0,e-t+n)}let F=class extends t.Disposable{constructor(e,n,r){super(),this._commandService=e,this._univerInstanceService=n,this._renderManagerService=r,f(this,`_pendingFrameId`,null),this.disposeWithMe(this._commandService.onCommandExecuted((e,n)=>{var r;if(e.id!==a.ScrollToCellCommand.id||(n==null?void 0:n.fromFindReplace)!==!0)return;let i=(r=e.params)==null?void 0:r.range;if(!i)return;let o=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET),s=o==null?void 0:o.getActiveSheet();!o||!s||this._scheduleReveal(o.getUnitId(),s.getSheetId(),i.endRow,i.endColumn)}))}dispose(){this._pendingFrameId!==null&&(cancelAnimationFrame(this._pendingFrameId),this._pendingFrameId=null),super.dispose()}_scheduleReveal(e,t,n,r){this._pendingFrameId!==null&&cancelAnimationFrame(this._pendingFrameId),this._pendingFrameId=requestAnimationFrame(()=>{this._pendingFrameId=null,this._revealMatch(e,t,n,r)})}_revealMatch(e,n,i,o){let s=document.querySelector(`[data-u-comp="mobile-find-replace-bar"]`);if(!s)return;let c=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET),l=c==null?void 0:c.getActiveSheet();if(!c||!l||c.getUnitId()!==e||l.getSheetId()!==n)return;let u=this._renderManagerService.getRenderUnitById(c.getUnitId()),d=(0,a.getSheetObject)(c,this._renderManagerService),f=u==null?void 0:u.with(a.SheetSkeletonManagerService).getSkeleton(l.getSheetId());if(!d||!f)return;let{scene:p,engine:m}=d,h=(0,a.getViewportByCell)(i,o,p,l);if(!h)return;let{endY:g}=(0,a.getCoordByCell)(i,o,p,f),{scaleY:_}=p.getAncestorScale(),v=p.getViewportScrollXY(h),y=P(m.getCanvasElement().getBoundingClientRect().top+(0,r.convertTransformToOffsetY)(g,_,v),s.getBoundingClientRect().top,8);y!==0&&this._commandService.executeCommand(a.SetScrollRelativeCommand.id,{offsetY:y}).catch(()=>void 0)}};F=x([b(0,t.ICommandService),b(1,t.IUniverInstanceService),b(2,r.IRenderManagerService)],F);let I=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],[F]].forEach(e=>this._injector.add(e))}onRendered(){this._injector.get(F)}onSteady(){this._injector.get(S)}};f(I,`pluginName`,`SHEET_FIND_REPLACE_PLUGIN`),f(I,`packageName`,A),f(I,`version`,j),f(I,`type`,t.UniverInstanceType.UNIVER_SHEET),I=x([(0,t.DependentOn)(r.UniverRenderEnginePlugin,n.UniverSheetsPlugin,i.UniverFindReplaceMobileUIPlugin,a.UniverSheetsMobileUIPlugin),b(1,(0,t.Inject)(t.Injector)),b(2,t.IConfigService)],I);let L=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(L,`pluginName`,`SHEET_FIND_REPLACE_PLUGIN`),f(L,`packageName`,A),f(L,`version`,j),f(L,`type`,t.UniverInstanceType.UNIVER_SHEET),L=x([(0,t.DependentOn)(r.UniverRenderEnginePlugin,n.UniverSheetsPlugin,i.UniverFindReplacePlugin,a.UniverSheetsUIPlugin),b(1,(0,t.Inject)(t.Injector)),b(2,t.IConfigService)],L),e.SheetReplaceCommand=s,Object.defineProperty(e,"SheetsFindReplaceController",{enumerable:!0,get:function(){return S}}),Object.defineProperty(e,"UniverSheetsFindReplaceMobileUIPlugin",{enumerable:!0,get:function(){return I}}),Object.defineProperty(e,"UniverSheetsFindReplacePlugin",{enumerable:!0,get:function(){return L}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-find-replace",
3
- "version": "1.0.0-insiders.20260809-70eefdd",
3
+ "version": "1.0.0-rc.0",
4
4
  "private": false,
5
5
  "description": "Find and replace integration for Univer Sheets.",
6
6
  "author": "DreamNum Co., Ltd. <developer@univer.ai>",
@@ -62,17 +62,17 @@
62
62
  "rxjs": ">=7.0.0"
63
63
  },
64
64
  "dependencies": {
65
- "@univerjs/core": "1.0.0-insiders.20260809-70eefdd",
66
- "@univerjs/engine-render": "1.0.0-insiders.20260809-70eefdd",
67
- "@univerjs/sheets": "1.0.0-insiders.20260809-70eefdd",
68
- "@univerjs/find-replace": "1.0.0-insiders.20260809-70eefdd",
69
- "@univerjs/sheets-ui": "1.0.0-insiders.20260809-70eefdd"
65
+ "@univerjs/core": "1.0.0-rc.0",
66
+ "@univerjs/sheets": "1.0.0-rc.0",
67
+ "@univerjs/sheets-ui": "1.0.0-rc.0",
68
+ "@univerjs/engine-render": "1.0.0-rc.0",
69
+ "@univerjs/find-replace": "1.0.0-rc.0"
70
70
  },
71
71
  "devDependencies": {
72
72
  "rxjs": "^7.8.2",
73
73
  "typescript": "^6.0.3",
74
- "vitest": "^4.1.10",
75
- "@univerjs-infra/shared": "1.0.0-beta.0"
74
+ "vitest": "^5.0.0",
75
+ "@univerjs-infra/shared": "1.0.0-rc.0"
76
76
  },
77
77
  "scripts": {
78
78
  "test": "vitest run",