@univerjs/sheets-find-replace 0.16.1-insiders.20260311-074e8ca → 0.17.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/lib/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var Z=Object.defineProperty;var ee=(c,e,t)=>e in c?Z(c,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):c[e]=t;var _=(c,e,t)=>ee(c,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@univerjs/core"),C=require("@univerjs/sheets"),y=require("@univerjs/engine-render"),S=require("@univerjs/find-replace"),M=require("@univerjs/sheets-ui"),I=require("rxjs"),T={id:"sheet.command.replace",type:l.CommandType.COMMAND,handler:async(c,e)=>{const t=c.get(l.IUndoRedoService),n=c.get(l.ICommandService),{unitId:i,replacements:r}=e,s=t.__tempBatchingUndoRedo(i),o=await Promise.all(r.map(h=>n.executeCommand(C.SetRangeValuesCommand.id,{unitId:i,subUnitId:h.subUnitId,value:h.value})));return s.dispose(),te(o,r)}};function te(c,e){let t=0,n=0;return c.forEach((i,r)=>{const s=e[r].count;i?t+=s:n+=s}),{success:t,failure:n}}class ne extends y.Shape{constructor(t,n){super(t,n);_(this,"_activated",!1);_(this,"_inHiddenRange",!1);_(this,"_color");n&&this.setShapeProps(n)}setShapeProps(t){this._activated=!!t.activated,typeof t.inHiddenRange<"u"&&(this._inHiddenRange=t.inHiddenRange),typeof t.color<"u"&&(this._color=t.color),this.transformByState({width:t.width,height:t.height})}_draw(t){const n=this._activated,i=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 0.35)`,r=`rgb(${this._color.r}, ${this._color.g}, ${this._color.b})`;y.Rect.drawWith(t,{width:this.width,height:this.height,fill:i,stroke:n?r:void 0,strokeWidth:n?2:0,evented:!1})}}function D(c,e){return c.startRow===e.startRow&&c.startColumn===e.startColumn}function N(c,e){return c.startRow<e.startRow||c.startRow===e.startRow&&c.startColumn<=e.startColumn}function $(c,e){return c.startColumn<e.startColumn||c.startColumn===e.startColumn&&c.startRow<=e.startRow}function ie(c,e){return c.startRow>e.startRow||c.startRow===e.startRow&&c.startColumn>=e.startColumn}function se(c,e){return c.startColumn>e.startColumn||c.startColumn===e.startColumn&&c.startRow>=e.startRow}function re(c,e){const{range:t}=c,{startRow:n,startColumn:i}=t,r=e.getMergedCell(n,i);return r?l.Rectangle.equals(t,r):t.endRow===t.startRow&&t.endColumn===t.startColumn}var oe=Object.getOwnPropertyDescriptor,O=(c,e,t,n)=>{for(var i=n>1?void 0:n?oe(e,t):e,r=c.length-1,s;r>=0;r--)(s=c[r])&&(i=s(i)||i);return i},v=(c,e)=>(t,n)=>e(t,n,c);exports.SheetsFindReplaceController=class extends l.Disposable{constructor(t,n,i,r,s){super();_(this,"_provider");this._injector=t,this._findReplaceController=n,this._contextService=i,this._findReplaceService=r,this._commandService=s,this._init(),this._initCommands()}dispose(){super.dispose(),this._findReplaceController.closePanel(),this._provider.dispose()}_init(){const t=this._injector.createInstance(H);this._provider=t,this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(t)),this.disposeWithMe(this._contextService.subscribeContextValue$(l.EDITOR_ACTIVATED).pipe(I.filter(n=>!!n)).subscribe(()=>this._findReplaceController.closePanel()))}_initCommands(){[T].forEach(t=>this.disposeWithMe(this._commandService.registerCommand(t)))}};exports.SheetsFindReplaceController=O([v(0,l.Inject(l.Injector)),v(1,l.Inject(S.FindReplaceController)),v(2,l.IContextService),v(3,S.IFindReplaceService),v(4,l.ICommandService)],exports.SheetsFindReplaceController);const ce="sheets-find-replace-provider",he=1e4;let W=class extends S.FindModel{constructor(e,t,n,i,r,s,o,h){super();_(this,"_matchesUpdate$",new I.Subject);_(this,"matchesUpdate$",this._matchesUpdate$.asObservable());_(this,"_activelyChangingMatch$",new I.Subject);_(this,"activelyChangingMatch$",this._activelyChangingMatch$.asObservable());_(this,"_matchesByWorksheet",new Map);_(this,"_matches",[]);_(this,"_matchesPosition",0);_(this,"_activeHighlightIndex",-1);_(this,"_highlightShapes",[]);_(this,"_currentHighlightShape",null);_(this,"_query",null);_(this,"_workbookSelections");this._workbook=e,this._sheetSkeletonManagerService=t,this._univerInstanceService=n,this._renderManagerService=i,this._commandService=r,this._contextService=s,this._themeService=o,this._workbookSelections=h.getWorkbookSelections(this.unitId)}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}dispose(){super.dispose(),this._disposeHighlights(),this._toggleDisplayRawFormula(!1)}getMatches(){return this._matches}start(e){switch(this._query=e,e.findBy===S.FindBy.FORMULA?this._toggleDisplayRawFormula(!0):this._toggleDisplayRawFormula(!1),e.findScope){case S.FindScope.UNIT:this.findInWorkbook(e);break;case S.FindScope.SUBUNIT:default:this.findInActiveWorksheet(e);break}}focusSelection(){const e=this.currentMatch;e&&this._commandService.executeCommand(C.SelectRangeCommand.id,{unitId:e.unitId,subUnit:e.range.subUnitId,range:e.range.range})}_toggleDisplayRawFormula(e){this._contextService.setContextValue(y.RENDER_RAW_FORMULA_KEY,e)}findInWorkbook(e){const t=this._workbook.getUnitId();let n,i=!0;const r=()=>{const s=this._workbook.getSheets().filter(o=>!o.isSheetHidden()).map(o=>{const h=this._findInWorksheet(o,e,t),d=o.getSheetId(),{results:a}=h;return a.length?this._matchesByWorksheet.set(d,h.results):this._matchesByWorksheet.delete(d),h});this._matches=s.map(o=>o.results).flat(),this._updateFindHighlight(),i?(n={results:this._matches},i=!1):this._matchesUpdate$.next(this._matches)};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>{this._updateFindHighlight(),this._updateCurrentHighlightShape(this._activeHighlightIndex)})),this.disposeWithMe(l.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(I.filter(([s,o])=>s.id===C.SetWorksheetActiveOperation.id&&!(o!=null&&o.fromFindReplace))).subscribe(()=>{const s=this._workbook.getActiveSheet();if(!s)return;const o=s.getSheetId();this._matchesByWorksheet.has(o)&&this._findNextMatchOnActiveSheetChange(s)})),this.disposeWithMe(l.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(I.filter(([s])=>s.type===l.CommandType.MUTATION&&s.params.unitId===this._workbook.getUnitId()),I.throttleTime(600,void 0,{leading:!1,trailing:!0})).subscribe(()=>r())),r(),n}_findNextMatchOnActiveSheetChange(e){let t,n,i=0;const r=this._matchesByWorksheet.get(e.getSheetId()),s=this._workbookSelections.getCurrentSelections();s!=null&&s.length?([t,i]=this._findNextMatchByRange(r,s[0].range),n=r.findIndex(o=>o===t)):(t=r[0],n=0,i=this._matches.findIndex(o=>o===t)),this._matchesPosition=i+1,this._activelyChangingMatch$.next(t),this._activeHighlightIndex=n,this._updateFindHighlight(),this._updateCurrentHighlightShape(n)}findInActiveWorksheet(e){const t=this._workbook.getUnitId(),n=()=>{var u;const h=this._workbook.getActiveSheet();if(!h)return!1;const d=this._workbookSelections.getCurrentSelections();return(u=d==null?void 0:d.some(g=>!re(g,h)))!=null?u:!1};let i,r=!0,s=!1;const o=()=>{const h=this._workbook.getActiveSheet();if(!h)return{results:[]};const d=this.currentMatch;s=n();const a=this._workbookSelections.getCurrentSelections(),u=s?this._findInSelections(h,a,e,t):this._findInWorksheet(h,e,t);return this._matches=u.results,this._matchesPosition=this._tryRestoreLastMatchesPosition(d,this._matches),r?(i=u,r=!1):this._matchesUpdate$.next(this._matches),this._updateFindHighlight(),u};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>this._updateFindHighlight())),this.disposeWithMe(I.merge(l.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(I.filter(([h])=>{if(h.type===l.CommandType.MUTATION&&h.params.unitId===this._workbook.getUnitId())return!0;if(h.id===C.SetSelectionsOperation.id&&h.params.unitId===t){const d=n();return d===!1&&s===!1?!1:(s=d,!0)}return!1})),this._workbook.activeSheet$.pipe(I.skip(1))).pipe(I.debounceTime(200)).subscribe(()=>o())),o(),i}_findInRange(e,t,n,i,r){const s=[],o=e.getSheetId(),h=(t.findDirection===S.FindDirection.COLUMN?e.iterateByColumn:e.iterateByRow).bind(e)(n);for(const d of h){const{row:a,col:u,colSpan:g,rowSpan:m,value:p}=d;if(r!=null&&r(a,u)||!p||e.getRowFiltered(a))continue;const{hit:k,replaceable:w,isFormula:R}=ae(e,a,u,t,p);if(k){const F={provider:ce,unitId:i,replaceable:w,isFormula:R,range:{subUnitId:o,range:{startRow:a,startColumn:u,endColumn:u+(g!=null?g:1)-1,endRow:a+(m!=null?m:1)-1}}};s.push(F)}}return{results:s}}_findInSelections(e,t,n,i){const{findDirection:r}=n,s=r===S.FindDirection.ROW?N:$,o=new Set;return{results:t.map(d=>this._findInRange(e,n,d.range,i,(a,u)=>{const g=`${a}-${u}`;return o.has(g)?!0:(o.add(g),!1)}).results).flat().sort((d,a)=>s(d.range.range,a.range.range)?-1:1)}}_findInWorksheet(e,t,n){const i=e.getRowCount(),r=e.getColumnCount(),s={startRow:0,startColumn:0,endRow:i-1,endColumn:r-1};return this._findInRange(e,t,s,n)}_disposeHighlights(){var e;this._highlightShapes.forEach(t=>{var n;(n=t.getScene())==null||n.makeDirty(),t.dispose()}),this._highlightShapes=[],(e=this._currentHighlightShape)==null||e.dispose(),this._currentHighlightShape=null}_updateFindHighlight(){var u;this._disposeHighlights();const e=(u=this._sheetSkeletonManagerService.getCurrent())==null?void 0:u.skeleton;if(!e)return;const t=this._workbook.getUnitId(),n=this._renderManagerService.getRenderById(t);if(n==null)return;const{scene:i}=n,r=this._matches,s=this._themeService.getColorFromTheme("yellow.400"),o=new l.ColorKit(s).toRgb(),h=this._workbook.getActiveSheet();if(!h)return;const d=h.getSheetId(),a=r.filter(g=>g.range.subUnitId===d).map((g,m)=>{const{startColumn:p,startRow:k,endColumn:w,endRow:R}=g.range.range,F=M.getCoordByCell(k,p,i,e),Y=M.getCoordByCell(R,w,i,e),{startX:E,startY:A}=F,{endX:q,endY:K}=Y;let U=!0;for(let b=k;b<=R;b++)if(h.getRowRawVisible(b)){U=!1;break}let P=!0;for(let b=p;b<=w;b++)if(h.getColVisible(b)){P=!1;break}const Q=U||P,X=P?2:q-E,z=U?2:K-A,J={left:E,top:A,color:o,width:X,height:z,evented:!1,inHiddenRange:Q,zIndex:he};return new ne(`find-highlight-${m}`,J)});i.addObjects(a),this._highlightShapes=a,i.makeDirty()}_updateCurrentHighlightShape(e){var t;if((t=this._currentHighlightShape)==null||t.setShapeProps({activated:!1}),this._currentHighlightShape=null,e!==void 0){const n=this._highlightShapes[e];if(!n)return;this._currentHighlightShape=n,n.setShapeProps({activated:!0})}}_getSheetObject(){return M.getSheetObject(this._univerInstanceService,this._renderManagerService)}_focusMatch(e){var n;const t=e.range.subUnitId;t!==((n=this._workbook.getActiveSheet())==null?void 0:n.getSheetId())&&this._commandService.executeCommand(C.SetWorksheetActivateCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:t},{fromFindReplace:!0}),this._commandService.executeCommand(M.ScrollToCellCommand.id,{range:e.range.range},{fromFindReplace:!0})}_tryRestoreLastMatchesPosition(e,t){if(!e)return 0;const{subUnitId:n}=e.range,{startColumn:i,startRow:r}=e.range.range,s=t.findIndex(o=>{if(n!==o.range.subUnitId)return!1;const{startColumn:h,startRow:d}=o.range.range;return h===i&&d===r});return s>-1?s+1:0}moveToNextMatch(e){var o,h,d,a,u;if(!this._matches.length)return null;const t=(o=e==null?void 0:e.loop)!=null?o:!1,n=(h=e==null?void 0:e.stayIfOnMatch)!=null?h:!1,i=(d=e==null?void 0:e.noFocus)!=null?d:!1,r=(a=e==null?void 0:e.ignoreSelection)!=null?a:!1,s=this._findNextMatch(t,n,r);if(s){const[g,m]=s;return this._matchesPosition=m+1,this._query.findScope===S.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(g.range.subUnitId).findIndex(p=>p===g):this._activeHighlightIndex=m,i||this._focusMatch(g),((u=this._workbook.getActiveSheet())==null?void 0:u.getSheetId())===g.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),g}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}moveToPreviousMatch(e){var o,h,d,a,u;if(!this._matches.length)return null;const t=(o=e==null?void 0:e.loop)!=null?o:!1,n=(h=e==null?void 0:e.stayIfOnMatch)!=null?h:!1,i=(d=e==null?void 0:e.noFocus)!=null?d:!1,r=(a=e==null?void 0:e.ignoreSelection)!=null?a:!1,s=this._findPreviousMatch(t,n,r);if(s){const[g,m]=s;return this._matchesPosition=m+1,this._query.findScope===S.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(g.range.subUnitId).findIndex(p=>p===g):this._activeHighlightIndex=m,i||this._focusMatch(g),((u=this._workbook.getActiveSheet())==null?void 0:u.getSheetId())===g.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),g}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}_findPreviousMatch(e=!1,t=!1,n=!1){var o;if(this.currentMatch){const h=this._matches.findIndex(g=>g===this.currentMatch);if(t)return[this.currentMatch,h];const d=h-1;if(!e&&d<0)return null;const a=this._matches.length,u=(d+a)%a;return[this._matches[u],u]}const i=this._workbookSelections.getCurrentLastSelection();if(n||!i){const h=this._matches.length-1;return[this._matches[h],h]}if(this._query.findScope!==S.FindScope.UNIT)return this._findPreviousMatchByRange(this._matches,i.range);const r=(o=this._workbook.getActiveSheet())==null?void 0:o.getSheetId();if(!r)return null;const s=this._findPreviousWorksheetThatHasAMatch(r,e);return s?this._findPreviousMatchByRange(this._matchesByWorksheet.get(s),i.range):null}_findNextMatch(e=!1,t=!1,n=!1){var o;if(this.currentMatch){const h=this._matches.findIndex(g=>g===this.currentMatch);if(t)return[this.currentMatch,h];const d=h+1,a=this._matches.length;if(!e&&d>=a)return null;const u=d%a;return[this._matches[u],u]}const i=this._workbookSelections.getCurrentLastSelection();if(n||!i)return[this._matches[0],0];if(this._query.findScope!==S.FindScope.UNIT)return this._findNextMatchByRange(this._matches,i.range,t);const r=(o=this._workbook.getActiveSheet())==null?void 0:o.getSheetId();if(!r)return null;const s=this._findNextWorksheetThatHasAMatch(r,e);return s?this._findNextMatchByRange(this._matchesByWorksheet.get(s),i.range):null}_findPreviousWorksheetThatHasAMatch(e,t=!1){const n=this._workbook.getSheetOrders(),i=n.findIndex(o=>o===e),s=(t?l.rotate(n,i+1):n.slice(0,i+1)).findLast(o=>this._matchesByWorksheet.has(o));return s!=null?s:null}_findNextWorksheetThatHasAMatch(e,t=!1){const n=this._workbook.getSheetOrders(),i=n.findIndex(o=>o===e),s=(t?l.rotate(n,i):n.slice(i)).find(o=>this._matchesByWorksheet.has(o));return s!=null?s:null}_findNextMatchByRange(e,t,n=!1){const i=this._query.findDirection===S.FindDirection.ROW;let r=e.findIndex(o=>{const h=o.range.range;if(!(i?N(t,h):$(t,h)))return!1;const a=D(t,h);return n?a:!a});r===-1&&(r=e.length-1);const s=e[r];return[s,this._matches.findIndex(o=>o===s)]}_findPreviousMatchByRange(e,t,n=!1){const i=this._query.findDirection===S.FindDirection.ROW;let r=this._matches.findLastIndex(o=>{const h=o.range.range;if(!(i?ie(t,h):se(t,h)))return!1;const a=D(t,h);return n?a:!a});r===-1&&(r=0);const s=e[r];return[s,this._matches.findIndex(o=>o===s)]}async replace(e){if(this._matchesCount===0||!this.currentMatch||!this._query||!this.currentMatch.replaceable)return!1;const t=this.currentMatch.range,n=this._workbook.getSheetBySheetId(this.currentMatch.range.subUnitId),i=this._getReplacedCellData(this.currentMatch,n,this._query.findBy===S.FindBy.FORMULA,this._query.findString,e,this._query.caseSensitive?"g":"ig"),r={unitId:this.currentMatch.unitId,subUnitId:t.subUnitId,value:{[t.range.startRow]:{[t.range.startColumn]:i}}};return this._commandService.executeCommand(C.SetRangeValuesCommand.id,r)}async replaceAll(e){if(this._matchesCount===0||!this._query)return{success:0,failure:0};const t=this._workbook.getUnitId(),{findString:n,caseSensitive:i,findBy:r}=this._query,s=r===S.FindBy.FORMULA,o=i?"g":"ig",h=[];return l.groupBy(this._matches.filter(a=>a.replaceable),a=>a.range.subUnitId).forEach((a,u)=>{const g=new l.ObjectMatrix,m=this._workbook.getSheetBySheetId(u);a.forEach(p=>{const{startColumn:k,startRow:w}=p.range.range,R=this._getReplacedCellData(p,m,s,n,e,o);R&&g.setValue(w,k,R)}),h.push({count:a.length,subUnitId:u,value:g.getMatrix()})}),h?this._commandService.executeCommand(T.id,{unitId:t,replacements:h}):{success:0,failure:0}}_getReplacedCellData(e,t,n,i,r,s){var m;const o=e.range.range,{startRow:h,startColumn:d}=o,a=t.getCellRaw(h,d);if(e.isFormula)return n?{f:a.f.replace(new RegExp(j(i),s),r),v:null}:null;if(!!((m=a.p)!=null&&m.body)){const p=l.Tools.deepClone(a.p);return l.replaceInDocumentBody(p.body,i,r,this._query.caseSensitive),{p}}return{v:a.v.toString().replace(new RegExp(j(i),s),r)}}};W=O([v(2,l.IUniverInstanceService),v(3,y.IRenderManagerService),v(4,l.ICommandService),v(5,l.IContextService),v(6,l.Inject(l.ThemeService)),v(7,l.Inject(C.SheetsSelectionsService))],W);function j(c){return c.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}let H=class extends l.Disposable{constructor(e,t,n){super();_(this,"_findModelsByUnitId",new Map);this._univerInstanceService=e,this._renderManagerService=t,this._injector=n}async find(e){this._terminate();const t=this._univerInstanceService.getCurrentUnitOfType(l.UniverInstanceType.UNIVER_SHEET);if(!t)return[];const n=this._preprocessQuery(e),i=this._renderManagerService.getRenderById(t.getUnitId()).with(M.SheetSkeletonManagerService),r=this._injector.createInstance(W,t,i);return this._findModelsByUnitId.set(t.getUnitId(),r),r.start(n),[r]}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}}};H=O([v(0,l.IUniverInstanceService),v(1,y.IRenderManagerService),v(2,l.Inject(l.Injector))],H);const f={hit:!1,replaceable:!1,isFormula:!1,rawData:null};function ae(c,e,t,n,i){const{findBy:r}=n,s=r===S.FindBy.FORMULA,o=c.getCellRaw(e,t);return f.rawData=o,!(o!=null&&o.f)?(f.isFormula=!1,B(i,n)?o?(f.hit=!0,f.replaceable=!0):(f.hit=!0,f.replaceable=!1):(f.hit=!1,f.replaceable=!1),f):(f.isFormula=!0,s?B({v:o.f},n)?(f.hit=!0,f.replaceable=!0,f):(f.hit=!1,f.replaceable=!1,f):(f.replaceable=!1,B(i,n)?f.hit=!0:f.hit=!1,f))}function B(c,e){let t=le(c);return t?e.matchesTheWholeCell?(t=de(t),e.caseSensitive?t===e.findString:t.toLowerCase()===e.findString):e.caseSensitive?t.indexOf(e.findString)>-1:t.toLowerCase().indexOf(e.findString)>-1:!1}function le(c){var t,n,i;const e=(i=(n=(t=c==null?void 0:c.p)==null?void 0:t.body)==null?void 0:n.dataStream)!=null?i:c==null?void 0:c.v;return typeof e=="number"?`${e}`:typeof e=="boolean"?e?"1":"0":e}function de(c){return c.replace(/^ +/g,"").replace(/ +$/g,"")}const ue="@univerjs/sheets-find-replace",ge="0.16.1-insiders.20260311-074e8ca",G={name:ue,version:ge},fe="sheets-find-replace.config",L={};var _e=Object.defineProperty,Se=Object.getOwnPropertyDescriptor,me=(c,e,t)=>e in c?_e(c,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):c[e]=t,pe=(c,e,t,n)=>{for(var i=n>1?void 0:n?Se(e,t):e,r=c.length-1,s;r>=0;r--)(s=c[r])&&(i=s(i)||i);return i},V=(c,e)=>(t,n)=>e(t,n,c),x=(c,e,t)=>me(c,typeof e!="symbol"?e+"":e,t);exports.UniverSheetsFindReplacePlugin=class extends l.Plugin{constructor(e=L,t,n){super(),this._config=e,this._injector=t,this._configService=n;const{...i}=l.merge({},L,this._config);this._configService.setConfig(fe,i)}onStarting(){[[exports.SheetsFindReplaceController]].forEach(e=>this._injector.add(e))}onSteady(){this._injector.get(exports.SheetsFindReplaceController)}};x(exports.UniverSheetsFindReplacePlugin,"pluginName","SHEET_FIND_REPLACE_PLUGIN");x(exports.UniverSheetsFindReplacePlugin,"packageName",G.name);x(exports.UniverSheetsFindReplacePlugin,"version",G.version);x(exports.UniverSheetsFindReplacePlugin,"type",l.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsFindReplacePlugin=pe([l.DependentOn(C.UniverSheetsPlugin,C.UniverSheetsPlugin,S.UniverFindReplacePlugin),V(1,l.Inject(l.Injector)),V(2,l.IConfigService)],exports.UniverSheetsFindReplacePlugin);exports.SheetReplaceCommand=T;
1
+ "use strict";var Z=Object.defineProperty;var ee=(c,e,t)=>e in c?Z(c,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):c[e]=t;var _=(c,e,t)=>ee(c,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@univerjs/core"),C=require("@univerjs/sheets"),y=require("@univerjs/engine-render"),S=require("@univerjs/find-replace"),M=require("@univerjs/sheets-ui"),I=require("rxjs"),T={id:"sheet.command.replace",type:l.CommandType.COMMAND,handler:async(c,e)=>{const t=c.get(l.IUndoRedoService),n=c.get(l.ICommandService),{unitId:i,replacements:r}=e,s=t.__tempBatchingUndoRedo(i),o=await Promise.all(r.map(h=>n.executeCommand(C.SetRangeValuesCommand.id,{unitId:i,subUnitId:h.subUnitId,value:h.value})));return s.dispose(),te(o,r)}};function te(c,e){let t=0,n=0;return c.forEach((i,r)=>{const s=e[r].count;i?t+=s:n+=s}),{success:t,failure:n}}class ne extends y.Shape{constructor(t,n){super(t,n);_(this,"_activated",!1);_(this,"_inHiddenRange",!1);_(this,"_color");n&&this.setShapeProps(n)}setShapeProps(t){this._activated=!!t.activated,typeof t.inHiddenRange<"u"&&(this._inHiddenRange=t.inHiddenRange),typeof t.color<"u"&&(this._color=t.color),this.transformByState({width:t.width,height:t.height})}_draw(t){const n=this._activated,i=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 0.35)`,r=`rgb(${this._color.r}, ${this._color.g}, ${this._color.b})`;y.Rect.drawWith(t,{width:this.width,height:this.height,fill:i,stroke:n?r:void 0,strokeWidth:n?2:0,evented:!1})}}function D(c,e){return c.startRow===e.startRow&&c.startColumn===e.startColumn}function N(c,e){return c.startRow<e.startRow||c.startRow===e.startRow&&c.startColumn<=e.startColumn}function $(c,e){return c.startColumn<e.startColumn||c.startColumn===e.startColumn&&c.startRow<=e.startRow}function ie(c,e){return c.startRow>e.startRow||c.startRow===e.startRow&&c.startColumn>=e.startColumn}function se(c,e){return c.startColumn>e.startColumn||c.startColumn===e.startColumn&&c.startRow>=e.startRow}function re(c,e){const{range:t}=c,{startRow:n,startColumn:i}=t,r=e.getMergedCell(n,i);return r?l.Rectangle.equals(t,r):t.endRow===t.startRow&&t.endColumn===t.startColumn}var oe=Object.getOwnPropertyDescriptor,O=(c,e,t,n)=>{for(var i=n>1?void 0:n?oe(e,t):e,r=c.length-1,s;r>=0;r--)(s=c[r])&&(i=s(i)||i);return i},v=(c,e)=>(t,n)=>e(t,n,c);exports.SheetsFindReplaceController=class extends l.Disposable{constructor(t,n,i,r,s){super();_(this,"_provider");this._injector=t,this._findReplaceController=n,this._contextService=i,this._findReplaceService=r,this._commandService=s,this._init(),this._initCommands()}dispose(){super.dispose(),this._findReplaceController.closePanel(),this._provider.dispose()}_init(){const t=this._injector.createInstance(H);this._provider=t,this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(t)),this.disposeWithMe(this._contextService.subscribeContextValue$(l.EDITOR_ACTIVATED).pipe(I.filter(n=>!!n)).subscribe(()=>this._findReplaceController.closePanel()))}_initCommands(){[T].forEach(t=>this.disposeWithMe(this._commandService.registerCommand(t)))}};exports.SheetsFindReplaceController=O([v(0,l.Inject(l.Injector)),v(1,l.Inject(S.FindReplaceController)),v(2,l.IContextService),v(3,S.IFindReplaceService),v(4,l.ICommandService)],exports.SheetsFindReplaceController);const ce="sheets-find-replace-provider",he=1e4;let W=class extends S.FindModel{constructor(e,t,n,i,r,s,o,h){super();_(this,"_matchesUpdate$",new I.Subject);_(this,"matchesUpdate$",this._matchesUpdate$.asObservable());_(this,"_activelyChangingMatch$",new I.Subject);_(this,"activelyChangingMatch$",this._activelyChangingMatch$.asObservable());_(this,"_matchesByWorksheet",new Map);_(this,"_matches",[]);_(this,"_matchesPosition",0);_(this,"_activeHighlightIndex",-1);_(this,"_highlightShapes",[]);_(this,"_currentHighlightShape",null);_(this,"_query",null);_(this,"_workbookSelections");this._workbook=e,this._sheetSkeletonManagerService=t,this._univerInstanceService=n,this._renderManagerService=i,this._commandService=r,this._contextService=s,this._themeService=o,this._workbookSelections=h.getWorkbookSelections(this.unitId)}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}dispose(){super.dispose(),this._disposeHighlights(),this._toggleDisplayRawFormula(!1)}getMatches(){return this._matches}start(e){switch(this._query=e,e.findBy===S.FindBy.FORMULA?this._toggleDisplayRawFormula(!0):this._toggleDisplayRawFormula(!1),e.findScope){case S.FindScope.UNIT:this.findInWorkbook(e);break;case S.FindScope.SUBUNIT:default:this.findInActiveWorksheet(e);break}}focusSelection(){const e=this.currentMatch;e&&this._commandService.executeCommand(C.SelectRangeCommand.id,{unitId:e.unitId,subUnit:e.range.subUnitId,range:e.range.range})}_toggleDisplayRawFormula(e){this._contextService.setContextValue(y.RENDER_RAW_FORMULA_KEY,e)}findInWorkbook(e){const t=this._workbook.getUnitId();let n,i=!0;const r=()=>{const s=this._workbook.getSheets().filter(o=>!o.isSheetHidden()).map(o=>{const h=this._findInWorksheet(o,e,t),d=o.getSheetId(),{results:a}=h;return a.length?this._matchesByWorksheet.set(d,h.results):this._matchesByWorksheet.delete(d),h});this._matches=s.map(o=>o.results).flat(),this._updateFindHighlight(),i?(n={results:this._matches},i=!1):this._matchesUpdate$.next(this._matches)};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>{this._updateFindHighlight(),this._updateCurrentHighlightShape(this._activeHighlightIndex)})),this.disposeWithMe(l.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(I.filter(([s,o])=>s.id===C.SetWorksheetActiveOperation.id&&!(o!=null&&o.fromFindReplace))).subscribe(()=>{const s=this._workbook.getActiveSheet();if(!s)return;const o=s.getSheetId();this._matchesByWorksheet.has(o)&&this._findNextMatchOnActiveSheetChange(s)})),this.disposeWithMe(l.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(I.filter(([s])=>s.type===l.CommandType.MUTATION&&s.params.unitId===this._workbook.getUnitId()),I.throttleTime(600,void 0,{leading:!1,trailing:!0})).subscribe(()=>r())),r(),n}_findNextMatchOnActiveSheetChange(e){let t,n,i=0;const r=this._matchesByWorksheet.get(e.getSheetId()),s=this._workbookSelections.getCurrentSelections();s!=null&&s.length?([t,i]=this._findNextMatchByRange(r,s[0].range),n=r.findIndex(o=>o===t)):(t=r[0],n=0,i=this._matches.findIndex(o=>o===t)),this._matchesPosition=i+1,this._activelyChangingMatch$.next(t),this._activeHighlightIndex=n,this._updateFindHighlight(),this._updateCurrentHighlightShape(n)}findInActiveWorksheet(e){const t=this._workbook.getUnitId(),n=()=>{var u;const h=this._workbook.getActiveSheet();if(!h)return!1;const d=this._workbookSelections.getCurrentSelections();return(u=d==null?void 0:d.some(g=>!re(g,h)))!=null?u:!1};let i,r=!0,s=!1;const o=()=>{const h=this._workbook.getActiveSheet();if(!h)return{results:[]};const d=this.currentMatch;s=n();const a=this._workbookSelections.getCurrentSelections(),u=s?this._findInSelections(h,a,e,t):this._findInWorksheet(h,e,t);return this._matches=u.results,this._matchesPosition=this._tryRestoreLastMatchesPosition(d,this._matches),r?(i=u,r=!1):this._matchesUpdate$.next(this._matches),this._updateFindHighlight(),u};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>this._updateFindHighlight())),this.disposeWithMe(I.merge(l.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(I.filter(([h])=>{if(h.type===l.CommandType.MUTATION&&h.params.unitId===this._workbook.getUnitId())return!0;if(h.id===C.SetSelectionsOperation.id&&h.params.unitId===t){const d=n();return d===!1&&s===!1?!1:(s=d,!0)}return!1})),this._workbook.activeSheet$.pipe(I.skip(1))).pipe(I.debounceTime(200)).subscribe(()=>o())),o(),i}_findInRange(e,t,n,i,r){const s=[],o=e.getSheetId(),h=(t.findDirection===S.FindDirection.COLUMN?e.iterateByColumn:e.iterateByRow).bind(e)(n);for(const d of h){const{row:a,col:u,colSpan:g,rowSpan:m,value:p}=d;if(r!=null&&r(a,u)||!p||e.getRowFiltered(a))continue;const{hit:k,replaceable:w,isFormula:R}=ae(e,a,u,t,p);if(k){const F={provider:ce,unitId:i,replaceable:w,isFormula:R,range:{subUnitId:o,range:{startRow:a,startColumn:u,endColumn:u+(g!=null?g:1)-1,endRow:a+(m!=null?m:1)-1}}};s.push(F)}}return{results:s}}_findInSelections(e,t,n,i){const{findDirection:r}=n,s=r===S.FindDirection.ROW?N:$,o=new Set;return{results:t.map(d=>this._findInRange(e,n,d.range,i,(a,u)=>{const g=`${a}-${u}`;return o.has(g)?!0:(o.add(g),!1)}).results).flat().sort((d,a)=>s(d.range.range,a.range.range)?-1:1)}}_findInWorksheet(e,t,n){const i=e.getRowCount(),r=e.getColumnCount(),s={startRow:0,startColumn:0,endRow:i-1,endColumn:r-1};return this._findInRange(e,t,s,n)}_disposeHighlights(){var e;this._highlightShapes.forEach(t=>{var n;(n=t.getScene())==null||n.makeDirty(),t.dispose()}),this._highlightShapes=[],(e=this._currentHighlightShape)==null||e.dispose(),this._currentHighlightShape=null}_updateFindHighlight(){var u;this._disposeHighlights();const e=(u=this._sheetSkeletonManagerService.getCurrent())==null?void 0:u.skeleton;if(!e)return;const t=this._workbook.getUnitId(),n=this._renderManagerService.getRenderById(t);if(n==null)return;const{scene:i}=n,r=this._matches,s=this._themeService.getColorFromTheme("yellow.400"),o=new l.ColorKit(s).toRgb(),h=this._workbook.getActiveSheet();if(!h)return;const d=h.getSheetId(),a=r.filter(g=>g.range.subUnitId===d).map((g,m)=>{const{startColumn:p,startRow:k,endColumn:w,endRow:R}=g.range.range,F=M.getCoordByCell(k,p,i,e),Y=M.getCoordByCell(R,w,i,e),{startX:E,startY:A}=F,{endX:q,endY:K}=Y;let U=!0;for(let b=k;b<=R;b++)if(h.getRowRawVisible(b)){U=!1;break}let P=!0;for(let b=p;b<=w;b++)if(h.getColVisible(b)){P=!1;break}const Q=U||P,X=P?2:q-E,z=U?2:K-A,J={left:E,top:A,color:o,width:X,height:z,evented:!1,inHiddenRange:Q,zIndex:he};return new ne(`find-highlight-${m}`,J)});i.addObjects(a),this._highlightShapes=a,i.makeDirty()}_updateCurrentHighlightShape(e){var t;if((t=this._currentHighlightShape)==null||t.setShapeProps({activated:!1}),this._currentHighlightShape=null,e!==void 0){const n=this._highlightShapes[e];if(!n)return;this._currentHighlightShape=n,n.setShapeProps({activated:!0})}}_getSheetObject(){return M.getSheetObject(this._univerInstanceService,this._renderManagerService)}_focusMatch(e){var n;const t=e.range.subUnitId;t!==((n=this._workbook.getActiveSheet())==null?void 0:n.getSheetId())&&this._commandService.executeCommand(C.SetWorksheetActivateCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:t},{fromFindReplace:!0}),this._commandService.executeCommand(M.ScrollToCellCommand.id,{range:e.range.range},{fromFindReplace:!0})}_tryRestoreLastMatchesPosition(e,t){if(!e)return 0;const{subUnitId:n}=e.range,{startColumn:i,startRow:r}=e.range.range,s=t.findIndex(o=>{if(n!==o.range.subUnitId)return!1;const{startColumn:h,startRow:d}=o.range.range;return h===i&&d===r});return s>-1?s+1:0}moveToNextMatch(e){var o,h,d,a,u;if(!this._matches.length)return null;const t=(o=e==null?void 0:e.loop)!=null?o:!1,n=(h=e==null?void 0:e.stayIfOnMatch)!=null?h:!1,i=(d=e==null?void 0:e.noFocus)!=null?d:!1,r=(a=e==null?void 0:e.ignoreSelection)!=null?a:!1,s=this._findNextMatch(t,n,r);if(s){const[g,m]=s;return this._matchesPosition=m+1,this._query.findScope===S.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(g.range.subUnitId).findIndex(p=>p===g):this._activeHighlightIndex=m,i||this._focusMatch(g),((u=this._workbook.getActiveSheet())==null?void 0:u.getSheetId())===g.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),g}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}moveToPreviousMatch(e){var o,h,d,a,u;if(!this._matches.length)return null;const t=(o=e==null?void 0:e.loop)!=null?o:!1,n=(h=e==null?void 0:e.stayIfOnMatch)!=null?h:!1,i=(d=e==null?void 0:e.noFocus)!=null?d:!1,r=(a=e==null?void 0:e.ignoreSelection)!=null?a:!1,s=this._findPreviousMatch(t,n,r);if(s){const[g,m]=s;return this._matchesPosition=m+1,this._query.findScope===S.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(g.range.subUnitId).findIndex(p=>p===g):this._activeHighlightIndex=m,i||this._focusMatch(g),((u=this._workbook.getActiveSheet())==null?void 0:u.getSheetId())===g.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),g}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}_findPreviousMatch(e=!1,t=!1,n=!1){var o;if(this.currentMatch){const h=this._matches.findIndex(g=>g===this.currentMatch);if(t)return[this.currentMatch,h];const d=h-1;if(!e&&d<0)return null;const a=this._matches.length,u=(d+a)%a;return[this._matches[u],u]}const i=this._workbookSelections.getCurrentLastSelection();if(n||!i){const h=this._matches.length-1;return[this._matches[h],h]}if(this._query.findScope!==S.FindScope.UNIT)return this._findPreviousMatchByRange(this._matches,i.range);const r=(o=this._workbook.getActiveSheet())==null?void 0:o.getSheetId();if(!r)return null;const s=this._findPreviousWorksheetThatHasAMatch(r,e);return s?this._findPreviousMatchByRange(this._matchesByWorksheet.get(s),i.range):null}_findNextMatch(e=!1,t=!1,n=!1){var o;if(this.currentMatch){const h=this._matches.findIndex(g=>g===this.currentMatch);if(t)return[this.currentMatch,h];const d=h+1,a=this._matches.length;if(!e&&d>=a)return null;const u=d%a;return[this._matches[u],u]}const i=this._workbookSelections.getCurrentLastSelection();if(n||!i)return[this._matches[0],0];if(this._query.findScope!==S.FindScope.UNIT)return this._findNextMatchByRange(this._matches,i.range,t);const r=(o=this._workbook.getActiveSheet())==null?void 0:o.getSheetId();if(!r)return null;const s=this._findNextWorksheetThatHasAMatch(r,e);return s?this._findNextMatchByRange(this._matchesByWorksheet.get(s),i.range):null}_findPreviousWorksheetThatHasAMatch(e,t=!1){const n=this._workbook.getSheetOrders(),i=n.findIndex(o=>o===e),s=(t?l.rotate(n,i+1):n.slice(0,i+1)).findLast(o=>this._matchesByWorksheet.has(o));return s!=null?s:null}_findNextWorksheetThatHasAMatch(e,t=!1){const n=this._workbook.getSheetOrders(),i=n.findIndex(o=>o===e),s=(t?l.rotate(n,i):n.slice(i)).find(o=>this._matchesByWorksheet.has(o));return s!=null?s:null}_findNextMatchByRange(e,t,n=!1){const i=this._query.findDirection===S.FindDirection.ROW;let r=e.findIndex(o=>{const h=o.range.range;if(!(i?N(t,h):$(t,h)))return!1;const a=D(t,h);return n?a:!a});r===-1&&(r=e.length-1);const s=e[r];return[s,this._matches.findIndex(o=>o===s)]}_findPreviousMatchByRange(e,t,n=!1){const i=this._query.findDirection===S.FindDirection.ROW;let r=this._matches.findLastIndex(o=>{const h=o.range.range;if(!(i?ie(t,h):se(t,h)))return!1;const a=D(t,h);return n?a:!a});r===-1&&(r=0);const s=e[r];return[s,this._matches.findIndex(o=>o===s)]}async replace(e){if(this._matchesCount===0||!this.currentMatch||!this._query||!this.currentMatch.replaceable)return!1;const t=this.currentMatch.range,n=this._workbook.getSheetBySheetId(this.currentMatch.range.subUnitId),i=this._getReplacedCellData(this.currentMatch,n,this._query.findBy===S.FindBy.FORMULA,this._query.findString,e,this._query.caseSensitive?"g":"ig"),r={unitId:this.currentMatch.unitId,subUnitId:t.subUnitId,value:{[t.range.startRow]:{[t.range.startColumn]:i}}};return this._commandService.executeCommand(C.SetRangeValuesCommand.id,r)}async replaceAll(e){if(this._matchesCount===0||!this._query)return{success:0,failure:0};const t=this._workbook.getUnitId(),{findString:n,caseSensitive:i,findBy:r}=this._query,s=r===S.FindBy.FORMULA,o=i?"g":"ig",h=[];return l.groupBy(this._matches.filter(a=>a.replaceable),a=>a.range.subUnitId).forEach((a,u)=>{const g=new l.ObjectMatrix,m=this._workbook.getSheetBySheetId(u);a.forEach(p=>{const{startColumn:k,startRow:w}=p.range.range,R=this._getReplacedCellData(p,m,s,n,e,o);R&&g.setValue(w,k,R)}),h.push({count:a.length,subUnitId:u,value:g.getMatrix()})}),h?this._commandService.executeCommand(T.id,{unitId:t,replacements:h}):{success:0,failure:0}}_getReplacedCellData(e,t,n,i,r,s){var m;const o=e.range.range,{startRow:h,startColumn:d}=o,a=t.getCellRaw(h,d);if(e.isFormula)return n?{f:a.f.replace(new RegExp(j(i),s),r),v:null}:null;if(!!((m=a.p)!=null&&m.body)){const p=l.Tools.deepClone(a.p);return l.replaceInDocumentBody(p.body,i,r,this._query.caseSensitive),{p}}return{v:a.v.toString().replace(new RegExp(j(i),s),r)}}};W=O([v(2,l.IUniverInstanceService),v(3,y.IRenderManagerService),v(4,l.ICommandService),v(5,l.IContextService),v(6,l.Inject(l.ThemeService)),v(7,l.Inject(C.SheetsSelectionsService))],W);function j(c){return c.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}let H=class extends l.Disposable{constructor(e,t,n){super();_(this,"_findModelsByUnitId",new Map);this._univerInstanceService=e,this._renderManagerService=t,this._injector=n}async find(e){this._terminate();const t=this._univerInstanceService.getCurrentUnitOfType(l.UniverInstanceType.UNIVER_SHEET);if(!t)return[];const n=this._preprocessQuery(e),i=this._renderManagerService.getRenderById(t.getUnitId()).with(M.SheetSkeletonManagerService),r=this._injector.createInstance(W,t,i);return this._findModelsByUnitId.set(t.getUnitId(),r),r.start(n),[r]}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}}};H=O([v(0,l.IUniverInstanceService),v(1,y.IRenderManagerService),v(2,l.Inject(l.Injector))],H);const f={hit:!1,replaceable:!1,isFormula:!1,rawData:null};function ae(c,e,t,n,i){const{findBy:r}=n,s=r===S.FindBy.FORMULA,o=c.getCellRaw(e,t);return f.rawData=o,!(o!=null&&o.f)?(f.isFormula=!1,B(i,n)?o?(f.hit=!0,f.replaceable=!0):(f.hit=!0,f.replaceable=!1):(f.hit=!1,f.replaceable=!1),f):(f.isFormula=!0,s?B({v:o.f},n)?(f.hit=!0,f.replaceable=!0,f):(f.hit=!1,f.replaceable=!1,f):(f.replaceable=!1,B(i,n)?f.hit=!0:f.hit=!1,f))}function B(c,e){let t=le(c);return t?e.matchesTheWholeCell?(t=de(t),e.caseSensitive?t===e.findString:t.toLowerCase()===e.findString):e.caseSensitive?t.indexOf(e.findString)>-1:t.toLowerCase().indexOf(e.findString)>-1:!1}function le(c){var t,n,i;const e=(i=(n=(t=c==null?void 0:c.p)==null?void 0:t.body)==null?void 0:n.dataStream)!=null?i:c==null?void 0:c.v;return typeof e=="number"?`${e}`:typeof e=="boolean"?e?"1":"0":e}function de(c){return c.replace(/^ +/g,"").replace(/ +$/g,"")}const ue="@univerjs/sheets-find-replace",ge="0.17.0",G={name:ue,version:ge},fe="sheets-find-replace.config",L={};var _e=Object.defineProperty,Se=Object.getOwnPropertyDescriptor,me=(c,e,t)=>e in c?_e(c,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):c[e]=t,pe=(c,e,t,n)=>{for(var i=n>1?void 0:n?Se(e,t):e,r=c.length-1,s;r>=0;r--)(s=c[r])&&(i=s(i)||i);return i},V=(c,e)=>(t,n)=>e(t,n,c),x=(c,e,t)=>me(c,typeof e!="symbol"?e+"":e,t);exports.UniverSheetsFindReplacePlugin=class extends l.Plugin{constructor(e=L,t,n){super(),this._config=e,this._injector=t,this._configService=n;const{...i}=l.merge({},L,this._config);this._configService.setConfig(fe,i)}onStarting(){[[exports.SheetsFindReplaceController]].forEach(e=>this._injector.add(e))}onSteady(){this._injector.get(exports.SheetsFindReplaceController)}};x(exports.UniverSheetsFindReplacePlugin,"pluginName","SHEET_FIND_REPLACE_PLUGIN");x(exports.UniverSheetsFindReplacePlugin,"packageName",G.name);x(exports.UniverSheetsFindReplacePlugin,"version",G.version);x(exports.UniverSheetsFindReplacePlugin,"type",l.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsFindReplacePlugin=pe([l.DependentOn(C.UniverSheetsPlugin,C.UniverSheetsPlugin,S.UniverFindReplacePlugin),V(1,l.Inject(l.Injector)),V(2,l.IConfigService)],exports.UniverSheetsFindReplacePlugin);exports.SheetReplaceCommand=T;
package/lib/es/facade.js CHANGED
@@ -1,8 +1,8 @@
1
1
  var u = Object.defineProperty;
2
2
  var p = (a, e, t) => e in a ? u(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t;
3
3
  var c = (a, e, t) => p(a, typeof e != "symbol" ? e + "" : e, t);
4
- import { Inject as m, Injector as _, Disposable as f, IUniverInstanceService as v } from "@univerjs/core";
5
- import { FindReplaceModel as g, createInitFindReplaceState as y, FindReplaceState as S, FindBy as h, IFindReplaceService as b } from "@univerjs/find-replace";
4
+ import { Inject as m, Injector as _, IUniverInstanceService as f, Disposable as v } from "@univerjs/core";
5
+ import { IFindReplaceService as g, FindReplaceModel as y, createInitFindReplaceState as S, FindReplaceState as b, FindBy as h } from "@univerjs/find-replace";
6
6
  import { FRange as F } from "@univerjs/sheets/facade";
7
7
  import { FUniver as d } from "@univerjs/core/facade";
8
8
  var w = Object.getOwnPropertyDescriptor, C = (a, e, t, s) => {
@@ -10,17 +10,17 @@ var w = Object.getOwnPropertyDescriptor, C = (a, e, t, s) => {
10
10
  (r = a[i]) && (n = r(n) || n);
11
11
  return n;
12
12
  }, o = (a, e) => (t, s) => e(t, s, a);
13
- let l = class extends f {
13
+ let l = class extends v {
14
14
  constructor(e, t, s, n) {
15
15
  super();
16
- c(this, "_state", new S());
16
+ c(this, "_state", new b());
17
17
  c(this, "_model");
18
18
  c(this, "_complete");
19
19
  this._injector = t, this._univerInstanceService = s, this._findReplaceService = n;
20
20
  const i = this._findReplaceService.getProviders();
21
- this._model = this._injector.createInstance(g, this._state, i);
21
+ this._model = this._injector.createInstance(y, this._state, i);
22
22
  const r = {
23
- ...y(),
23
+ ...S(),
24
24
  ...e
25
25
  };
26
26
  this._state.changeState(r);
@@ -89,8 +89,8 @@ let l = class extends f {
89
89
  };
90
90
  l = C([
91
91
  o(1, m(_)),
92
- o(2, v),
93
- o(3, b)
92
+ o(2, f),
93
+ o(3, g)
94
94
  ], l);
95
95
  class R extends d {
96
96
  async createTextFinderAsync(e) {
package/lib/es/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  var fe = Object.defineProperty;
2
2
  var _e = (h, e, t) => e in h ? fe(h, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : h[e] = t;
3
3
  var f = (h, e, t) => _e(h, typeof e != "symbol" ? e + "" : e, t);
4
- import { CommandType as T, IUndoRedoService as me, ICommandService as A, Rectangle as Se, Inject as k, Injector as N, ThemeService as pe, Disposable as q, EDITOR_ACTIVATED as ve, UniverInstanceType as ee, fromCallback as W, ColorKit as Ie, rotate as j, groupBy as Ce, ObjectMatrix as Re, Tools as ke, replaceInDocumentBody as we, IContextService as te, IUniverInstanceService as ie, DependentOn as be, Plugin as Me, merge as xe, IConfigService as ye } from "@univerjs/core";
4
+ import { CommandType as T, IUndoRedoService as me, ICommandService as A, Rectangle as Se, Inject as k, Injector as N, IContextService as q, IUniverInstanceService as ee, ThemeService as pe, Disposable as te, EDITOR_ACTIVATED as ve, UniverInstanceType as ie, fromCallback as W, ColorKit as Ie, rotate as j, groupBy as Ce, ObjectMatrix as Re, Tools as ke, replaceInDocumentBody as we, DependentOn as be, IConfigService as Me, Plugin as xe, merge as ye } from "@univerjs/core";
5
5
  import { SetRangeValuesCommand as ne, SheetsSelectionsService as Ue, SelectRangeCommand as Pe, SetWorksheetActiveOperation as Be, SetSelectionsOperation as Fe, SetWorksheetActivateCommand as We, UniverSheetsPlugin as V } from "@univerjs/sheets";
6
- import { Shape as He, Rect as Te, RENDER_RAW_FORMULA_KEY as Ee, IRenderManagerService as se } from "@univerjs/engine-render";
7
- import { FindReplaceController as Oe, FindModel as Ae, FindBy as M, FindScope as R, FindDirection as b, IFindReplaceService as Ne, UniverFindReplacePlugin as De } from "@univerjs/find-replace";
6
+ import { Shape as He, Rect as Te, IRenderManagerService as se, RENDER_RAW_FORMULA_KEY as Ee } from "@univerjs/engine-render";
7
+ import { FindReplaceController as Oe, IFindReplaceService as Ae, FindModel as Ne, FindBy as M, FindScope as R, FindDirection as b, UniverFindReplacePlugin as De } from "@univerjs/find-replace";
8
8
  import { SheetSkeletonManagerService as $e, getCoordByCell as G, getSheetObject as Le, ScrollToCellCommand as je } from "@univerjs/sheets-ui";
9
9
  import { filter as x, Subject as Y, throttleTime as Ve, merge as Ge, skip as Ye, debounceTime as Ke } from "rxjs";
10
10
  const re = {
@@ -76,7 +76,7 @@ var qe = Object.getOwnPropertyDescriptor, D = (h, e, t, i) => {
76
76
  (s = h[r]) && (n = s(n) || n);
77
77
  return n;
78
78
  }, S = (h, e) => (t, i) => e(t, i, h);
79
- let y = class extends q {
79
+ let y = class extends te {
80
80
  constructor(e, t, i, n, r) {
81
81
  super();
82
82
  f(this, "_provider");
@@ -96,12 +96,12 @@ let y = class extends q {
96
96
  y = D([
97
97
  S(0, k(N)),
98
98
  S(1, k(Oe)),
99
- S(2, te),
100
- S(3, Ne),
99
+ S(2, q),
100
+ S(3, Ae),
101
101
  S(4, A)
102
102
  ], y);
103
103
  const et = "sheets-find-replace-provider", tt = 1e4;
104
- let E = class extends Ae {
104
+ let E = class extends Ne {
105
105
  constructor(e, t, i, n, r, s, o, c) {
106
106
  super();
107
107
  // We can directly inject the `FindReplaceService` here, and call its methods instead of using the observables.
@@ -524,17 +524,17 @@ let E = class extends Ae {
524
524
  }
525
525
  };
526
526
  E = D([
527
- S(2, ie),
527
+ S(2, ee),
528
528
  S(3, se),
529
529
  S(4, A),
530
- S(5, te),
530
+ S(5, q),
531
531
  S(6, k(pe)),
532
532
  S(7, k(Ue))
533
533
  ], E);
534
534
  function z(h) {
535
535
  return h.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
536
536
  }
537
- let O = class extends q {
537
+ let O = class extends te {
538
538
  constructor(e, t, i) {
539
539
  super();
540
540
  /**
@@ -545,7 +545,7 @@ let O = class extends q {
545
545
  }
546
546
  async find(e) {
547
547
  this._terminate();
548
- const t = this._univerInstanceService.getCurrentUnitOfType(ee.UNIVER_SHEET);
548
+ const t = this._univerInstanceService.getCurrentUnitOfType(ie.UNIVER_SHEET);
549
549
  if (!t) return [];
550
550
  const i = this._preprocessQuery(e), n = this._renderManagerService.getRenderById(t.getUnitId()).with($e), r = this._injector.createInstance(E, t, n);
551
551
  return this._findModelsByUnitId.set(t.getUnitId(), r), r.start(i), [r];
@@ -570,7 +570,7 @@ let O = class extends q {
570
570
  }
571
571
  };
572
572
  O = D([
573
- S(0, ie),
573
+ S(0, ee),
574
574
  S(1, se),
575
575
  S(2, k(N))
576
576
  ], O);
@@ -591,7 +591,7 @@ function nt(h) {
591
591
  function st(h) {
592
592
  return h.replace(/^ +/g, "").replace(/ +$/g, "");
593
593
  }
594
- const rt = "@univerjs/sheets-find-replace", ot = "0.16.1-insiders.20260311-074e8ca", oe = {
594
+ const rt = "@univerjs/sheets-find-replace", ot = "0.17.0", oe = {
595
595
  name: rt,
596
596
  version: ot
597
597
  }, ht = "sheets-find-replace.config", J = {};
@@ -600,10 +600,10 @@ var ct = Object.defineProperty, at = Object.getOwnPropertyDescriptor, lt = (h, e
600
600
  (s = h[r]) && (n = s(n) || n);
601
601
  return n;
602
602
  }, Z = (h, e) => (t, i) => e(t, i, h), U = (h, e, t) => lt(h, typeof e != "symbol" ? e + "" : e, t);
603
- let w = class extends Me {
603
+ let w = class extends xe {
604
604
  constructor(h = J, e, t) {
605
605
  super(), this._config = h, this._injector = e, this._configService = t;
606
- const { ...i } = xe(
606
+ const { ...i } = ye(
607
607
  {},
608
608
  J,
609
609
  this._config
@@ -620,11 +620,11 @@ let w = class extends Me {
620
620
  U(w, "pluginName", "SHEET_FIND_REPLACE_PLUGIN");
621
621
  U(w, "packageName", oe.name);
622
622
  U(w, "version", oe.version);
623
- U(w, "type", ee.UNIVER_SHEET);
623
+ U(w, "type", ie.UNIVER_SHEET);
624
624
  w = dt([
625
625
  be(V, V, De),
626
626
  Z(1, k(N)),
627
- Z(2, ye)
627
+ Z(2, Me)
628
628
  ], w);
629
629
  export {
630
630
  re as SheetReplaceCommand,
package/lib/facade.js CHANGED
@@ -1,8 +1,8 @@
1
1
  var u = Object.defineProperty;
2
2
  var p = (a, e, t) => e in a ? u(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t;
3
3
  var c = (a, e, t) => p(a, typeof e != "symbol" ? e + "" : e, t);
4
- import { Inject as m, Injector as _, Disposable as f, IUniverInstanceService as v } from "@univerjs/core";
5
- import { FindReplaceModel as g, createInitFindReplaceState as y, FindReplaceState as S, FindBy as h, IFindReplaceService as b } from "@univerjs/find-replace";
4
+ import { Inject as m, Injector as _, IUniverInstanceService as f, Disposable as v } from "@univerjs/core";
5
+ import { IFindReplaceService as g, FindReplaceModel as y, createInitFindReplaceState as S, FindReplaceState as b, FindBy as h } from "@univerjs/find-replace";
6
6
  import { FRange as F } from "@univerjs/sheets/facade";
7
7
  import { FUniver as d } from "@univerjs/core/facade";
8
8
  var w = Object.getOwnPropertyDescriptor, C = (a, e, t, s) => {
@@ -10,17 +10,17 @@ var w = Object.getOwnPropertyDescriptor, C = (a, e, t, s) => {
10
10
  (r = a[i]) && (n = r(n) || n);
11
11
  return n;
12
12
  }, o = (a, e) => (t, s) => e(t, s, a);
13
- let l = class extends f {
13
+ let l = class extends v {
14
14
  constructor(e, t, s, n) {
15
15
  super();
16
- c(this, "_state", new S());
16
+ c(this, "_state", new b());
17
17
  c(this, "_model");
18
18
  c(this, "_complete");
19
19
  this._injector = t, this._univerInstanceService = s, this._findReplaceService = n;
20
20
  const i = this._findReplaceService.getProviders();
21
- this._model = this._injector.createInstance(g, this._state, i);
21
+ this._model = this._injector.createInstance(y, this._state, i);
22
22
  const r = {
23
- ...y(),
23
+ ...S(),
24
24
  ...e
25
25
  };
26
26
  this._state.changeState(r);
@@ -89,8 +89,8 @@ let l = class extends f {
89
89
  };
90
90
  l = C([
91
91
  o(1, m(_)),
92
- o(2, v),
93
- o(3, b)
92
+ o(2, f),
93
+ o(3, g)
94
94
  ], l);
95
95
  class R extends d {
96
96
  async createTextFinderAsync(e) {
package/lib/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  var fe = Object.defineProperty;
2
2
  var _e = (h, e, t) => e in h ? fe(h, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : h[e] = t;
3
3
  var f = (h, e, t) => _e(h, typeof e != "symbol" ? e + "" : e, t);
4
- import { CommandType as T, IUndoRedoService as me, ICommandService as A, Rectangle as Se, Inject as k, Injector as N, ThemeService as pe, Disposable as q, EDITOR_ACTIVATED as ve, UniverInstanceType as ee, fromCallback as W, ColorKit as Ie, rotate as j, groupBy as Ce, ObjectMatrix as Re, Tools as ke, replaceInDocumentBody as we, IContextService as te, IUniverInstanceService as ie, DependentOn as be, Plugin as Me, merge as xe, IConfigService as ye } from "@univerjs/core";
4
+ import { CommandType as T, IUndoRedoService as me, ICommandService as A, Rectangle as Se, Inject as k, Injector as N, IContextService as q, IUniverInstanceService as ee, ThemeService as pe, Disposable as te, EDITOR_ACTIVATED as ve, UniverInstanceType as ie, fromCallback as W, ColorKit as Ie, rotate as j, groupBy as Ce, ObjectMatrix as Re, Tools as ke, replaceInDocumentBody as we, DependentOn as be, IConfigService as Me, Plugin as xe, merge as ye } from "@univerjs/core";
5
5
  import { SetRangeValuesCommand as ne, SheetsSelectionsService as Ue, SelectRangeCommand as Pe, SetWorksheetActiveOperation as Be, SetSelectionsOperation as Fe, SetWorksheetActivateCommand as We, UniverSheetsPlugin as V } from "@univerjs/sheets";
6
- import { Shape as He, Rect as Te, RENDER_RAW_FORMULA_KEY as Ee, IRenderManagerService as se } from "@univerjs/engine-render";
7
- import { FindReplaceController as Oe, FindModel as Ae, FindBy as M, FindScope as R, FindDirection as b, IFindReplaceService as Ne, UniverFindReplacePlugin as De } from "@univerjs/find-replace";
6
+ import { Shape as He, Rect as Te, IRenderManagerService as se, RENDER_RAW_FORMULA_KEY as Ee } from "@univerjs/engine-render";
7
+ import { FindReplaceController as Oe, IFindReplaceService as Ae, FindModel as Ne, FindBy as M, FindScope as R, FindDirection as b, UniverFindReplacePlugin as De } from "@univerjs/find-replace";
8
8
  import { SheetSkeletonManagerService as $e, getCoordByCell as G, getSheetObject as Le, ScrollToCellCommand as je } from "@univerjs/sheets-ui";
9
9
  import { filter as x, Subject as Y, throttleTime as Ve, merge as Ge, skip as Ye, debounceTime as Ke } from "rxjs";
10
10
  const re = {
@@ -76,7 +76,7 @@ var qe = Object.getOwnPropertyDescriptor, D = (h, e, t, i) => {
76
76
  (s = h[r]) && (n = s(n) || n);
77
77
  return n;
78
78
  }, S = (h, e) => (t, i) => e(t, i, h);
79
- let y = class extends q {
79
+ let y = class extends te {
80
80
  constructor(e, t, i, n, r) {
81
81
  super();
82
82
  f(this, "_provider");
@@ -96,12 +96,12 @@ let y = class extends q {
96
96
  y = D([
97
97
  S(0, k(N)),
98
98
  S(1, k(Oe)),
99
- S(2, te),
100
- S(3, Ne),
99
+ S(2, q),
100
+ S(3, Ae),
101
101
  S(4, A)
102
102
  ], y);
103
103
  const et = "sheets-find-replace-provider", tt = 1e4;
104
- let E = class extends Ae {
104
+ let E = class extends Ne {
105
105
  constructor(e, t, i, n, r, s, o, c) {
106
106
  super();
107
107
  // We can directly inject the `FindReplaceService` here, and call its methods instead of using the observables.
@@ -524,17 +524,17 @@ let E = class extends Ae {
524
524
  }
525
525
  };
526
526
  E = D([
527
- S(2, ie),
527
+ S(2, ee),
528
528
  S(3, se),
529
529
  S(4, A),
530
- S(5, te),
530
+ S(5, q),
531
531
  S(6, k(pe)),
532
532
  S(7, k(Ue))
533
533
  ], E);
534
534
  function z(h) {
535
535
  return h.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
536
536
  }
537
- let O = class extends q {
537
+ let O = class extends te {
538
538
  constructor(e, t, i) {
539
539
  super();
540
540
  /**
@@ -545,7 +545,7 @@ let O = class extends q {
545
545
  }
546
546
  async find(e) {
547
547
  this._terminate();
548
- const t = this._univerInstanceService.getCurrentUnitOfType(ee.UNIVER_SHEET);
548
+ const t = this._univerInstanceService.getCurrentUnitOfType(ie.UNIVER_SHEET);
549
549
  if (!t) return [];
550
550
  const i = this._preprocessQuery(e), n = this._renderManagerService.getRenderById(t.getUnitId()).with($e), r = this._injector.createInstance(E, t, n);
551
551
  return this._findModelsByUnitId.set(t.getUnitId(), r), r.start(i), [r];
@@ -570,7 +570,7 @@ let O = class extends q {
570
570
  }
571
571
  };
572
572
  O = D([
573
- S(0, ie),
573
+ S(0, ee),
574
574
  S(1, se),
575
575
  S(2, k(N))
576
576
  ], O);
@@ -591,7 +591,7 @@ function nt(h) {
591
591
  function st(h) {
592
592
  return h.replace(/^ +/g, "").replace(/ +$/g, "");
593
593
  }
594
- const rt = "@univerjs/sheets-find-replace", ot = "0.16.1-insiders.20260311-074e8ca", oe = {
594
+ const rt = "@univerjs/sheets-find-replace", ot = "0.17.0", oe = {
595
595
  name: rt,
596
596
  version: ot
597
597
  }, ht = "sheets-find-replace.config", J = {};
@@ -600,10 +600,10 @@ var ct = Object.defineProperty, at = Object.getOwnPropertyDescriptor, lt = (h, e
600
600
  (s = h[r]) && (n = s(n) || n);
601
601
  return n;
602
602
  }, Z = (h, e) => (t, i) => e(t, i, h), U = (h, e, t) => lt(h, typeof e != "symbol" ? e + "" : e, t);
603
- let w = class extends Me {
603
+ let w = class extends xe {
604
604
  constructor(h = J, e, t) {
605
605
  super(), this._config = h, this._injector = e, this._configService = t;
606
- const { ...i } = xe(
606
+ const { ...i } = ye(
607
607
  {},
608
608
  J,
609
609
  this._config
@@ -620,11 +620,11 @@ let w = class extends Me {
620
620
  U(w, "pluginName", "SHEET_FIND_REPLACE_PLUGIN");
621
621
  U(w, "packageName", oe.name);
622
622
  U(w, "version", oe.version);
623
- U(w, "type", ee.UNIVER_SHEET);
623
+ U(w, "type", ie.UNIVER_SHEET);
624
624
  w = dt([
625
625
  be(V, V, De),
626
626
  Z(1, k(N)),
627
- Z(2, ye)
627
+ Z(2, Me)
628
628
  ], w);
629
629
  export {
630
630
  re as SheetReplaceCommand,
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(f,a){typeof exports=="object"&&typeof module<"u"?a(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"],a):(f=typeof globalThis<"u"?globalThis:f||self,a(f.UniverSheetsFindReplace={},f.UniverCore,f.UniverSheets,f.UniverEngineRender,f.UniverFindReplace,f.UniverSheetsUi,f.rxjs))})(this,(function(f,a,p,y,S,F,k){"use strict";var Se=Object.defineProperty;var me=(f,a,p)=>a in f?Se(f,a,{enumerable:!0,configurable:!0,writable:!0,value:p}):f[a]=p;var m=(f,a,p)=>me(f,typeof a!="symbol"?a+"":a,p);const P={id:"sheet.command.replace",type:a.CommandType.COMMAND,handler:async(h,e)=>{const t=h.get(a.IUndoRedoService),i=h.get(a.ICommandService),{unitId:n,replacements:r}=e,s=t.__tempBatchingUndoRedo(n),o=await Promise.all(r.map(c=>i.executeCommand(p.SetRangeValuesCommand.id,{unitId:n,subUnitId:c.subUnitId,value:c.value})));return s.dispose(),q(o,r)}};function q(h,e){let t=0,i=0;return h.forEach((n,r)=>{const s=e[r].count;n?t+=s:i+=s}),{success:t,failure:i}}class K extends y.Shape{constructor(t,i){super(t,i);m(this,"_activated",!1);m(this,"_inHiddenRange",!1);m(this,"_color");i&&this.setShapeProps(i)}setShapeProps(t){this._activated=!!t.activated,typeof t.inHiddenRange<"u"&&(this._inHiddenRange=t.inHiddenRange),typeof t.color<"u"&&(this._color=t.color),this.transformByState({width:t.width,height:t.height})}_draw(t){const i=this._activated,n=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 0.35)`,r=`rgb(${this._color.r}, ${this._color.g}, ${this._color.b})`;y.Rect.drawWith(t,{width:this.width,height:this.height,fill:n,stroke:i?r:void 0,strokeWidth:i?2:0,evented:!1})}}function A(h,e){return h.startRow===e.startRow&&h.startColumn===e.startColumn}function D(h,e){return h.startRow<e.startRow||h.startRow===e.startRow&&h.startColumn<=e.startColumn}function N(h,e){return h.startColumn<e.startColumn||h.startColumn===e.startColumn&&h.startRow<=e.startRow}function Q(h,e){return h.startRow>e.startRow||h.startRow===e.startRow&&h.startColumn>=e.startColumn}function X(h,e){return h.startColumn>e.startColumn||h.startColumn===e.startColumn&&h.startRow>=e.startRow}function z(h,e){const{range:t}=h,{startRow:i,startColumn:n}=t,r=e.getMergedCell(i,n);return r?a.Rectangle.equals(t,r):t.endRow===t.startRow&&t.endColumn===t.startColumn}var J=Object.getOwnPropertyDescriptor,x=(h,e,t,i)=>{for(var n=i>1?void 0:i?J(e,t):e,r=h.length-1,s;r>=0;r--)(s=h[r])&&(n=s(n)||n);return n},C=(h,e)=>(t,i)=>e(t,i,h);f.SheetsFindReplaceController=class extends a.Disposable{constructor(t,i,n,r,s){super();m(this,"_provider");this._injector=t,this._findReplaceController=i,this._contextService=n,this._findReplaceService=r,this._commandService=s,this._init(),this._initCommands()}dispose(){super.dispose(),this._findReplaceController.closePanel(),this._provider.dispose()}_init(){const t=this._injector.createInstance(W);this._provider=t,this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(t)),this.disposeWithMe(this._contextService.subscribeContextValue$(a.EDITOR_ACTIVATED).pipe(k.filter(i=>!!i)).subscribe(()=>this._findReplaceController.closePanel()))}_initCommands(){[P].forEach(t=>this.disposeWithMe(this._commandService.registerCommand(t)))}},f.SheetsFindReplaceController=x([C(0,a.Inject(a.Injector)),C(1,a.Inject(S.FindReplaceController)),C(2,a.IContextService),C(3,S.IFindReplaceService),C(4,a.ICommandService)],f.SheetsFindReplaceController);const Z="sheets-find-replace-provider",ee=1e4;let B=class extends S.FindModel{constructor(e,t,i,n,r,s,o,c){super();m(this,"_matchesUpdate$",new k.Subject);m(this,"matchesUpdate$",this._matchesUpdate$.asObservable());m(this,"_activelyChangingMatch$",new k.Subject);m(this,"activelyChangingMatch$",this._activelyChangingMatch$.asObservable());m(this,"_matchesByWorksheet",new Map);m(this,"_matches",[]);m(this,"_matchesPosition",0);m(this,"_activeHighlightIndex",-1);m(this,"_highlightShapes",[]);m(this,"_currentHighlightShape",null);m(this,"_query",null);m(this,"_workbookSelections");this._workbook=e,this._sheetSkeletonManagerService=t,this._univerInstanceService=i,this._renderManagerService=n,this._commandService=r,this._contextService=s,this._themeService=o,this._workbookSelections=c.getWorkbookSelections(this.unitId)}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}dispose(){super.dispose(),this._disposeHighlights(),this._toggleDisplayRawFormula(!1)}getMatches(){return this._matches}start(e){switch(this._query=e,e.findBy===S.FindBy.FORMULA?this._toggleDisplayRawFormula(!0):this._toggleDisplayRawFormula(!1),e.findScope){case S.FindScope.UNIT:this.findInWorkbook(e);break;case S.FindScope.SUBUNIT:default:this.findInActiveWorksheet(e);break}}focusSelection(){const e=this.currentMatch;e&&this._commandService.executeCommand(p.SelectRangeCommand.id,{unitId:e.unitId,subUnit:e.range.subUnitId,range:e.range.range})}_toggleDisplayRawFormula(e){this._contextService.setContextValue(y.RENDER_RAW_FORMULA_KEY,e)}findInWorkbook(e){const t=this._workbook.getUnitId();let i,n=!0;const r=()=>{const s=this._workbook.getSheets().filter(o=>!o.isSheetHidden()).map(o=>{const c=this._findInWorksheet(o,e,t),d=o.getSheetId(),{results:l}=c;return l.length?this._matchesByWorksheet.set(d,c.results):this._matchesByWorksheet.delete(d),c});this._matches=s.map(o=>o.results).flat(),this._updateFindHighlight(),n?(i={results:this._matches},n=!1):this._matchesUpdate$.next(this._matches)};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>{this._updateFindHighlight(),this._updateCurrentHighlightShape(this._activeHighlightIndex)})),this.disposeWithMe(a.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(k.filter(([s,o])=>s.id===p.SetWorksheetActiveOperation.id&&!(o!=null&&o.fromFindReplace))).subscribe(()=>{const s=this._workbook.getActiveSheet();if(!s)return;const o=s.getSheetId();this._matchesByWorksheet.has(o)&&this._findNextMatchOnActiveSheetChange(s)})),this.disposeWithMe(a.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(k.filter(([s])=>s.type===a.CommandType.MUTATION&&s.params.unitId===this._workbook.getUnitId()),k.throttleTime(600,void 0,{leading:!1,trailing:!0})).subscribe(()=>r())),r(),i}_findNextMatchOnActiveSheetChange(e){let t,i,n=0;const r=this._matchesByWorksheet.get(e.getSheetId()),s=this._workbookSelections.getCurrentSelections();s!=null&&s.length?([t,n]=this._findNextMatchByRange(r,s[0].range),i=r.findIndex(o=>o===t)):(t=r[0],i=0,n=this._matches.findIndex(o=>o===t)),this._matchesPosition=n+1,this._activelyChangingMatch$.next(t),this._activeHighlightIndex=i,this._updateFindHighlight(),this._updateCurrentHighlightShape(i)}findInActiveWorksheet(e){const t=this._workbook.getUnitId(),i=()=>{var u;const c=this._workbook.getActiveSheet();if(!c)return!1;const d=this._workbookSelections.getCurrentSelections();return(u=d==null?void 0:d.some(g=>!z(g,c)))!=null?u:!1};let n,r=!0,s=!1;const o=()=>{const c=this._workbook.getActiveSheet();if(!c)return{results:[]};const d=this.currentMatch;s=i();const l=this._workbookSelections.getCurrentSelections(),u=s?this._findInSelections(c,l,e,t):this._findInWorksheet(c,e,t);return this._matches=u.results,this._matchesPosition=this._tryRestoreLastMatchesPosition(d,this._matches),r?(n=u,r=!1):this._matchesUpdate$.next(this._matches),this._updateFindHighlight(),u};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>this._updateFindHighlight())),this.disposeWithMe(k.merge(a.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(k.filter(([c])=>{if(c.type===a.CommandType.MUTATION&&c.params.unitId===this._workbook.getUnitId())return!0;if(c.id===p.SetSelectionsOperation.id&&c.params.unitId===t){const d=i();return d===!1&&s===!1?!1:(s=d,!0)}return!1})),this._workbook.activeSheet$.pipe(k.skip(1))).pipe(k.debounceTime(200)).subscribe(()=>o())),o(),n}_findInRange(e,t,i,n,r){const s=[],o=e.getSheetId(),c=(t.findDirection===S.FindDirection.COLUMN?e.iterateByColumn:e.iterateByRow).bind(e)(i);for(const d of c){const{row:l,col:u,colSpan:g,rowSpan:v,value:I}=d;if(r!=null&&r(l,u)||!I||e.getRowFiltered(l))continue;const{hit:w,replaceable:M,isFormula:R}=te(e,l,u,t,I);if(w){const H={provider:Z,unitId:n,replaceable:M,isFormula:R,range:{subUnitId:o,range:{startRow:l,startColumn:u,endColumn:u+(g!=null?g:1)-1,endRow:l+(v!=null?v:1)-1}}};s.push(H)}}return{results:s}}_findInSelections(e,t,i,n){const{findDirection:r}=i,s=r===S.FindDirection.ROW?D:N,o=new Set;return{results:t.map(d=>this._findInRange(e,i,d.range,n,(l,u)=>{const g=`${l}-${u}`;return o.has(g)?!0:(o.add(g),!1)}).results).flat().sort((d,l)=>s(d.range.range,l.range.range)?-1:1)}}_findInWorksheet(e,t,i){const n=e.getRowCount(),r=e.getColumnCount(),s={startRow:0,startColumn:0,endRow:n-1,endColumn:r-1};return this._findInRange(e,t,s,i)}_disposeHighlights(){var e;this._highlightShapes.forEach(t=>{var i;(i=t.getScene())==null||i.makeDirty(),t.dispose()}),this._highlightShapes=[],(e=this._currentHighlightShape)==null||e.dispose(),this._currentHighlightShape=null}_updateFindHighlight(){var u;this._disposeHighlights();const e=(u=this._sheetSkeletonManagerService.getCurrent())==null?void 0:u.skeleton;if(!e)return;const t=this._workbook.getUnitId(),i=this._renderManagerService.getRenderById(t);if(i==null)return;const{scene:n}=i,r=this._matches,s=this._themeService.getColorFromTheme("yellow.400"),o=new a.ColorKit(s).toRgb(),c=this._workbook.getActiveSheet();if(!c)return;const d=c.getSheetId(),l=r.filter(g=>g.range.subUnitId===d).map((g,v)=>{const{startColumn:I,startRow:w,endColumn:M,endRow:R}=g.range.range,H=F.getCoordByCell(w,I,n,e),ae=F.getCoordByCell(R,M,n,e),{startX:G,startY:Y}=H,{endX:le,endY:de}=ae;let E=!0;for(let b=w;b<=R;b++)if(c.getRowRawVisible(b)){E=!1;break}let O=!0;for(let b=I;b<=M;b++)if(c.getColVisible(b)){O=!1;break}const ue=E||O,ge=O?2:le-G,fe=E?2:de-Y,_e={left:G,top:Y,color:o,width:ge,height:fe,evented:!1,inHiddenRange:ue,zIndex:ee};return new K(`find-highlight-${v}`,_e)});n.addObjects(l),this._highlightShapes=l,n.makeDirty()}_updateCurrentHighlightShape(e){var t;if((t=this._currentHighlightShape)==null||t.setShapeProps({activated:!1}),this._currentHighlightShape=null,e!==void 0){const i=this._highlightShapes[e];if(!i)return;this._currentHighlightShape=i,i.setShapeProps({activated:!0})}}_getSheetObject(){return F.getSheetObject(this._univerInstanceService,this._renderManagerService)}_focusMatch(e){var i;const t=e.range.subUnitId;t!==((i=this._workbook.getActiveSheet())==null?void 0:i.getSheetId())&&this._commandService.executeCommand(p.SetWorksheetActivateCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:t},{fromFindReplace:!0}),this._commandService.executeCommand(F.ScrollToCellCommand.id,{range:e.range.range},{fromFindReplace:!0})}_tryRestoreLastMatchesPosition(e,t){if(!e)return 0;const{subUnitId:i}=e.range,{startColumn:n,startRow:r}=e.range.range,s=t.findIndex(o=>{if(i!==o.range.subUnitId)return!1;const{startColumn:c,startRow:d}=o.range.range;return c===n&&d===r});return s>-1?s+1:0}moveToNextMatch(e){var o,c,d,l,u;if(!this._matches.length)return null;const t=(o=e==null?void 0:e.loop)!=null?o:!1,i=(c=e==null?void 0:e.stayIfOnMatch)!=null?c:!1,n=(d=e==null?void 0:e.noFocus)!=null?d:!1,r=(l=e==null?void 0:e.ignoreSelection)!=null?l:!1,s=this._findNextMatch(t,i,r);if(s){const[g,v]=s;return this._matchesPosition=v+1,this._query.findScope===S.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(g.range.subUnitId).findIndex(I=>I===g):this._activeHighlightIndex=v,n||this._focusMatch(g),((u=this._workbook.getActiveSheet())==null?void 0:u.getSheetId())===g.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),g}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}moveToPreviousMatch(e){var o,c,d,l,u;if(!this._matches.length)return null;const t=(o=e==null?void 0:e.loop)!=null?o:!1,i=(c=e==null?void 0:e.stayIfOnMatch)!=null?c:!1,n=(d=e==null?void 0:e.noFocus)!=null?d:!1,r=(l=e==null?void 0:e.ignoreSelection)!=null?l:!1,s=this._findPreviousMatch(t,i,r);if(s){const[g,v]=s;return this._matchesPosition=v+1,this._query.findScope===S.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(g.range.subUnitId).findIndex(I=>I===g):this._activeHighlightIndex=v,n||this._focusMatch(g),((u=this._workbook.getActiveSheet())==null?void 0:u.getSheetId())===g.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),g}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}_findPreviousMatch(e=!1,t=!1,i=!1){var o;if(this.currentMatch){const c=this._matches.findIndex(g=>g===this.currentMatch);if(t)return[this.currentMatch,c];const d=c-1;if(!e&&d<0)return null;const l=this._matches.length,u=(d+l)%l;return[this._matches[u],u]}const n=this._workbookSelections.getCurrentLastSelection();if(i||!n){const c=this._matches.length-1;return[this._matches[c],c]}if(this._query.findScope!==S.FindScope.UNIT)return this._findPreviousMatchByRange(this._matches,n.range);const r=(o=this._workbook.getActiveSheet())==null?void 0:o.getSheetId();if(!r)return null;const s=this._findPreviousWorksheetThatHasAMatch(r,e);return s?this._findPreviousMatchByRange(this._matchesByWorksheet.get(s),n.range):null}_findNextMatch(e=!1,t=!1,i=!1){var o;if(this.currentMatch){const c=this._matches.findIndex(g=>g===this.currentMatch);if(t)return[this.currentMatch,c];const d=c+1,l=this._matches.length;if(!e&&d>=l)return null;const u=d%l;return[this._matches[u],u]}const n=this._workbookSelections.getCurrentLastSelection();if(i||!n)return[this._matches[0],0];if(this._query.findScope!==S.FindScope.UNIT)return this._findNextMatchByRange(this._matches,n.range,t);const r=(o=this._workbook.getActiveSheet())==null?void 0:o.getSheetId();if(!r)return null;const s=this._findNextWorksheetThatHasAMatch(r,e);return s?this._findNextMatchByRange(this._matchesByWorksheet.get(s),n.range):null}_findPreviousWorksheetThatHasAMatch(e,t=!1){const i=this._workbook.getSheetOrders(),n=i.findIndex(o=>o===e),s=(t?a.rotate(i,n+1):i.slice(0,n+1)).findLast(o=>this._matchesByWorksheet.has(o));return s!=null?s:null}_findNextWorksheetThatHasAMatch(e,t=!1){const i=this._workbook.getSheetOrders(),n=i.findIndex(o=>o===e),s=(t?a.rotate(i,n):i.slice(n)).find(o=>this._matchesByWorksheet.has(o));return s!=null?s:null}_findNextMatchByRange(e,t,i=!1){const n=this._query.findDirection===S.FindDirection.ROW;let r=e.findIndex(o=>{const c=o.range.range;if(!(n?D(t,c):N(t,c)))return!1;const l=A(t,c);return i?l:!l});r===-1&&(r=e.length-1);const s=e[r];return[s,this._matches.findIndex(o=>o===s)]}_findPreviousMatchByRange(e,t,i=!1){const n=this._query.findDirection===S.FindDirection.ROW;let r=this._matches.findLastIndex(o=>{const c=o.range.range;if(!(n?Q(t,c):X(t,c)))return!1;const l=A(t,c);return i?l:!l});r===-1&&(r=0);const s=e[r];return[s,this._matches.findIndex(o=>o===s)]}async replace(e){if(this._matchesCount===0||!this.currentMatch||!this._query||!this.currentMatch.replaceable)return!1;const t=this.currentMatch.range,i=this._workbook.getSheetBySheetId(this.currentMatch.range.subUnitId),n=this._getReplacedCellData(this.currentMatch,i,this._query.findBy===S.FindBy.FORMULA,this._query.findString,e,this._query.caseSensitive?"g":"ig"),r={unitId:this.currentMatch.unitId,subUnitId:t.subUnitId,value:{[t.range.startRow]:{[t.range.startColumn]:n}}};return this._commandService.executeCommand(p.SetRangeValuesCommand.id,r)}async replaceAll(e){if(this._matchesCount===0||!this._query)return{success:0,failure:0};const t=this._workbook.getUnitId(),{findString:i,caseSensitive:n,findBy:r}=this._query,s=r===S.FindBy.FORMULA,o=n?"g":"ig",c=[];return a.groupBy(this._matches.filter(l=>l.replaceable),l=>l.range.subUnitId).forEach((l,u)=>{const g=new a.ObjectMatrix,v=this._workbook.getSheetBySheetId(u);l.forEach(I=>{const{startColumn:w,startRow:M}=I.range.range,R=this._getReplacedCellData(I,v,s,i,e,o);R&&g.setValue(M,w,R)}),c.push({count:l.length,subUnitId:u,value:g.getMatrix()})}),c?this._commandService.executeCommand(P.id,{unitId:t,replacements:c}):{success:0,failure:0}}_getReplacedCellData(e,t,i,n,r,s){var v;const o=e.range.range,{startRow:c,startColumn:d}=o,l=t.getCellRaw(c,d);if(e.isFormula)return i?{f:l.f.replace(new RegExp(j(n),s),r),v:null}:null;if(!!((v=l.p)!=null&&v.body)){const I=a.Tools.deepClone(l.p);return a.replaceInDocumentBody(I.body,n,r,this._query.caseSensitive),{p:I}}return{v:l.v.toString().replace(new RegExp(j(n),s),r)}}};B=x([C(2,a.IUniverInstanceService),C(3,y.IRenderManagerService),C(4,a.ICommandService),C(5,a.IContextService),C(6,a.Inject(a.ThemeService)),C(7,a.Inject(p.SheetsSelectionsService))],B);function j(h){return h.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}let W=class extends a.Disposable{constructor(e,t,i){super();m(this,"_findModelsByUnitId",new Map);this._univerInstanceService=e,this._renderManagerService=t,this._injector=i}async find(e){this._terminate();const t=this._univerInstanceService.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET);if(!t)return[];const i=this._preprocessQuery(e),n=this._renderManagerService.getRenderById(t.getUnitId()).with(F.SheetSkeletonManagerService),r=this._injector.createInstance(B,t,n);return this._findModelsByUnitId.set(t.getUnitId(),r),r.start(i),[r]}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([C(0,a.IUniverInstanceService),C(1,y.IRenderManagerService),C(2,a.Inject(a.Injector))],W);const _={hit:!1,replaceable:!1,isFormula:!1,rawData:null};function te(h,e,t,i,n){const{findBy:r}=i,s=r===S.FindBy.FORMULA,o=h.getCellRaw(e,t);return _.rawData=o,!(o!=null&&o.f)?(_.isFormula=!1,T(n,i)?o?(_.hit=!0,_.replaceable=!0):(_.hit=!0,_.replaceable=!1):(_.hit=!1,_.replaceable=!1),_):(_.isFormula=!0,s?T({v:o.f},i)?(_.hit=!0,_.replaceable=!0,_):(_.hit=!1,_.replaceable=!1,_):(_.replaceable=!1,T(n,i)?_.hit=!0:_.hit=!1,_))}function T(h,e){let t=ie(h);return t?e.matchesTheWholeCell?(t=ne(t),e.caseSensitive?t===e.findString:t.toLowerCase()===e.findString):e.caseSensitive?t.indexOf(e.findString)>-1:t.toLowerCase().indexOf(e.findString)>-1:!1}function ie(h){var t,i,n;const e=(n=(i=(t=h==null?void 0:h.p)==null?void 0:t.body)==null?void 0:i.dataStream)!=null?n:h==null?void 0:h.v;return typeof e=="number"?`${e}`:typeof e=="boolean"?e?"1":"0":e}function ne(h){return h.replace(/^ +/g,"").replace(/ +$/g,"")}const $={name:"@univerjs/sheets-find-replace",version:"0.16.1-insiders.20260311-074e8ca"},se="sheets-find-replace.config",L={};var re=Object.defineProperty,oe=Object.getOwnPropertyDescriptor,he=(h,e,t)=>e in h?re(h,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):h[e]=t,ce=(h,e,t,i)=>{for(var n=i>1?void 0:i?oe(e,t):e,r=h.length-1,s;r>=0;r--)(s=h[r])&&(n=s(n)||n);return n},V=(h,e)=>(t,i)=>e(t,i,h),U=(h,e,t)=>he(h,typeof e!="symbol"?e+"":e,t);f.UniverSheetsFindReplacePlugin=class extends a.Plugin{constructor(e=L,t,i){super(),this._config=e,this._injector=t,this._configService=i;const{...n}=a.merge({},L,this._config);this._configService.setConfig(se,n)}onStarting(){[[f.SheetsFindReplaceController]].forEach(e=>this._injector.add(e))}onSteady(){this._injector.get(f.SheetsFindReplaceController)}},U(f.UniverSheetsFindReplacePlugin,"pluginName","SHEET_FIND_REPLACE_PLUGIN"),U(f.UniverSheetsFindReplacePlugin,"packageName",$.name),U(f.UniverSheetsFindReplacePlugin,"version",$.version),U(f.UniverSheetsFindReplacePlugin,"type",a.UniverInstanceType.UNIVER_SHEET),f.UniverSheetsFindReplacePlugin=ce([a.DependentOn(p.UniverSheetsPlugin,p.UniverSheetsPlugin,S.UniverFindReplacePlugin),V(1,a.Inject(a.Injector)),V(2,a.IConfigService)],f.UniverSheetsFindReplacePlugin),f.SheetReplaceCommand=P,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(f,a){typeof exports=="object"&&typeof module<"u"?a(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"],a):(f=typeof globalThis<"u"?globalThis:f||self,a(f.UniverSheetsFindReplace={},f.UniverCore,f.UniverSheets,f.UniverEngineRender,f.UniverFindReplace,f.UniverSheetsUi,f.rxjs))})(this,(function(f,a,p,y,S,F,k){"use strict";var Se=Object.defineProperty;var me=(f,a,p)=>a in f?Se(f,a,{enumerable:!0,configurable:!0,writable:!0,value:p}):f[a]=p;var m=(f,a,p)=>me(f,typeof a!="symbol"?a+"":a,p);const P={id:"sheet.command.replace",type:a.CommandType.COMMAND,handler:async(h,e)=>{const t=h.get(a.IUndoRedoService),i=h.get(a.ICommandService),{unitId:n,replacements:r}=e,s=t.__tempBatchingUndoRedo(n),o=await Promise.all(r.map(c=>i.executeCommand(p.SetRangeValuesCommand.id,{unitId:n,subUnitId:c.subUnitId,value:c.value})));return s.dispose(),q(o,r)}};function q(h,e){let t=0,i=0;return h.forEach((n,r)=>{const s=e[r].count;n?t+=s:i+=s}),{success:t,failure:i}}class K extends y.Shape{constructor(t,i){super(t,i);m(this,"_activated",!1);m(this,"_inHiddenRange",!1);m(this,"_color");i&&this.setShapeProps(i)}setShapeProps(t){this._activated=!!t.activated,typeof t.inHiddenRange<"u"&&(this._inHiddenRange=t.inHiddenRange),typeof t.color<"u"&&(this._color=t.color),this.transformByState({width:t.width,height:t.height})}_draw(t){const i=this._activated,n=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 0.35)`,r=`rgb(${this._color.r}, ${this._color.g}, ${this._color.b})`;y.Rect.drawWith(t,{width:this.width,height:this.height,fill:n,stroke:i?r:void 0,strokeWidth:i?2:0,evented:!1})}}function A(h,e){return h.startRow===e.startRow&&h.startColumn===e.startColumn}function D(h,e){return h.startRow<e.startRow||h.startRow===e.startRow&&h.startColumn<=e.startColumn}function N(h,e){return h.startColumn<e.startColumn||h.startColumn===e.startColumn&&h.startRow<=e.startRow}function Q(h,e){return h.startRow>e.startRow||h.startRow===e.startRow&&h.startColumn>=e.startColumn}function X(h,e){return h.startColumn>e.startColumn||h.startColumn===e.startColumn&&h.startRow>=e.startRow}function z(h,e){const{range:t}=h,{startRow:i,startColumn:n}=t,r=e.getMergedCell(i,n);return r?a.Rectangle.equals(t,r):t.endRow===t.startRow&&t.endColumn===t.startColumn}var J=Object.getOwnPropertyDescriptor,x=(h,e,t,i)=>{for(var n=i>1?void 0:i?J(e,t):e,r=h.length-1,s;r>=0;r--)(s=h[r])&&(n=s(n)||n);return n},C=(h,e)=>(t,i)=>e(t,i,h);f.SheetsFindReplaceController=class extends a.Disposable{constructor(t,i,n,r,s){super();m(this,"_provider");this._injector=t,this._findReplaceController=i,this._contextService=n,this._findReplaceService=r,this._commandService=s,this._init(),this._initCommands()}dispose(){super.dispose(),this._findReplaceController.closePanel(),this._provider.dispose()}_init(){const t=this._injector.createInstance(W);this._provider=t,this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(t)),this.disposeWithMe(this._contextService.subscribeContextValue$(a.EDITOR_ACTIVATED).pipe(k.filter(i=>!!i)).subscribe(()=>this._findReplaceController.closePanel()))}_initCommands(){[P].forEach(t=>this.disposeWithMe(this._commandService.registerCommand(t)))}},f.SheetsFindReplaceController=x([C(0,a.Inject(a.Injector)),C(1,a.Inject(S.FindReplaceController)),C(2,a.IContextService),C(3,S.IFindReplaceService),C(4,a.ICommandService)],f.SheetsFindReplaceController);const Z="sheets-find-replace-provider",ee=1e4;let B=class extends S.FindModel{constructor(e,t,i,n,r,s,o,c){super();m(this,"_matchesUpdate$",new k.Subject);m(this,"matchesUpdate$",this._matchesUpdate$.asObservable());m(this,"_activelyChangingMatch$",new k.Subject);m(this,"activelyChangingMatch$",this._activelyChangingMatch$.asObservable());m(this,"_matchesByWorksheet",new Map);m(this,"_matches",[]);m(this,"_matchesPosition",0);m(this,"_activeHighlightIndex",-1);m(this,"_highlightShapes",[]);m(this,"_currentHighlightShape",null);m(this,"_query",null);m(this,"_workbookSelections");this._workbook=e,this._sheetSkeletonManagerService=t,this._univerInstanceService=i,this._renderManagerService=n,this._commandService=r,this._contextService=s,this._themeService=o,this._workbookSelections=c.getWorkbookSelections(this.unitId)}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}dispose(){super.dispose(),this._disposeHighlights(),this._toggleDisplayRawFormula(!1)}getMatches(){return this._matches}start(e){switch(this._query=e,e.findBy===S.FindBy.FORMULA?this._toggleDisplayRawFormula(!0):this._toggleDisplayRawFormula(!1),e.findScope){case S.FindScope.UNIT:this.findInWorkbook(e);break;case S.FindScope.SUBUNIT:default:this.findInActiveWorksheet(e);break}}focusSelection(){const e=this.currentMatch;e&&this._commandService.executeCommand(p.SelectRangeCommand.id,{unitId:e.unitId,subUnit:e.range.subUnitId,range:e.range.range})}_toggleDisplayRawFormula(e){this._contextService.setContextValue(y.RENDER_RAW_FORMULA_KEY,e)}findInWorkbook(e){const t=this._workbook.getUnitId();let i,n=!0;const r=()=>{const s=this._workbook.getSheets().filter(o=>!o.isSheetHidden()).map(o=>{const c=this._findInWorksheet(o,e,t),d=o.getSheetId(),{results:l}=c;return l.length?this._matchesByWorksheet.set(d,c.results):this._matchesByWorksheet.delete(d),c});this._matches=s.map(o=>o.results).flat(),this._updateFindHighlight(),n?(i={results:this._matches},n=!1):this._matchesUpdate$.next(this._matches)};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>{this._updateFindHighlight(),this._updateCurrentHighlightShape(this._activeHighlightIndex)})),this.disposeWithMe(a.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(k.filter(([s,o])=>s.id===p.SetWorksheetActiveOperation.id&&!(o!=null&&o.fromFindReplace))).subscribe(()=>{const s=this._workbook.getActiveSheet();if(!s)return;const o=s.getSheetId();this._matchesByWorksheet.has(o)&&this._findNextMatchOnActiveSheetChange(s)})),this.disposeWithMe(a.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(k.filter(([s])=>s.type===a.CommandType.MUTATION&&s.params.unitId===this._workbook.getUnitId()),k.throttleTime(600,void 0,{leading:!1,trailing:!0})).subscribe(()=>r())),r(),i}_findNextMatchOnActiveSheetChange(e){let t,i,n=0;const r=this._matchesByWorksheet.get(e.getSheetId()),s=this._workbookSelections.getCurrentSelections();s!=null&&s.length?([t,n]=this._findNextMatchByRange(r,s[0].range),i=r.findIndex(o=>o===t)):(t=r[0],i=0,n=this._matches.findIndex(o=>o===t)),this._matchesPosition=n+1,this._activelyChangingMatch$.next(t),this._activeHighlightIndex=i,this._updateFindHighlight(),this._updateCurrentHighlightShape(i)}findInActiveWorksheet(e){const t=this._workbook.getUnitId(),i=()=>{var u;const c=this._workbook.getActiveSheet();if(!c)return!1;const d=this._workbookSelections.getCurrentSelections();return(u=d==null?void 0:d.some(g=>!z(g,c)))!=null?u:!1};let n,r=!0,s=!1;const o=()=>{const c=this._workbook.getActiveSheet();if(!c)return{results:[]};const d=this.currentMatch;s=i();const l=this._workbookSelections.getCurrentSelections(),u=s?this._findInSelections(c,l,e,t):this._findInWorksheet(c,e,t);return this._matches=u.results,this._matchesPosition=this._tryRestoreLastMatchesPosition(d,this._matches),r?(n=u,r=!1):this._matchesUpdate$.next(this._matches),this._updateFindHighlight(),u};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>this._updateFindHighlight())),this.disposeWithMe(k.merge(a.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(k.filter(([c])=>{if(c.type===a.CommandType.MUTATION&&c.params.unitId===this._workbook.getUnitId())return!0;if(c.id===p.SetSelectionsOperation.id&&c.params.unitId===t){const d=i();return d===!1&&s===!1?!1:(s=d,!0)}return!1})),this._workbook.activeSheet$.pipe(k.skip(1))).pipe(k.debounceTime(200)).subscribe(()=>o())),o(),n}_findInRange(e,t,i,n,r){const s=[],o=e.getSheetId(),c=(t.findDirection===S.FindDirection.COLUMN?e.iterateByColumn:e.iterateByRow).bind(e)(i);for(const d of c){const{row:l,col:u,colSpan:g,rowSpan:v,value:I}=d;if(r!=null&&r(l,u)||!I||e.getRowFiltered(l))continue;const{hit:w,replaceable:M,isFormula:R}=te(e,l,u,t,I);if(w){const H={provider:Z,unitId:n,replaceable:M,isFormula:R,range:{subUnitId:o,range:{startRow:l,startColumn:u,endColumn:u+(g!=null?g:1)-1,endRow:l+(v!=null?v:1)-1}}};s.push(H)}}return{results:s}}_findInSelections(e,t,i,n){const{findDirection:r}=i,s=r===S.FindDirection.ROW?D:N,o=new Set;return{results:t.map(d=>this._findInRange(e,i,d.range,n,(l,u)=>{const g=`${l}-${u}`;return o.has(g)?!0:(o.add(g),!1)}).results).flat().sort((d,l)=>s(d.range.range,l.range.range)?-1:1)}}_findInWorksheet(e,t,i){const n=e.getRowCount(),r=e.getColumnCount(),s={startRow:0,startColumn:0,endRow:n-1,endColumn:r-1};return this._findInRange(e,t,s,i)}_disposeHighlights(){var e;this._highlightShapes.forEach(t=>{var i;(i=t.getScene())==null||i.makeDirty(),t.dispose()}),this._highlightShapes=[],(e=this._currentHighlightShape)==null||e.dispose(),this._currentHighlightShape=null}_updateFindHighlight(){var u;this._disposeHighlights();const e=(u=this._sheetSkeletonManagerService.getCurrent())==null?void 0:u.skeleton;if(!e)return;const t=this._workbook.getUnitId(),i=this._renderManagerService.getRenderById(t);if(i==null)return;const{scene:n}=i,r=this._matches,s=this._themeService.getColorFromTheme("yellow.400"),o=new a.ColorKit(s).toRgb(),c=this._workbook.getActiveSheet();if(!c)return;const d=c.getSheetId(),l=r.filter(g=>g.range.subUnitId===d).map((g,v)=>{const{startColumn:I,startRow:w,endColumn:M,endRow:R}=g.range.range,H=F.getCoordByCell(w,I,n,e),ae=F.getCoordByCell(R,M,n,e),{startX:G,startY:Y}=H,{endX:le,endY:de}=ae;let E=!0;for(let b=w;b<=R;b++)if(c.getRowRawVisible(b)){E=!1;break}let O=!0;for(let b=I;b<=M;b++)if(c.getColVisible(b)){O=!1;break}const ue=E||O,ge=O?2:le-G,fe=E?2:de-Y,_e={left:G,top:Y,color:o,width:ge,height:fe,evented:!1,inHiddenRange:ue,zIndex:ee};return new K(`find-highlight-${v}`,_e)});n.addObjects(l),this._highlightShapes=l,n.makeDirty()}_updateCurrentHighlightShape(e){var t;if((t=this._currentHighlightShape)==null||t.setShapeProps({activated:!1}),this._currentHighlightShape=null,e!==void 0){const i=this._highlightShapes[e];if(!i)return;this._currentHighlightShape=i,i.setShapeProps({activated:!0})}}_getSheetObject(){return F.getSheetObject(this._univerInstanceService,this._renderManagerService)}_focusMatch(e){var i;const t=e.range.subUnitId;t!==((i=this._workbook.getActiveSheet())==null?void 0:i.getSheetId())&&this._commandService.executeCommand(p.SetWorksheetActivateCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:t},{fromFindReplace:!0}),this._commandService.executeCommand(F.ScrollToCellCommand.id,{range:e.range.range},{fromFindReplace:!0})}_tryRestoreLastMatchesPosition(e,t){if(!e)return 0;const{subUnitId:i}=e.range,{startColumn:n,startRow:r}=e.range.range,s=t.findIndex(o=>{if(i!==o.range.subUnitId)return!1;const{startColumn:c,startRow:d}=o.range.range;return c===n&&d===r});return s>-1?s+1:0}moveToNextMatch(e){var o,c,d,l,u;if(!this._matches.length)return null;const t=(o=e==null?void 0:e.loop)!=null?o:!1,i=(c=e==null?void 0:e.stayIfOnMatch)!=null?c:!1,n=(d=e==null?void 0:e.noFocus)!=null?d:!1,r=(l=e==null?void 0:e.ignoreSelection)!=null?l:!1,s=this._findNextMatch(t,i,r);if(s){const[g,v]=s;return this._matchesPosition=v+1,this._query.findScope===S.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(g.range.subUnitId).findIndex(I=>I===g):this._activeHighlightIndex=v,n||this._focusMatch(g),((u=this._workbook.getActiveSheet())==null?void 0:u.getSheetId())===g.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),g}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}moveToPreviousMatch(e){var o,c,d,l,u;if(!this._matches.length)return null;const t=(o=e==null?void 0:e.loop)!=null?o:!1,i=(c=e==null?void 0:e.stayIfOnMatch)!=null?c:!1,n=(d=e==null?void 0:e.noFocus)!=null?d:!1,r=(l=e==null?void 0:e.ignoreSelection)!=null?l:!1,s=this._findPreviousMatch(t,i,r);if(s){const[g,v]=s;return this._matchesPosition=v+1,this._query.findScope===S.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(g.range.subUnitId).findIndex(I=>I===g):this._activeHighlightIndex=v,n||this._focusMatch(g),((u=this._workbook.getActiveSheet())==null?void 0:u.getSheetId())===g.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),g}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}_findPreviousMatch(e=!1,t=!1,i=!1){var o;if(this.currentMatch){const c=this._matches.findIndex(g=>g===this.currentMatch);if(t)return[this.currentMatch,c];const d=c-1;if(!e&&d<0)return null;const l=this._matches.length,u=(d+l)%l;return[this._matches[u],u]}const n=this._workbookSelections.getCurrentLastSelection();if(i||!n){const c=this._matches.length-1;return[this._matches[c],c]}if(this._query.findScope!==S.FindScope.UNIT)return this._findPreviousMatchByRange(this._matches,n.range);const r=(o=this._workbook.getActiveSheet())==null?void 0:o.getSheetId();if(!r)return null;const s=this._findPreviousWorksheetThatHasAMatch(r,e);return s?this._findPreviousMatchByRange(this._matchesByWorksheet.get(s),n.range):null}_findNextMatch(e=!1,t=!1,i=!1){var o;if(this.currentMatch){const c=this._matches.findIndex(g=>g===this.currentMatch);if(t)return[this.currentMatch,c];const d=c+1,l=this._matches.length;if(!e&&d>=l)return null;const u=d%l;return[this._matches[u],u]}const n=this._workbookSelections.getCurrentLastSelection();if(i||!n)return[this._matches[0],0];if(this._query.findScope!==S.FindScope.UNIT)return this._findNextMatchByRange(this._matches,n.range,t);const r=(o=this._workbook.getActiveSheet())==null?void 0:o.getSheetId();if(!r)return null;const s=this._findNextWorksheetThatHasAMatch(r,e);return s?this._findNextMatchByRange(this._matchesByWorksheet.get(s),n.range):null}_findPreviousWorksheetThatHasAMatch(e,t=!1){const i=this._workbook.getSheetOrders(),n=i.findIndex(o=>o===e),s=(t?a.rotate(i,n+1):i.slice(0,n+1)).findLast(o=>this._matchesByWorksheet.has(o));return s!=null?s:null}_findNextWorksheetThatHasAMatch(e,t=!1){const i=this._workbook.getSheetOrders(),n=i.findIndex(o=>o===e),s=(t?a.rotate(i,n):i.slice(n)).find(o=>this._matchesByWorksheet.has(o));return s!=null?s:null}_findNextMatchByRange(e,t,i=!1){const n=this._query.findDirection===S.FindDirection.ROW;let r=e.findIndex(o=>{const c=o.range.range;if(!(n?D(t,c):N(t,c)))return!1;const l=A(t,c);return i?l:!l});r===-1&&(r=e.length-1);const s=e[r];return[s,this._matches.findIndex(o=>o===s)]}_findPreviousMatchByRange(e,t,i=!1){const n=this._query.findDirection===S.FindDirection.ROW;let r=this._matches.findLastIndex(o=>{const c=o.range.range;if(!(n?Q(t,c):X(t,c)))return!1;const l=A(t,c);return i?l:!l});r===-1&&(r=0);const s=e[r];return[s,this._matches.findIndex(o=>o===s)]}async replace(e){if(this._matchesCount===0||!this.currentMatch||!this._query||!this.currentMatch.replaceable)return!1;const t=this.currentMatch.range,i=this._workbook.getSheetBySheetId(this.currentMatch.range.subUnitId),n=this._getReplacedCellData(this.currentMatch,i,this._query.findBy===S.FindBy.FORMULA,this._query.findString,e,this._query.caseSensitive?"g":"ig"),r={unitId:this.currentMatch.unitId,subUnitId:t.subUnitId,value:{[t.range.startRow]:{[t.range.startColumn]:n}}};return this._commandService.executeCommand(p.SetRangeValuesCommand.id,r)}async replaceAll(e){if(this._matchesCount===0||!this._query)return{success:0,failure:0};const t=this._workbook.getUnitId(),{findString:i,caseSensitive:n,findBy:r}=this._query,s=r===S.FindBy.FORMULA,o=n?"g":"ig",c=[];return a.groupBy(this._matches.filter(l=>l.replaceable),l=>l.range.subUnitId).forEach((l,u)=>{const g=new a.ObjectMatrix,v=this._workbook.getSheetBySheetId(u);l.forEach(I=>{const{startColumn:w,startRow:M}=I.range.range,R=this._getReplacedCellData(I,v,s,i,e,o);R&&g.setValue(M,w,R)}),c.push({count:l.length,subUnitId:u,value:g.getMatrix()})}),c?this._commandService.executeCommand(P.id,{unitId:t,replacements:c}):{success:0,failure:0}}_getReplacedCellData(e,t,i,n,r,s){var v;const o=e.range.range,{startRow:c,startColumn:d}=o,l=t.getCellRaw(c,d);if(e.isFormula)return i?{f:l.f.replace(new RegExp(j(n),s),r),v:null}:null;if(!!((v=l.p)!=null&&v.body)){const I=a.Tools.deepClone(l.p);return a.replaceInDocumentBody(I.body,n,r,this._query.caseSensitive),{p:I}}return{v:l.v.toString().replace(new RegExp(j(n),s),r)}}};B=x([C(2,a.IUniverInstanceService),C(3,y.IRenderManagerService),C(4,a.ICommandService),C(5,a.IContextService),C(6,a.Inject(a.ThemeService)),C(7,a.Inject(p.SheetsSelectionsService))],B);function j(h){return h.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}let W=class extends a.Disposable{constructor(e,t,i){super();m(this,"_findModelsByUnitId",new Map);this._univerInstanceService=e,this._renderManagerService=t,this._injector=i}async find(e){this._terminate();const t=this._univerInstanceService.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET);if(!t)return[];const i=this._preprocessQuery(e),n=this._renderManagerService.getRenderById(t.getUnitId()).with(F.SheetSkeletonManagerService),r=this._injector.createInstance(B,t,n);return this._findModelsByUnitId.set(t.getUnitId(),r),r.start(i),[r]}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([C(0,a.IUniverInstanceService),C(1,y.IRenderManagerService),C(2,a.Inject(a.Injector))],W);const _={hit:!1,replaceable:!1,isFormula:!1,rawData:null};function te(h,e,t,i,n){const{findBy:r}=i,s=r===S.FindBy.FORMULA,o=h.getCellRaw(e,t);return _.rawData=o,!(o!=null&&o.f)?(_.isFormula=!1,T(n,i)?o?(_.hit=!0,_.replaceable=!0):(_.hit=!0,_.replaceable=!1):(_.hit=!1,_.replaceable=!1),_):(_.isFormula=!0,s?T({v:o.f},i)?(_.hit=!0,_.replaceable=!0,_):(_.hit=!1,_.replaceable=!1,_):(_.replaceable=!1,T(n,i)?_.hit=!0:_.hit=!1,_))}function T(h,e){let t=ie(h);return t?e.matchesTheWholeCell?(t=ne(t),e.caseSensitive?t===e.findString:t.toLowerCase()===e.findString):e.caseSensitive?t.indexOf(e.findString)>-1:t.toLowerCase().indexOf(e.findString)>-1:!1}function ie(h){var t,i,n;const e=(n=(i=(t=h==null?void 0:h.p)==null?void 0:t.body)==null?void 0:i.dataStream)!=null?n:h==null?void 0:h.v;return typeof e=="number"?`${e}`:typeof e=="boolean"?e?"1":"0":e}function ne(h){return h.replace(/^ +/g,"").replace(/ +$/g,"")}const $={name:"@univerjs/sheets-find-replace",version:"0.17.0"},se="sheets-find-replace.config",L={};var re=Object.defineProperty,oe=Object.getOwnPropertyDescriptor,he=(h,e,t)=>e in h?re(h,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):h[e]=t,ce=(h,e,t,i)=>{for(var n=i>1?void 0:i?oe(e,t):e,r=h.length-1,s;r>=0;r--)(s=h[r])&&(n=s(n)||n);return n},V=(h,e)=>(t,i)=>e(t,i,h),U=(h,e,t)=>he(h,typeof e!="symbol"?e+"":e,t);f.UniverSheetsFindReplacePlugin=class extends a.Plugin{constructor(e=L,t,i){super(),this._config=e,this._injector=t,this._configService=i;const{...n}=a.merge({},L,this._config);this._configService.setConfig(se,n)}onStarting(){[[f.SheetsFindReplaceController]].forEach(e=>this._injector.add(e))}onSteady(){this._injector.get(f.SheetsFindReplaceController)}},U(f.UniverSheetsFindReplacePlugin,"pluginName","SHEET_FIND_REPLACE_PLUGIN"),U(f.UniverSheetsFindReplacePlugin,"packageName",$.name),U(f.UniverSheetsFindReplacePlugin,"version",$.version),U(f.UniverSheetsFindReplacePlugin,"type",a.UniverInstanceType.UNIVER_SHEET),f.UniverSheetsFindReplacePlugin=ce([a.DependentOn(p.UniverSheetsPlugin,p.UniverSheetsPlugin,S.UniverFindReplacePlugin),V(1,a.Inject(a.Injector)),V(2,a.IConfigService)],f.UniverSheetsFindReplacePlugin),f.SheetReplaceCommand=P,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-find-replace",
3
- "version": "0.16.1-insiders.20260311-074e8ca",
3
+ "version": "0.17.0",
4
4
  "private": false,
5
5
  "description": "UniverSheet find replace plugin",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -63,18 +63,18 @@
63
63
  "rxjs": ">=7.0.0"
64
64
  },
65
65
  "dependencies": {
66
- "@univerjs/core": "0.16.1-insiders.20260311-074e8ca",
67
- "@univerjs/engine-render": "0.16.1-insiders.20260311-074e8ca",
68
- "@univerjs/find-replace": "0.16.1-insiders.20260311-074e8ca",
69
- "@univerjs/sheets": "0.16.1-insiders.20260311-074e8ca",
70
- "@univerjs/sheets-ui": "0.16.1-insiders.20260311-074e8ca"
66
+ "@univerjs/engine-render": "0.17.0",
67
+ "@univerjs/core": "0.17.0",
68
+ "@univerjs/sheets": "0.17.0",
69
+ "@univerjs/sheets-ui": "0.17.0",
70
+ "@univerjs/find-replace": "0.17.0"
71
71
  },
72
72
  "devDependencies": {
73
73
  "rxjs": "^7.8.2",
74
74
  "typescript": "^5.9.3",
75
75
  "vite": "^7.3.1",
76
76
  "vitest": "^4.0.18",
77
- "@univerjs-infra/shared": "0.16.1"
77
+ "@univerjs-infra/shared": "0.17.0"
78
78
  },
79
79
  "scripts": {
80
80
  "test": "vitest run",