@univerjs/sheets-find-replace 0.2.2 → 0.2.4-alpha.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/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # @univerjs/sheets-find-replace
2
2
 
3
- [![npm version](https://img.shields.io/npm/v/@univerjs/sheets-find-replace)](https://npmjs.org/package/@univerjs/sheets-find-replace)
4
- [![license](https://img.shields.io/npm/l/@univerjs/sheets-find-replace)](https://img.shields.io/npm/l/@univerjs/sheets-find-replace)
5
- ![i18n](https://img.shields.io/badge/zh--CN%20%7C%20en--US-cornflowerblue?label=i18n)
3
+ ## Package Overview
4
+
5
+ | Package Name | UMD Namespace | Version | License | Downloads | Contains CSS | Contains i18n locales |
6
+ | --- | --- | --- | --- | --- | :---: | :---: |
7
+ | `@univerjs/sheets-find-replace` | `UniverSheetsFindReplace` | [![][npm-version-shield]][npm-version-link] | ![][npm-license-shield] | ![][npm-downloads-shield] | ❌ | ⭕️ |
6
8
 
7
9
  ## Introduction
8
10
 
@@ -12,7 +14,7 @@ This package provides the feature to find and replace text in spreadsheets.
12
14
 
13
15
  You should use this plugin with the `@univerjs/find-replace` package.
14
16
 
15
- ```ts
17
+ ```typescript
16
18
  import { UniverFindReplacePlugin } from '@univerjs/find-replace';
17
19
  import { UniverSheetsFindReplacePlugin } from '@univerjs/sheets-find-replace';
18
20
 
@@ -29,3 +31,9 @@ npm install @univerjs/sheets-find-replace
29
31
  # Using pnpm
30
32
  pnpm add @univerjs/sheets-find-replace
31
33
  ```
34
+
35
+ <!-- Links -->
36
+ [npm-version-shield]: https://img.shields.io/npm/v/@univerjs/sheets-find-replace?style=flat-square
37
+ [npm-version-link]: https://npmjs.com/package/@univerjs/sheets-find-replace
38
+ [npm-license-shield]: https://img.shields.io/npm/l/@univerjs/sheets-find-replace?style=flat-square
39
+ [npm-downloads-shield]: https://img.shields.io/npm/dm/@univerjs/sheets-find-replace?style=flat-square
package/lib/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var ee=Object.defineProperty;var te=(c,e,t)=>e in c?ee(c,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):c[e]=t;var S=(c,e,t)=>te(c,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("@univerjs/core"),C=require("@wendellhu/redi"),_=require("@univerjs/find-replace"),R=require("@univerjs/sheets"),y=require("@univerjs/engine-render"),k=require("@univerjs/sheets-ui"),I=require("rxjs");class ne extends y.Shape{constructor(t,n){super(t,n);S(this,"_activated",!1);S(this,"_inHiddenRange",!1);S(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})}}const B={id:"sheet.command.replace",type:d.CommandType.COMMAND,handler:async(c,e)=>{const t=c.get(d.IUndoRedoService),n=c.get(d.ICommandService),{unitId:i,replacements:r}=e,s=t.__tempBatchingUndoRedo(i),o=await Promise.all(r.map(a=>n.executeCommand(R.SetRangeValuesCommand.id,{unitId:i,subUnitId:a.subUnitId,value:a.value})));return s.dispose(),ie(o,r)}};function ie(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}}function A(c,e){return c.startRow===e.startRow&&c.startColumn===e.startColumn}function D(c,e){return c.startRow<e.startRow||c.startRow===e.startRow&&c.startColumn<=e.startColumn}function N(c,e){return c.startColumn<e.startColumn||c.startColumn===e.startColumn&&c.startRow<=e.startRow}function se(c,e){return c.startRow>e.startRow||c.startRow===e.startRow&&c.startColumn>=e.startColumn}function re(c,e){return c.startColumn>e.startColumn||c.startColumn===e.startColumn&&c.startRow>=e.startRow}function oe(c,e){const{range:t}=c,{startRow:n,startColumn:i}=t,r=e.getMergedCell(n,i);return r?d.Rectangle.equals(t,r):t.endRow===t.startRow&&t.endColumn===t.startColumn}var ce=Object.defineProperty,he=Object.getOwnPropertyDescriptor,W=(c,e,t,n)=>{for(var i=n>1?void 0:n?he(e,t):e,r=c.length-1,s;r>=0;r--)(s=c[r])&&(i=(n?s(e,t,i):s(i))||i);return n&&i&&ce(e,t,i),i},m=(c,e)=>(t,n)=>e(t,n,c);exports.SheetsFindReplaceController=class extends d.Disposable{constructor(t,n,i,r,s){super();S(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(P);this._provider=t,this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(t)),this.disposeWithMe(this._contextService.subscribeContextValue$(d.EDITOR_ACTIVATED).pipe(I.filter(n=>!!n)).subscribe(()=>this._findReplaceController.closePanel()))}_initCommands(){[B].forEach(t=>this.disposeWithMe(this._commandService.registerCommand(t)))}};exports.SheetsFindReplaceController=W([d.OnLifecycle(d.LifecycleStages.Steady,exports.SheetsFindReplaceController),m(0,C.Inject(C.Injector)),m(1,C.Inject(_.FindReplaceController)),m(2,d.IContextService),m(3,_.IFindReplaceService),m(4,d.ICommandService)],exports.SheetsFindReplaceController);const ae="sheets-find-replace-provider",le=1e4;let F=class extends _.FindModel{constructor(e,t,n,i,r,s,o,a){super();S(this,"_matchesUpdate$",new I.Subject);S(this,"matchesUpdate$",this._matchesUpdate$.asObservable());S(this,"_activelyChangingMatch$",new I.Subject);S(this,"activelyChangingMatch$",this._activelyChangingMatch$.asObservable());S(this,"_matchesByWorksheet",new Map);S(this,"_matches",[]);S(this,"_matchesPosition",0);S(this,"_activeHighlightIndex",-1);S(this,"_highlightShapes",[]);S(this,"_currentHighlightShape",null);S(this,"_query",null);this._workbook=e,this._sheetSkeletonManagerService=t,this._univerInstanceService=n,this._renderManagerService=i,this._commandService=r,this._contextService=s,this._themeService=o,this._selectionManagerService=a}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===_.FindBy.FORMULA?this._toggleDisplayRawFormula(!0):this._toggleDisplayRawFormula(!1),e.findScope){case _.FindScope.UNIT:this.findInWorkbook(e);break;case _.FindScope.SUBUNIT:default:this.findInActiveWorksheet(e);break}}_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 a=this._findInWorksheet(o,e,t),l=o.getSheetId(),{results:h}=a;return h.length?this._matchesByWorksheet.set(l,a.results):this._matchesByWorksheet.delete(l),a});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(d.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService.onCommandExecuted)).pipe(I.filter(([s,o])=>s.id===R.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(d.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(I.filter(([s])=>s.type===d.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._selectionManagerService.getSelections();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 a=this._workbook.getActiveSheet();if(!a)return!1;const l=this._selectionManagerService.getSelections();return(u=l==null?void 0:l.some(f=>!oe(f,a)))!=null?u:!1};let i,r=!0,s=!1;const o=()=>{const a=this._workbook.getActiveSheet();if(!a)return{results:[]};const l=this.currentMatch;s=n();const h=this._selectionManagerService.getSelections(),u=s?this._findInSelections(a,h,e,t):this._findInWorksheet(a,e,t);return this._matches=u.results,this._matchesPosition=this._tryRestoreLastMatchesPosition(l,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(d.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(I.filter(([a])=>{if(a.type===d.CommandType.MUTATION&&a.params.unitId===this._workbook.getUnitId())return!0;if(a.id===R.SetSelectionsOperation.id&&a.params.unitId===t){const l=n();return l===!1&&s===!1?!1:(s=l,!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(),a=(t.findDirection===_.FindDirection.COLUMN?e.iterateByColumn:e.iterateByRow).bind(e)(n);for(const l of a){const{row:h,col:u,colSpan:f,rowSpan:v,value:p}=l;if(r!=null&&r(h,u)||!p||e.getRowFiltered(h))continue;const{hit:b,replaceable:M,isFormula:w}=de(e,h,u,t,p);if(b){const x={provider:ae,unitId:i,replaceable:M,isFormula:w,range:{subUnitId:o,range:{startRow:h,startColumn:u,endColumn:u+(f!=null?f:1)-1,endRow:h+(v!=null?v:1)-1}}};s.push(x)}}return{results:s}}_findInSelections(e,t,n,i){const{findDirection:r}=n,s=r===_.FindDirection.ROW?D:N,o=new Set;return{results:t.map(l=>this._findInRange(e,n,l.range,i,(h,u)=>{const f=`${h}-${u}`;return o.has(f)?!0:(o.add(f),!1)}).results).flat().sort((l,h)=>s(l.range.range,h.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=>{t.getScene().makeDirty(),t.dispose()}),this._highlightShapes=[],(e=this._currentHighlightShape)==null||e.dispose(),this._currentHighlightShape=null}_updateFindHighlight(){var v,p;this._disposeHighlights();const e=(v=this._sheetSkeletonManagerService.getCurrent())==null?void 0:v.skeleton;if(!e||!this._getSheetObject()||((p=this._univerInstanceService.getFocusedUnit())==null?void 0:p.getUnitId())!==this._workbook.getUnitId())return;const i=this._workbook.getUnitId(),r=this._renderManagerService.getRenderById(i);if(r==null)return;const{scene:s}=r,o=this._matches,a=this._themeService.getCurrentTheme().gold400,l=new d.ColorKit(a).toRgb(),h=this._workbook.getActiveSheet();if(!h)return;const u=h.getSheetId(),f=o.filter(b=>b.range.subUnitId===u).map((b,M)=>{const{startColumn:w,startRow:x,endColumn:V,endRow:q}=b.range.range,Q=k.getCoordByCell(x,w,s,e),X=k.getCoordByCell(q,V,s,e),{startX:H,startY:T}=Q,{endX:Y,endY:G}=X,O=!h.getRowRawVisible(x),E=!h.getColVisible(w),K=O||E,z=E?2:Y-H,J=O?2:G-T,Z={left:H,top:T,color:l,width:z,height:J,evented:!1,inHiddenRange:K,zIndex:le};return new ne(`find-highlight-${M}`,Z)});s.addObjects(f),this._highlightShapes=f,s.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 k.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.syncExecuteCommand(R.SetWorksheetActivateCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:t},{fromFindReplace:!0}),this._commandService.syncExecuteCommand(k.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:a,startRow:l}=o.range.range;return a===i&&l===r});return s>-1?s+1:0}moveToNextMatch(e){var s,o,a,l;if(!this._matches.length)return null;const t=(s=e==null?void 0:e.loop)!=null?s:!1,n=(o=e==null?void 0:e.stayIfOnMatch)!=null?o:!1,i=(a=e==null?void 0:e.noFocus)!=null?a:!1,r=this._findNextMatch(t,n);if(r){const[h,u]=r;return this._matchesPosition=u+1,this._query.findScope===_.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(h.range.subUnitId).findIndex(f=>f===h):this._activeHighlightIndex=u,i||this._focusMatch(h),((l=this._workbook.getActiveSheet())==null?void 0:l.getSheetId())===h.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),h}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}moveToPreviousMatch(e){var s,o,a,l;if(!this._matches.length)return null;const t=(s=e==null?void 0:e.loop)!=null?s:!1,n=(o=e==null?void 0:e.stayIfOnMatch)!=null?o:!1,i=(a=e==null?void 0:e.noFocus)!=null?a:!1,r=this._findPreviousMatch(t,n);if(r){const[h,u]=r;return this._matchesPosition=u+1,this._query.findScope===_.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(h.range.subUnitId).findIndex(f=>f===h):this._activeHighlightIndex=u,i||this._focusMatch(h),((l=this._workbook.getActiveSheet())==null?void 0:l.getSheetId())===h.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),h}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}_findPreviousMatch(e=!1,t=!1){var s;if(this.currentMatch){const o=this._matches.findIndex(u=>u===this.currentMatch);if(t)return[this.currentMatch,o];const a=o-1;if(!e&&a<0)return null;const l=this._matches.length,h=(a+l)%l;return[this._matches[h],h]}const n=this._selectionManagerService.getSelections();if(!(n!=null&&n.length))return[this._matches[0],0];if(this._query.findScope!==_.FindScope.UNIT)return this._findPreviousMatchByRange(this._matches,n[0].range);const i=(s=this._workbook.getActiveSheet())==null?void 0:s.getSheetId();if(!i)return null;const r=this._findPreviousWorksheetThatHasAMatch(i,e);return r?this._findPreviousMatchByRange(this._matchesByWorksheet.get(r),n[0].range):null}_findNextMatch(e=!1,t=!1){var s;if(this.currentMatch){const o=this._matches.findIndex(u=>u===this.currentMatch);if(t)return[this.currentMatch,o];const a=o+1,l=this._matches.length;if(!e&&a>=l)return null;const h=a%l;return[this._matches[h],h]}const n=this._selectionManagerService.getSelections();if(!(n!=null&&n.length))return[this._matches[0],0];if(this._query.findScope!==_.FindScope.UNIT)return this._findNextMatchByRange(this._matches,n[0].range,t);const i=(s=this._workbook.getActiveSheet())==null?void 0:s.getSheetId();if(!i)return null;const r=this._findNextWorksheetThatHasAMatch(i,e);return r?this._findNextMatchByRange(this._matchesByWorksheet.get(r),n[0].range):null}_findPreviousWorksheetThatHasAMatch(e,t=!1){const n=this._workbook.getSheetOrders(),i=n.findIndex(o=>o===e),s=(t?d.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?d.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===_.FindDirection.ROW;let r=e.findIndex(o=>{const a=o.range.range;if(!(i?D(t,a):N(t,a)))return!1;const h=A(t,a);return n?h:!h});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===_.FindDirection.ROW;let r=this._matches.findLastIndex(o=>{const a=o.range.range;if(!(i?se(t,a):re(t,a)))return!1;const h=A(t,a);return n?h:!h});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===_.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(R.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===_.FindBy.FORMULA,o=i?"g":"ig",a=[];return d.groupBy(this._matches.filter(h=>h.replaceable),h=>h.range.subUnitId).forEach((h,u)=>{const f=new d.ObjectMatrix,v=this._workbook.getSheetBySheetId(u);h.forEach(p=>{const{startColumn:b,startRow:M}=p.range.range,w=this._getReplacedCellData(p,v,s,n,e,o);w&&f.setValue(M,b,w)}),a.push({count:h.length,subUnitId:u,value:f.getMatrix()})}),a?this._commandService.executeCommand(B.id,{unitId:t,replacements:a}):{success:0,failure:0}}_getReplacedCellData(e,t,n,i,r,s){var v;const o=e.range.range,{startRow:a,startColumn:l}=o,h=t.getCellRaw(a,l);if(e.isFormula)return n?{f:h.f.replace(new RegExp($(i),s),r),v:null}:null;if(!!((v=h.p)!=null&&v.body)){const p=d.Tools.deepClone(h.p);return d.replaceInDocumentBody(p.body,i,r),{p}}return{v:h.v.toString().replace(new RegExp($(i),s),r)}}};F=W([m(2,d.IUniverInstanceService),m(3,y.IRenderManagerService),m(4,d.ICommandService),m(5,d.IContextService),m(6,C.Inject(d.ThemeService)),m(7,C.Inject(R.SelectionManagerService))],F);function $(c){return c.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}let P=class extends d.Disposable{constructor(e,t,n){super();S(this,"_findModelsByUnitId",new Map);this._univerInstanceService=e,this._renderManagerService=t,this._injector=n}async find(e){this._terminate();const t=this._univerInstanceService.getCurrentUnitForType(d.UniverInstanceType.UNIVER_SHEET),n=this._renderManagerService.getRenderById(t.getUnitId()).with(k.SheetSkeletonManagerService);if(t){const i=this._injector.createInstance(F,t,n);this._findModelsByUnitId.set(t.getUnitId(),i);const r=this._preprocessQuery(e);return i.start(r),[i]}return[]}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}}};P=W([m(0,d.IUniverInstanceService),m(1,y.IRenderManagerService),m(2,C.Inject(C.Injector))],P);const g={hit:!1,replaceable:!1,isFormula:!1,rawData:null};function de(c,e,t,n,i){const{findBy:r}=n,s=r===_.FindBy.FORMULA,o=c.getCellRaw(e,t);return g.rawData=o,!(o!=null&&o.f)?(g.isFormula=!1,U(i,n)?o?(g.hit=!0,g.replaceable=!0):(g.hit=!0,g.replaceable=!1):(g.hit=!1,g.replaceable=!1),g):(g.isFormula=!0,s?U({v:o.f},n)?(g.hit=!0,g.replaceable=!0,g):(g.hit=!1,g.replaceable=!1,g):(g.replaceable=!1,U(i,n)?g.hit=!0:g.hit=!1,g))}function U(c,e){let t=ue(c);return t?e.matchesTheWholeCell?(t=ge(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 ue(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 ge(c){return c.replace(/^ +/g,"").replace(/ +$/g,"")}var j=Object.defineProperty,fe=Object.getOwnPropertyDescriptor,_e=(c,e,t)=>e in c?j(c,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):c[e]=t,Se=(c,e,t,n)=>{for(var i=n>1?void 0:n?fe(e,t):e,r=c.length-1,s;r>=0;r--)(s=c[r])&&(i=(n?s(e,t,i):s(i))||i);return n&&i&&j(e,t,i),i},me=(c,e)=>(t,n)=>e(t,n,c),L=(c,e,t)=>_e(c,typeof e!="symbol"?e+"":e,t);const pe="SHEET_FIND_REPLACE_PLUGIN";exports.UniverSheetsFindReplacePlugin=class extends d.Plugin{constructor(e,t){super(),this._injector=t}onStarting(e){[[exports.SheetsFindReplaceController]].forEach(t=>e.add(t))}};L(exports.UniverSheetsFindReplacePlugin,"pluginName",pe);L(exports.UniverSheetsFindReplacePlugin,"type",d.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsFindReplacePlugin=Se([d.DependentOn(R.UniverSheetsPlugin,R.UniverSheetsPlugin,_.UniverFindReplacePlugin),me(1,C.Inject(C.Injector))],exports.UniverSheetsFindReplacePlugin);exports.SheetReplaceCommand=B;
1
+ "use strict";var K=Object.defineProperty;var z=(c,e,t)=>e in c?K(c,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):c[e]=t;var _=(c,e,t)=>z(c,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@univerjs/core"),S=require("@univerjs/find-replace"),C=require("@univerjs/sheets"),M=require("@univerjs/engine-render"),k=require("@univerjs/sheets-ui"),I=require("rxjs");class J extends M.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})`;M.Rect.drawWith(t,{width:this.width,height:this.height,fill:i,stroke:n?r:void 0,strokeWidth:n?2:0,evented:!1})}}const P={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(),Z(o,r)}};function Z(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}}function E(c,e){return c.startRow===e.startRow&&c.startColumn===e.startColumn}function A(c,e){return c.startRow<e.startRow||c.startRow===e.startRow&&c.startColumn<=e.startColumn}function D(c,e){return c.startColumn<e.startColumn||c.startColumn===e.startColumn&&c.startRow<=e.startRow}function ee(c,e){return c.startRow>e.startRow||c.startRow===e.startRow&&c.startColumn>=e.startColumn}function te(c,e){return c.startColumn>e.startColumn||c.startColumn===e.startColumn&&c.startRow>=e.startRow}function ne(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 ie=Object.defineProperty,se=Object.getOwnPropertyDescriptor,B=(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=(n?s(e,t,i):s(i))||i);return n&&i&&ie(e,t,i),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(U);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(){[P].forEach(t=>this.disposeWithMe(this._commandService.registerCommand(t)))}};exports.SheetsFindReplaceController=B([l.OnLifecycle(l.LifecycleStages.Steady,exports.SheetsFindReplaceController),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 re="sheets-find-replace-provider",oe=1e4;let F=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}}_toggleDisplayRawFormula(e){this._contextService.setContextValue(M.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.onCommandExecuted)).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=>!ne(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:R,replaceable:w,isFormula:b}=ce(e,a,u,t,p);if(R){const y={provider:re,unitId:i,replaceable:w,isFormula:b,range:{subUnitId:o,range:{startRow:a,startColumn:u,endColumn:u+(g!=null?g:1)-1,endRow:a+(m!=null?m:1)-1}}};s.push(y)}}return{results:s}}_findInSelections(e,t,n,i){const{findDirection:r}=n,s=r===S.FindDirection.ROW?A:D,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=>{t.getScene().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.getCurrentTheme().gold400,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:R,endColumn:w,endRow:b}=g.range.range,y=k.getCoordByCell(R,p,i,e),L=k.getCoordByCell(b,w,i,e),{startX:W,startY:H}=y,{endX:V,endY:Q}=L,T=!h.getRowRawVisible(R),O=!h.getColVisible(p),X=T||O,Y=O?2:V-W,q=T?2:Q-H,G={left:W,top:H,color:o,width:Y,height:q,evented:!1,inHiddenRange:X,zIndex:oe};return new J(`find-highlight-${m}`,G)});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 k.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(k.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?A(t,h):D(t,h)))return!1;const a=E(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?ee(t,h):te(t,h)))return!1;const a=E(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:R,startRow:w}=p.range.range,b=this._getReplacedCellData(p,m,s,n,e,o);b&&g.setValue(w,R,b)}),h.push({count:a.length,subUnitId:u,value:g.getMatrix()})}),h?this._commandService.executeCommand(P.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(N(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),{p}}return{v:a.v.toString().replace(new RegExp(N(i),s),r)}}};F=B([v(2,l.IUniverInstanceService),v(3,M.IRenderManagerService),v(4,l.ICommandService),v(5,l.IContextService),v(6,l.Inject(l.ThemeService)),v(7,l.Inject(C.SheetsSelectionsService))],F);function N(c){return c.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}let U=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.getAllUnitsForType(l.UniverInstanceType.UNIVER_SHEET),n=this._preprocessQuery(e);return t.map(r=>{const s=this._renderManagerService.getRenderById(r.getUnitId()).with(k.SheetSkeletonManagerService),o=this._injector.createInstance(F,r,s);return this._findModelsByUnitId.set(r.getUnitId(),o),o.start(n),o})}terminate(){this._terminate()}_terminate(){this._findModelsByUnitId.forEach(e=>e.dispose()),this._findModelsByUnitId.clear()}_preprocessQuery(e){let t=e.caseSensitive?e.findString:e.findString.toLowerCase();return t=t.trim(),{...e,findString:t}}};U=B([v(0,l.IUniverInstanceService),v(1,M.IRenderManagerService),v(2,l.Inject(l.Injector))],U);const f={hit:!1,replaceable:!1,isFormula:!1,rawData:null};function ce(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,x(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?x({v:o.f},n)?(f.hit=!0,f.replaceable=!0,f):(f.hit=!1,f.replaceable=!1,f):(f.replaceable=!1,x(i,n)?f.hit=!0:f.hit=!1,f))}function x(c,e){let t=he(c);return t?e.matchesTheWholeCell?(t=ae(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 he(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 ae(c){return c.replace(/^ +/g,"").replace(/ +$/g,"")}var $=Object.defineProperty,le=Object.getOwnPropertyDescriptor,de=(c,e,t)=>e in c?$(c,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):c[e]=t,ue=(c,e,t,n)=>{for(var i=n>1?void 0:n?le(e,t):e,r=c.length-1,s;r>=0;r--)(s=c[r])&&(i=(n?s(e,t,i):s(i))||i);return n&&i&&$(e,t,i),i},ge=(c,e)=>(t,n)=>e(t,n,c),j=(c,e,t)=>de(c,typeof e!="symbol"?e+"":e,t);const fe="SHEET_FIND_REPLACE_PLUGIN";exports.UniverSheetsFindReplacePlugin=class extends l.Plugin{constructor(e,t){super(),this._injector=t}onStarting(e){[[exports.SheetsFindReplaceController]].forEach(t=>e.add(t))}};j(exports.UniverSheetsFindReplacePlugin,"pluginName",fe);j(exports.UniverSheetsFindReplacePlugin,"type",l.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsFindReplacePlugin=ue([l.DependentOn(C.UniverSheetsPlugin,C.UniverSheetsPlugin,S.UniverFindReplacePlugin),ge(1,l.Inject(l.Injector))],exports.UniverSheetsFindReplacePlugin);exports.SheetReplaceCommand=P;
package/lib/es/index.js CHANGED
@@ -1,19 +1,18 @@
1
- var fe = Object.defineProperty;
2
- var _e = (h, e, t) => e in h ? fe(h, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : h[e] = t;
3
- var f = (h, e, t) => _e(h, typeof e != "symbol" ? e + "" : e, t);
4
- import { CommandType as B, IUndoRedoService as me, ICommandService as H, Rectangle as Se, OnLifecycle as pe, LifecycleStages as ve, ThemeService as Ie, Disposable as K, EDITOR_ACTIVATED as Ce, IContextService as z, IUniverInstanceService as J, UniverInstanceType as Z, fromCallback as U, ColorKit as Re, rotate as $, groupBy as be, ObjectMatrix as we, Tools as Me, replaceInDocumentBody as ke, DependentOn as xe, Plugin as ye } from "@univerjs/core";
5
- import { Inject as C, Injector as O } from "@wendellhu/redi";
6
- import { FindReplaceController as Ue, IFindReplaceService as Pe, FindModel as Be, FindBy as M, FindScope as I, FindDirection as w, UniverFindReplacePlugin as We } from "@univerjs/find-replace";
7
- import { SetRangeValuesCommand as q, SelectionManagerService as Fe, SetWorksheetActiveOperation as He, SetSelectionsOperation as Oe, SetWorksheetActivateCommand as Te, UniverSheetsPlugin as L } from "@univerjs/sheets";
8
- import { Shape as Ee, Rect as Ae, IRenderManagerService as ee, RENDER_RAW_FORMULA_KEY as Ne } from "@univerjs/engine-render";
9
- import { SheetSkeletonManagerService as De, getCoordByCell as j, getSheetObject as $e, ScrollToCellCommand as Le } from "@univerjs/sheets-ui";
10
- import { filter as k, Subject as V, throttleTime as je, merge as Ve, skip as Qe, debounceTime as Xe } from "rxjs";
11
- class Ye extends Ee {
1
+ var de = Object.defineProperty;
2
+ var ue = (h, e, t) => e in h ? de(h, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : h[e] = t;
3
+ var g = (h, e, t) => ue(h, typeof e != "symbol" ? e + "" : e, t);
4
+ import { CommandType as B, IUndoRedoService as fe, ICommandService as H, Rectangle as ge, OnLifecycle as _e, LifecycleStages as me, Inject as C, Injector as T, ThemeService as Se, Disposable as K, EDITOR_ACTIVATED as pe, IContextService as z, IUniverInstanceService as J, UniverInstanceType as Z, fromCallback as P, ColorKit as ve, rotate as $, groupBy as Ie, ObjectMatrix as Ce, Tools as Re, replaceInDocumentBody as we, DependentOn as be, Plugin as ke } from "@univerjs/core";
5
+ import { FindReplaceController as Me, IFindReplaceService as xe, FindModel as ye, FindBy as b, FindScope as I, FindDirection as w, UniverFindReplacePlugin as Pe } from "@univerjs/find-replace";
6
+ import { SetRangeValuesCommand as q, SheetsSelectionsService as Ue, SetWorksheetActiveOperation as Be, SetSelectionsOperation as We, SetWorksheetActivateCommand as Fe, UniverSheetsPlugin as L } from "@univerjs/sheets";
7
+ import { Shape as He, Rect as Te, IRenderManagerService as ee, RENDER_RAW_FORMULA_KEY as Oe } from "@univerjs/engine-render";
8
+ import { SheetSkeletonManagerService as Ee, getCoordByCell as j, getSheetObject as Ae, ScrollToCellCommand as Ne } from "@univerjs/sheets-ui";
9
+ import { filter as k, Subject as V, throttleTime as De, merge as $e, skip as Le, debounceTime as je } from "rxjs";
10
+ class Ve extends He {
12
11
  constructor(t, i) {
13
12
  super(t, i);
14
- f(this, "_activated", !1);
15
- f(this, "_inHiddenRange", !1);
16
- f(this, "_color");
13
+ g(this, "_activated", !1);
14
+ g(this, "_inHiddenRange", !1);
15
+ g(this, "_color");
17
16
  i && this.setShapeProps(i);
18
17
  }
19
18
  setShapeProps(t) {
@@ -24,7 +23,7 @@ class Ye extends Ee {
24
23
  }
25
24
  _draw(t) {
26
25
  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})`;
27
- Ae.drawWith(t, {
26
+ Te.drawWith(t, {
28
27
  width: this.width,
29
28
  height: this.height,
30
29
  fill: n,
@@ -38,15 +37,15 @@ const te = {
38
37
  id: "sheet.command.replace",
39
38
  type: B.COMMAND,
40
39
  handler: async (h, e) => {
41
- const t = h.get(me), i = h.get(H), { unitId: n, replacements: r } = e, s = t.__tempBatchingUndoRedo(n), o = await Promise.all(r.map((a) => i.executeCommand(q.id, {
40
+ const t = h.get(fe), i = h.get(H), { unitId: n, replacements: r } = e, s = t.__tempBatchingUndoRedo(n), o = await Promise.all(r.map((c) => i.executeCommand(q.id, {
42
41
  unitId: n,
43
- subUnitId: a.subUnitId,
44
- value: a.value
42
+ subUnitId: c.subUnitId,
43
+ value: c.value
45
44
  })));
46
- return s.dispose(), Ge(o, r);
45
+ return s.dispose(), Qe(o, r);
47
46
  }
48
47
  };
49
- function Ge(h, e) {
48
+ function Qe(h, e) {
50
49
  let t = 0, i = 0;
51
50
  return h.forEach((n, r) => {
52
51
  const s = e[r].count;
@@ -62,25 +61,25 @@ function X(h, e) {
62
61
  function Y(h, e) {
63
62
  return h.startColumn < e.startColumn || h.startColumn === e.startColumn && h.startRow <= e.startRow;
64
63
  }
65
- function Ke(h, e) {
64
+ function Xe(h, e) {
66
65
  return h.startRow > e.startRow || h.startRow === e.startRow && h.startColumn >= e.startColumn;
67
66
  }
68
- function ze(h, e) {
67
+ function Ye(h, e) {
69
68
  return h.startColumn > e.startColumn || h.startColumn === e.startColumn && h.startRow >= e.startRow;
70
69
  }
71
- function Je(h, e) {
70
+ function Ge(h, e) {
72
71
  const { range: t } = h, { startRow: i, startColumn: n } = t, r = e.getMergedCell(i, n);
73
- return r ? Se.equals(t, r) : t.endRow === t.startRow && t.endColumn === t.startColumn;
72
+ return r ? ge.equals(t, r) : t.endRow === t.startRow && t.endColumn === t.startColumn;
74
73
  }
75
- var Ze = Object.defineProperty, qe = Object.getOwnPropertyDescriptor, T = (h, e, t, i) => {
76
- for (var n = i > 1 ? void 0 : i ? qe(e, t) : e, r = h.length - 1, s; r >= 0; r--)
74
+ var Ke = Object.defineProperty, ze = Object.getOwnPropertyDescriptor, O = (h, e, t, i) => {
75
+ for (var n = i > 1 ? void 0 : i ? ze(e, t) : e, r = h.length - 1, s; r >= 0; r--)
77
76
  (s = h[r]) && (n = (i ? s(e, t, n) : s(n)) || n);
78
- return i && n && Ze(e, t, n), n;
79
- }, _ = (h, e) => (t, i) => e(t, i, h);
80
- let x = class extends K {
77
+ return i && n && Ke(e, t, n), n;
78
+ }, S = (h, e) => (t, i) => e(t, i, h);
79
+ let M = class extends K {
81
80
  constructor(e, t, i, n, r) {
82
81
  super();
83
- f(this, "_provider");
82
+ g(this, "_provider");
84
83
  this._injector = e, this._findReplaceController = t, this._contextService = i, this._findReplaceService = n, this._commandService = r, this._init(), this._initCommands();
85
84
  }
86
85
  dispose() {
@@ -89,42 +88,43 @@ let x = class extends K {
89
88
  _init() {
90
89
  const e = this._injector.createInstance(F);
91
90
  this._provider = e, this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(e)), this.disposeWithMe(
92
- this._contextService.subscribeContextValue$(Ce).pipe(k((t) => !!t)).subscribe(() => this._findReplaceController.closePanel())
91
+ this._contextService.subscribeContextValue$(pe).pipe(k((t) => !!t)).subscribe(() => this._findReplaceController.closePanel())
93
92
  );
94
93
  }
95
94
  _initCommands() {
96
95
  [te].forEach((e) => this.disposeWithMe(this._commandService.registerCommand(e)));
97
96
  }
98
97
  };
99
- x = T([
100
- pe(ve.Steady, x),
101
- _(0, C(O)),
102
- _(1, C(Ue)),
103
- _(2, z),
104
- _(3, Pe),
105
- _(4, H)
106
- ], x);
107
- const et = "sheets-find-replace-provider", tt = 1e4;
108
- let W = class extends Be {
109
- constructor(e, t, i, n, r, s, o, a) {
98
+ M = O([
99
+ _e(me.Steady, M),
100
+ S(0, C(T)),
101
+ S(1, C(Me)),
102
+ S(2, z),
103
+ S(3, xe),
104
+ S(4, H)
105
+ ], M);
106
+ const Je = "sheets-find-replace-provider", Ze = 1e4;
107
+ let W = class extends ye {
108
+ constructor(e, t, i, n, r, s, o, c) {
110
109
  super();
111
110
  // We can directly inject the `FindReplaceService` here, and call its methods instead of using the observables.
112
- f(this, "_matchesUpdate$", new V());
113
- f(this, "matchesUpdate$", this._matchesUpdate$.asObservable());
114
- f(this, "_activelyChangingMatch$", new V());
115
- f(this, "activelyChangingMatch$", this._activelyChangingMatch$.asObservable());
111
+ g(this, "_matchesUpdate$", new V());
112
+ g(this, "matchesUpdate$", this._matchesUpdate$.asObservable());
113
+ g(this, "_activelyChangingMatch$", new V());
114
+ g(this, "activelyChangingMatch$", this._activelyChangingMatch$.asObservable());
116
115
  /** Hold matches by the worksheet they are in. Make it easier to track the next (or previous) match when searching in the whole workbook. */
117
- f(this, "_matchesByWorksheet", /* @__PURE__ */ new Map());
116
+ g(this, "_matchesByWorksheet", /* @__PURE__ */ new Map());
118
117
  /** Hold all matches in the currently searching scope. */
119
- f(this, "_matches", []);
118
+ g(this, "_matches", []);
120
119
  /** Position of the current focused ISheetCellMatch, starting from 1. */
121
- f(this, "_matchesPosition", 0);
122
- f(this, "_activeHighlightIndex", -1);
123
- f(this, "_highlightShapes", []);
124
- f(this, "_currentHighlightShape", null);
120
+ g(this, "_matchesPosition", 0);
121
+ g(this, "_activeHighlightIndex", -1);
122
+ g(this, "_highlightShapes", []);
123
+ g(this, "_currentHighlightShape", null);
125
124
  /** This properties holds the query params during this searching session. */
126
- f(this, "_query", null);
127
- this._workbook = e, this._sheetSkeletonManagerService = t, this._univerInstanceService = i, this._renderManagerService = n, this._commandService = r, this._contextService = s, this._themeService = o, this._selectionManagerService = a;
125
+ g(this, "_query", null);
126
+ g(this, "_workbookSelections");
127
+ 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);
128
128
  }
129
129
  get _matchesCount() {
130
130
  return this._matches.length;
@@ -148,7 +148,7 @@ let W = class extends Be {
148
148
  return this._matches;
149
149
  }
150
150
  start(e) {
151
- switch (this._query = e, e.findBy === M.FORMULA ? this._toggleDisplayRawFormula(!0) : this._toggleDisplayRawFormula(!1), e.findScope) {
151
+ switch (this._query = e, e.findBy === b.FORMULA ? this._toggleDisplayRawFormula(!0) : this._toggleDisplayRawFormula(!1), e.findScope) {
152
152
  case I.UNIT:
153
153
  this.findInWorkbook(e);
154
154
  break;
@@ -159,7 +159,7 @@ let W = class extends Be {
159
159
  }
160
160
  }
161
161
  _toggleDisplayRawFormula(e) {
162
- this._contextService.setContextValue(Ne, e);
162
+ this._contextService.setContextValue(Oe, e);
163
163
  }
164
164
  /**
165
165
  * Find all matches in the current workbook no matter which worksheet is activated.
@@ -171,16 +171,16 @@ let W = class extends Be {
171
171
  let i, n = !0;
172
172
  const r = () => {
173
173
  const s = this._workbook.getSheets().filter((o) => !o.isSheetHidden()).map((o) => {
174
- const a = this._findInWorksheet(o, e, t), l = o.getSheetId(), { results: c } = a;
175
- return c.length ? this._matchesByWorksheet.set(l, a.results) : this._matchesByWorksheet.delete(l), a;
174
+ const c = this._findInWorksheet(o, e, t), l = o.getSheetId(), { results: a } = c;
175
+ return a.length ? this._matchesByWorksheet.set(l, c.results) : this._matchesByWorksheet.delete(l), c;
176
176
  });
177
177
  this._matches = s.map((o) => o.results).flat(), this._updateFindHighlight(), n ? (i = { results: this._matches }, n = !1) : this._matchesUpdate$.next(this._matches);
178
178
  };
179
179
  return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(() => {
180
180
  this._updateFindHighlight(), this._updateCurrentHighlightShape(this._activeHighlightIndex);
181
181
  })), this.disposeWithMe(
182
- U(this._commandService.onCommandExecuted.bind(this._commandService.onCommandExecuted)).pipe(
183
- k(([s, o]) => s.id === He.id && !(o != null && o.fromFindReplace))
182
+ P(this._commandService.onCommandExecuted.bind(this._commandService.onCommandExecuted)).pipe(
183
+ k(([s, o]) => s.id === Be.id && !(o != null && o.fromFindReplace))
184
184
  ).subscribe(() => {
185
185
  const s = this._workbook.getActiveSheet();
186
186
  if (!s)
@@ -189,11 +189,11 @@ let W = class extends Be {
189
189
  this._matchesByWorksheet.has(o) && this._findNextMatchOnActiveSheetChange(s);
190
190
  })
191
191
  ), this.disposeWithMe(
192
- U(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(
192
+ P(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(
193
193
  k(
194
194
  ([s]) => s.type === B.MUTATION && s.params.unitId === this._workbook.getUnitId()
195
195
  ),
196
- je(600, void 0, { leading: !1, trailing: !0 })
196
+ De(600, void 0, { leading: !1, trailing: !0 })
197
197
  ).subscribe(() => r())
198
198
  ), r(), i;
199
199
  }
@@ -203,7 +203,7 @@ let W = class extends Be {
203
203
  */
204
204
  _findNextMatchOnActiveSheetChange(e) {
205
205
  let t, i, n = 0;
206
- const r = this._matchesByWorksheet.get(e.getSheetId()), s = this._selectionManagerService.getSelections();
206
+ const r = this._matchesByWorksheet.get(e.getSheetId()), s = this._workbookSelections.getCurrentSelections();
207
207
  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);
208
208
  }
209
209
  /**
@@ -214,27 +214,27 @@ let W = class extends Be {
214
214
  findInActiveWorksheet(e) {
215
215
  const t = this._workbook.getUnitId(), i = () => {
216
216
  var d;
217
- const a = this._workbook.getActiveSheet();
218
- if (!a) return !1;
219
- const l = this._selectionManagerService.getSelections();
220
- return (d = l == null ? void 0 : l.some((g) => !Je(g, a))) != null ? d : !1;
217
+ const c = this._workbook.getActiveSheet();
218
+ if (!c) return !1;
219
+ const l = this._workbookSelections.getCurrentSelections();
220
+ return (d = l == null ? void 0 : l.some((u) => !Ge(u, c))) != null ? d : !1;
221
221
  };
222
222
  let n, r = !0, s = !1;
223
223
  const o = () => {
224
- const a = this._workbook.getActiveSheet();
225
- if (!a) return { results: [] };
224
+ const c = this._workbook.getActiveSheet();
225
+ if (!c) return { results: [] };
226
226
  const l = this.currentMatch;
227
227
  s = i();
228
- const c = this._selectionManagerService.getSelections(), d = s ? this._findInSelections(a, c, e, t) : this._findInWorksheet(a, e, t);
228
+ const a = this._workbookSelections.getCurrentSelections(), d = s ? this._findInSelections(c, a, e, t) : this._findInWorksheet(c, e, t);
229
229
  return this._matches = d.results, this._matchesPosition = this._tryRestoreLastMatchesPosition(l, this._matches), r ? (n = d, r = !1) : this._matchesUpdate$.next(this._matches), this._updateFindHighlight(), d;
230
230
  };
231
231
  return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(() => this._updateFindHighlight())), this.disposeWithMe(
232
- Ve(
233
- U(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(
234
- k(([a]) => {
235
- if (a.type === B.MUTATION && a.params.unitId === this._workbook.getUnitId())
232
+ $e(
233
+ P(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(
234
+ k(([c]) => {
235
+ if (c.type === B.MUTATION && c.params.unitId === this._workbook.getUnitId())
236
236
  return !0;
237
- if (a.id === Oe.id && a.params.unitId === t) {
237
+ if (c.id === We.id && c.params.unitId === t) {
238
238
  const l = i();
239
239
  return l === !1 && s === !1 ? !1 : (s = l, !0);
240
240
  }
@@ -242,34 +242,34 @@ let W = class extends Be {
242
242
  })
243
243
  ),
244
244
  // activeSheet$ is a BehaviorSubject, so we need to skip the first
245
- this._workbook.activeSheet$.pipe(Qe(1))
246
- ).pipe(Xe(200)).subscribe(() => o())
245
+ this._workbook.activeSheet$.pipe(Le(1))
246
+ ).pipe(je(200)).subscribe(() => o())
247
247
  ), o(), n;
248
248
  }
249
249
  _findInRange(e, t, i, n, r) {
250
- const s = [], o = e.getSheetId(), a = (t.findDirection === w.COLUMN ? e.iterateByColumn : e.iterateByRow).bind(e)(i);
251
- for (const l of a) {
252
- const { row: c, col: d, colSpan: g, rowSpan: S, value: m } = l;
253
- if (r != null && r(c, d) || !m || e.getRowFiltered(c))
250
+ const s = [], o = e.getSheetId(), c = (t.findDirection === w.COLUMN ? e.iterateByColumn : e.iterateByRow).bind(e)(i);
251
+ for (const l of c) {
252
+ const { row: a, col: d, colSpan: u, rowSpan: _, value: m } = l;
253
+ if (r != null && r(a, d) || !m || e.getRowFiltered(a))
254
254
  continue;
255
- const { hit: p, replaceable: R, isFormula: v } = it(e, c, d, t, m);
255
+ const { hit: p, replaceable: R, isFormula: v } = qe(e, a, d, t, m);
256
256
  if (p) {
257
- const b = {
258
- provider: et,
257
+ const y = {
258
+ provider: Je,
259
259
  unitId: n,
260
260
  replaceable: R,
261
261
  isFormula: v,
262
262
  range: {
263
263
  subUnitId: o,
264
264
  range: {
265
- startRow: c,
265
+ startRow: a,
266
266
  startColumn: d,
267
- endColumn: d + (g != null ? g : 1) - 1,
268
- endRow: c + (S != null ? S : 1) - 1
267
+ endColumn: d + (u != null ? u : 1) - 1,
268
+ endRow: a + (_ != null ? _ : 1) - 1
269
269
  }
270
270
  }
271
271
  };
272
- s.push(b);
272
+ s.push(y);
273
273
  }
274
274
  }
275
275
  return { results: s };
@@ -281,11 +281,11 @@ let W = class extends Be {
281
281
  i,
282
282
  l.range,
283
283
  n,
284
- (c, d) => {
285
- const g = `${c}-${d}`;
286
- return o.has(g) ? !0 : (o.add(g), !1);
284
+ (a, d) => {
285
+ const u = `${a}-${d}`;
286
+ return o.has(u) ? !0 : (o.add(u), !1);
287
287
  }
288
- ).results).flat().sort((l, c) => s(l.range.range, c.range.range) ? -1 : 1) };
288
+ ).results).flat().sort((l, a) => s(l.range.range, a.range.range) ? -1 : 1) };
289
289
  }
290
290
  /** Find matches in a given worksheet. */
291
291
  _findInWorksheet(e, t, i) {
@@ -299,31 +299,31 @@ let W = class extends Be {
299
299
  }), this._highlightShapes = [], (e = this._currentHighlightShape) == null || e.dispose(), this._currentHighlightShape = null;
300
300
  }
301
301
  _updateFindHighlight() {
302
- var S, m;
302
+ var d;
303
303
  this._disposeHighlights();
304
- const e = (S = this._sheetSkeletonManagerService.getCurrent()) == null ? void 0 : S.skeleton;
305
- if (!e || !this._getSheetObject() || ((m = this._univerInstanceService.getFocusedUnit()) == null ? void 0 : m.getUnitId()) !== this._workbook.getUnitId())
304
+ const e = (d = this._sheetSkeletonManagerService.getCurrent()) == null ? void 0 : d.skeleton;
305
+ if (!e)
306
306
  return;
307
- const n = this._workbook.getUnitId(), r = this._renderManagerService.getRenderById(n);
308
- if (r == null)
307
+ const t = this._workbook.getUnitId(), i = this._renderManagerService.getRenderById(t);
308
+ if (i == null)
309
309
  return;
310
- const { scene: s } = r, o = this._matches, a = this._themeService.getCurrentTheme().gold400, l = new Re(a).toRgb(), c = this._workbook.getActiveSheet();
310
+ const { scene: n } = i, r = this._matches, s = this._themeService.getCurrentTheme().gold400, o = new ve(s).toRgb(), c = this._workbook.getActiveSheet();
311
311
  if (!c)
312
312
  return;
313
- const d = c.getSheetId(), g = o.filter((p) => p.range.subUnitId === d).map((p, R) => {
314
- const { startColumn: v, startRow: b, endColumn: se, endRow: re } = p.range.range, oe = j(b, v, s, e), he = j(re, se, s, e), { startX: E, startY: A } = oe, { endX: ce, endY: ae } = he, N = !c.getRowRawVisible(b), D = !c.getColVisible(v), le = N || D, de = D ? 2 : ce - E, ue = N ? 2 : ae - A, ge = {
313
+ const l = c.getSheetId(), a = r.filter((u) => u.range.subUnitId === l).map((u, _) => {
314
+ const { startColumn: m, startRow: p, endColumn: R, endRow: v } = u.range.range, y = j(p, m, n, e), se = j(v, R, n, e), { startX: E, startY: A } = y, { endX: re, endY: oe } = se, N = !c.getRowRawVisible(p), D = !c.getColVisible(m), he = N || D, ce = D ? 2 : re - E, ae = N ? 2 : oe - A, le = {
315
315
  left: E,
316
316
  top: A,
317
- color: l,
318
- width: de,
319
- height: ue,
317
+ color: o,
318
+ width: ce,
319
+ height: ae,
320
320
  evented: !1,
321
- inHiddenRange: le,
322
- zIndex: tt
321
+ inHiddenRange: he,
322
+ zIndex: Ze
323
323
  };
324
- return new Ye(`find-highlight-${R}`, ge);
324
+ return new Ve(`find-highlight-${_}`, le);
325
325
  });
326
- s.addObjects(g), this._highlightShapes = g, s.makeDirty();
326
+ n.addObjects(a), this._highlightShapes = a, n.makeDirty();
327
327
  }
328
328
  _updateCurrentHighlightShape(e) {
329
329
  var t;
@@ -335,17 +335,17 @@ let W = class extends Be {
335
335
  }
336
336
  }
337
337
  _getSheetObject() {
338
- return $e(this._univerInstanceService, this._renderManagerService);
338
+ return Ae(this._univerInstanceService, this._renderManagerService);
339
339
  }
340
340
  _focusMatch(e) {
341
341
  var i;
342
342
  const t = e.range.subUnitId;
343
- t !== ((i = this._workbook.getActiveSheet()) == null ? void 0 : i.getSheetId()) && this._commandService.syncExecuteCommand(
344
- Te.id,
343
+ t !== ((i = this._workbook.getActiveSheet()) == null ? void 0 : i.getSheetId()) && this._commandService.executeCommand(
344
+ Fe.id,
345
345
  { unitId: this._workbook.getUnitId(), subUnitId: t },
346
346
  { fromFindReplace: !0 }
347
- ), this._commandService.syncExecuteCommand(
348
- Le.id,
347
+ ), this._commandService.executeCommand(
348
+ Ne.id,
349
349
  { range: e.range.range },
350
350
  { fromFindReplace: !0 }
351
351
  );
@@ -355,78 +355,80 @@ let W = class extends Be {
355
355
  const { subUnitId: i } = e.range, { startColumn: n, startRow: r } = e.range.range, s = t.findIndex((o) => {
356
356
  if (i !== o.range.subUnitId)
357
357
  return !1;
358
- const { startColumn: a, startRow: l } = o.range.range;
359
- return a === n && l === r;
358
+ const { startColumn: c, startRow: l } = o.range.range;
359
+ return c === n && l === r;
360
360
  });
361
361
  return s > -1 ? s + 1 : 0;
362
362
  }
363
363
  moveToNextMatch(e) {
364
- var s, o, a, l;
364
+ var o, c, l, a, d;
365
365
  if (!this._matches.length)
366
366
  return null;
367
- const t = (s = e == null ? void 0 : e.loop) != null ? s : !1, i = (o = e == null ? void 0 : e.stayIfOnMatch) != null ? o : !1, n = (a = e == null ? void 0 : e.noFocus) != null ? a : !1, r = this._findNextMatch(t, i);
368
- if (r) {
369
- const [c, d] = r;
370
- return this._matchesPosition = d + 1, this._query.findScope === I.UNIT ? this._activeHighlightIndex = this._matchesByWorksheet.get(c.range.subUnitId).findIndex((g) => g === c) : this._activeHighlightIndex = d, n || this._focusMatch(c), ((l = this._workbook.getActiveSheet()) == null ? void 0 : l.getSheetId()) === c.range.subUnitId && this._updateCurrentHighlightShape(this._activeHighlightIndex), c;
367
+ const t = (o = e == null ? void 0 : e.loop) != null ? o : !1, i = (c = e == null ? void 0 : e.stayIfOnMatch) != null ? c : !1, n = (l = e == null ? void 0 : e.noFocus) != null ? l : !1, r = (a = e == null ? void 0 : e.ignoreSelection) != null ? a : !1, s = this._findNextMatch(t, i, r);
368
+ if (s) {
369
+ const [u, _] = s;
370
+ return this._matchesPosition = _ + 1, this._query.findScope === I.UNIT ? this._activeHighlightIndex = this._matchesByWorksheet.get(u.range.subUnitId).findIndex((m) => m === u) : this._activeHighlightIndex = _, n || this._focusMatch(u), ((d = this._workbook.getActiveSheet()) == null ? void 0 : d.getSheetId()) === u.range.subUnitId && this._updateCurrentHighlightShape(this._activeHighlightIndex), u;
371
371
  }
372
372
  return this._matchesPosition = 0, this._updateCurrentHighlightShape(), null;
373
373
  }
374
374
  moveToPreviousMatch(e) {
375
- var s, o, a, l;
375
+ var o, c, l, a, d;
376
376
  if (!this._matches.length)
377
377
  return null;
378
- const t = (s = e == null ? void 0 : e.loop) != null ? s : !1, i = (o = e == null ? void 0 : e.stayIfOnMatch) != null ? o : !1, n = (a = e == null ? void 0 : e.noFocus) != null ? a : !1, r = this._findPreviousMatch(t, i);
379
- if (r) {
380
- const [c, d] = r;
381
- return this._matchesPosition = d + 1, this._query.findScope === I.UNIT ? this._activeHighlightIndex = this._matchesByWorksheet.get(c.range.subUnitId).findIndex((g) => g === c) : this._activeHighlightIndex = d, n || this._focusMatch(c), ((l = this._workbook.getActiveSheet()) == null ? void 0 : l.getSheetId()) === c.range.subUnitId && this._updateCurrentHighlightShape(this._activeHighlightIndex), c;
378
+ const t = (o = e == null ? void 0 : e.loop) != null ? o : !1, i = (c = e == null ? void 0 : e.stayIfOnMatch) != null ? c : !1, n = (l = e == null ? void 0 : e.noFocus) != null ? l : !1, r = (a = e == null ? void 0 : e.ignoreSelection) != null ? a : !1, s = this._findPreviousMatch(t, i, r);
379
+ if (s) {
380
+ const [u, _] = s;
381
+ return this._matchesPosition = _ + 1, this._query.findScope === I.UNIT ? this._activeHighlightIndex = this._matchesByWorksheet.get(u.range.subUnitId).findIndex((m) => m === u) : this._activeHighlightIndex = _, n || this._focusMatch(u), ((d = this._workbook.getActiveSheet()) == null ? void 0 : d.getSheetId()) === u.range.subUnitId && this._updateCurrentHighlightShape(this._activeHighlightIndex), u;
382
382
  }
383
383
  return this._matchesPosition = 0, this._updateCurrentHighlightShape(), null;
384
384
  }
385
- _findPreviousMatch(e = !1, t = !1) {
386
- var s;
385
+ _findPreviousMatch(e = !1, t = !1, i = !1) {
386
+ var o;
387
387
  if (this.currentMatch) {
388
- const o = this._matches.findIndex((d) => d === this.currentMatch);
388
+ const c = this._matches.findIndex((u) => u === this.currentMatch);
389
389
  if (t)
390
- return [this.currentMatch, o];
391
- const a = o - 1;
392
- if (!e && a < 0)
390
+ return [this.currentMatch, c];
391
+ const l = c - 1;
392
+ if (!e && l < 0)
393
393
  return null;
394
- const l = this._matches.length, c = (a + l) % l;
394
+ const a = this._matches.length, d = (l + a) % a;
395
+ return [this._matches[d], d];
396
+ }
397
+ const n = this._workbookSelections.getCurrentLastSelection();
398
+ if (i || !n) {
399
+ const c = this._matches.length - 1;
395
400
  return [this._matches[c], c];
396
401
  }
397
- const i = this._selectionManagerService.getSelections();
398
- if (!(i != null && i.length))
399
- return [this._matches[0], 0];
400
402
  if (this._query.findScope !== I.UNIT)
401
- return this._findPreviousMatchByRange(this._matches, i[0].range);
402
- const n = (s = this._workbook.getActiveSheet()) == null ? void 0 : s.getSheetId();
403
- if (!n)
403
+ return this._findPreviousMatchByRange(this._matches, n.range);
404
+ const r = (o = this._workbook.getActiveSheet()) == null ? void 0 : o.getSheetId();
405
+ if (!r)
404
406
  return null;
405
- const r = this._findPreviousWorksheetThatHasAMatch(n, e);
406
- return r ? this._findPreviousMatchByRange(this._matchesByWorksheet.get(r), i[0].range) : null;
407
+ const s = this._findPreviousWorksheetThatHasAMatch(r, e);
408
+ return s ? this._findPreviousMatchByRange(this._matchesByWorksheet.get(s), n.range) : null;
407
409
  }
408
- _findNextMatch(e = !1, t = !1) {
409
- var s;
410
+ _findNextMatch(e = !1, t = !1, i = !1) {
411
+ var o;
410
412
  if (this.currentMatch) {
411
- const o = this._matches.findIndex((d) => d === this.currentMatch);
413
+ const c = this._matches.findIndex((u) => u === this.currentMatch);
412
414
  if (t)
413
- return [this.currentMatch, o];
414
- const a = o + 1, l = this._matches.length;
415
- if (!e && a >= l)
415
+ return [this.currentMatch, c];
416
+ const l = c + 1, a = this._matches.length;
417
+ if (!e && l >= a)
416
418
  return null;
417
- const c = a % l;
418
- return [this._matches[c], c];
419
+ const d = l % a;
420
+ return [this._matches[d], d];
419
421
  }
420
- const i = this._selectionManagerService.getSelections();
421
- if (!(i != null && i.length))
422
+ const n = this._workbookSelections.getCurrentLastSelection();
423
+ if (i || !n)
422
424
  return [this._matches[0], 0];
423
425
  if (this._query.findScope !== I.UNIT)
424
- return this._findNextMatchByRange(this._matches, i[0].range, t);
425
- const n = (s = this._workbook.getActiveSheet()) == null ? void 0 : s.getSheetId();
426
- if (!n)
426
+ return this._findNextMatchByRange(this._matches, n.range, t);
427
+ const r = (o = this._workbook.getActiveSheet()) == null ? void 0 : o.getSheetId();
428
+ if (!r)
427
429
  return null;
428
- const r = this._findNextWorksheetThatHasAMatch(n, e);
429
- return r ? this._findNextMatchByRange(this._matchesByWorksheet.get(r), i[0].range) : null;
430
+ const s = this._findNextWorksheetThatHasAMatch(r, e);
431
+ return s ? this._findNextMatchByRange(this._matchesByWorksheet.get(s), n.range) : null;
430
432
  }
431
433
  _findPreviousWorksheetThatHasAMatch(e, t = !1) {
432
434
  const i = this._workbook.getSheetOrders(), n = i.findIndex((o) => o === e), s = (t ? $(i, n + 1) : i.slice(0, n + 1)).findLast((o) => this._matchesByWorksheet.has(o));
@@ -439,11 +441,11 @@ let W = class extends Be {
439
441
  _findNextMatchByRange(e, t, i = !1) {
440
442
  const n = this._query.findDirection === w.ROW;
441
443
  let r = e.findIndex((o) => {
442
- const a = o.range.range;
443
- if (!(n ? X(t, a) : Y(t, a)))
444
+ const c = o.range.range;
445
+ if (!(n ? X(t, c) : Y(t, c)))
444
446
  return !1;
445
- const c = Q(t, a);
446
- return i ? c : !c;
447
+ const a = Q(t, c);
448
+ return i ? a : !a;
447
449
  });
448
450
  r === -1 && (r = e.length - 1);
449
451
  const s = e[r];
@@ -452,11 +454,11 @@ let W = class extends Be {
452
454
  _findPreviousMatchByRange(e, t, i = !1) {
453
455
  const n = this._query.findDirection === w.ROW;
454
456
  let r = this._matches.findLastIndex((o) => {
455
- const a = o.range.range;
456
- if (!(n ? Ke(t, a) : ze(t, a)))
457
+ const c = o.range.range;
458
+ if (!(n ? Xe(t, c) : Ye(t, c)))
457
459
  return !1;
458
- const c = Q(t, a);
459
- return i ? c : !c;
460
+ const a = Q(t, c);
461
+ return i ? a : !a;
460
462
  });
461
463
  r === -1 && (r = 0);
462
464
  const s = e[r];
@@ -468,7 +470,7 @@ let W = class extends Be {
468
470
  const t = this.currentMatch.range, i = this._workbook.getSheetBySheetId(this.currentMatch.range.subUnitId), n = this._getReplacedCellData(
469
471
  this.currentMatch,
470
472
  i,
471
- this._query.findBy === M.FORMULA,
473
+ this._query.findBy === b.FORMULA,
472
474
  this._query.findString,
473
475
  e,
474
476
  this._query.caseSensitive ? "g" : "ig"
@@ -486,41 +488,41 @@ let W = class extends Be {
486
488
  async replaceAll(e) {
487
489
  if (this._matchesCount === 0 || !this._query)
488
490
  return { success: 0, failure: 0 };
489
- const t = this._workbook.getUnitId(), { findString: i, caseSensitive: n, findBy: r } = this._query, s = r === M.FORMULA, o = n ? "g" : "ig", a = [];
490
- return be(this._matches.filter((c) => c.replaceable), (c) => c.range.subUnitId).forEach((c, d) => {
491
- const g = new we(), S = this._workbook.getSheetBySheetId(d);
492
- c.forEach((m) => {
493
- const { startColumn: p, startRow: R } = m.range.range, v = this._getReplacedCellData(m, S, s, i, e, o);
494
- v && g.setValue(R, p, v);
495
- }), a.push({
496
- count: c.length,
491
+ const t = this._workbook.getUnitId(), { findString: i, caseSensitive: n, findBy: r } = this._query, s = r === b.FORMULA, o = n ? "g" : "ig", c = [];
492
+ return Ie(this._matches.filter((a) => a.replaceable), (a) => a.range.subUnitId).forEach((a, d) => {
493
+ const u = new Ce(), _ = this._workbook.getSheetBySheetId(d);
494
+ a.forEach((m) => {
495
+ const { startColumn: p, startRow: R } = m.range.range, v = this._getReplacedCellData(m, _, s, i, e, o);
496
+ v && u.setValue(R, p, v);
497
+ }), c.push({
498
+ count: a.length,
497
499
  subUnitId: d,
498
- value: g.getMatrix()
500
+ value: u.getMatrix()
499
501
  });
500
- }), a ? this._commandService.executeCommand(te.id, {
502
+ }), c ? this._commandService.executeCommand(te.id, {
501
503
  unitId: t,
502
- replacements: a
504
+ replacements: c
503
505
  }) : { success: 0, failure: 0 };
504
506
  }
505
507
  _getReplacedCellData(e, t, i, n, r, s) {
506
- var S;
507
- const o = e.range.range, { startRow: a, startColumn: l } = o, c = t.getCellRaw(a, l);
508
+ var _;
509
+ const o = e.range.range, { startRow: c, startColumn: l } = o, a = t.getCellRaw(c, l);
508
510
  if (e.isFormula)
509
- return i ? { f: c.f.replace(new RegExp(G(n), s), r), v: null } : null;
510
- if (!!((S = c.p) != null && S.body)) {
511
- const m = Me.deepClone(c.p);
512
- return ke(m.body, n, r), { p: m };
511
+ return i ? { f: a.f.replace(new RegExp(G(n), s), r), v: null } : null;
512
+ if (!!((_ = a.p) != null && _.body)) {
513
+ const m = Re.deepClone(a.p);
514
+ return we(m.body, n, r), { p: m };
513
515
  }
514
- return { v: c.v.toString().replace(new RegExp(G(n), s), r) };
516
+ return { v: a.v.toString().replace(new RegExp(G(n), s), r) };
515
517
  }
516
518
  };
517
- W = T([
518
- _(2, J),
519
- _(3, ee),
520
- _(4, H),
521
- _(5, z),
522
- _(6, C(Ie)),
523
- _(7, C(Fe))
519
+ W = O([
520
+ S(2, J),
521
+ S(3, ee),
522
+ S(4, H),
523
+ S(5, z),
524
+ S(6, C(Se)),
525
+ S(7, C(Ue))
524
526
  ], W);
525
527
  function G(h) {
526
528
  return h.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
@@ -531,19 +533,16 @@ let F = class extends K {
531
533
  /**
532
534
  * Hold all find results in this kind of univer business instances (Workbooks).
533
535
  */
534
- f(this, "_findModelsByUnitId", /* @__PURE__ */ new Map());
536
+ g(this, "_findModelsByUnitId", /* @__PURE__ */ new Map());
535
537
  this._univerInstanceService = e, this._renderManagerService = t, this._injector = i;
536
538
  }
537
539
  async find(e) {
538
540
  this._terminate();
539
- const t = this._univerInstanceService.getCurrentUnitForType(Z.UNIVER_SHEET), i = this._renderManagerService.getRenderById(t.getUnitId()).with(De);
540
- if (t) {
541
- const n = this._injector.createInstance(W, t, i);
542
- this._findModelsByUnitId.set(t.getUnitId(), n);
543
- const r = this._preprocessQuery(e);
544
- return n.start(r), [n];
545
- }
546
- return [];
541
+ const t = this._univerInstanceService.getAllUnitsForType(Z.UNIVER_SHEET), i = this._preprocessQuery(e);
542
+ return t.map((r) => {
543
+ const s = this._renderManagerService.getRenderById(r.getUnitId()).with(Ee), o = this._injector.createInstance(W, r, s);
544
+ return this._findModelsByUnitId.set(r.getUnitId(), o), o.start(i), o;
545
+ });
547
546
  }
548
547
  terminate() {
549
548
  this._terminate();
@@ -564,50 +563,50 @@ let F = class extends K {
564
563
  };
565
564
  }
566
565
  };
567
- F = T([
568
- _(0, J),
569
- _(1, ee),
570
- _(2, C(O))
566
+ F = O([
567
+ S(0, J),
568
+ S(1, ee),
569
+ S(2, C(T))
571
570
  ], F);
572
- const u = { hit: !1, replaceable: !1, isFormula: !1, rawData: null };
573
- function it(h, e, t, i, n) {
574
- const { findBy: r } = i, s = r === M.FORMULA, o = h.getCellRaw(e, t);
575
- return u.rawData = o, !(o != null && o.f) ? (u.isFormula = !1, P(n, i) ? o ? (u.hit = !0, u.replaceable = !0) : (u.hit = !0, u.replaceable = !1) : (u.hit = !1, u.replaceable = !1), u) : (u.isFormula = !0, s ? P({ v: o.f }, i) ? (u.hit = !0, u.replaceable = !0, u) : (u.hit = !1, u.replaceable = !1, u) : (u.replaceable = !1, P(n, i) ? u.hit = !0 : u.hit = !1, u));
571
+ const f = { hit: !1, replaceable: !1, isFormula: !1, rawData: null };
572
+ function qe(h, e, t, i, n) {
573
+ const { findBy: r } = i, s = r === b.FORMULA, o = h.getCellRaw(e, t);
574
+ return f.rawData = o, !(o != null && o.f) ? (f.isFormula = !1, U(n, i) ? o ? (f.hit = !0, f.replaceable = !0) : (f.hit = !0, f.replaceable = !1) : (f.hit = !1, f.replaceable = !1), f) : (f.isFormula = !0, s ? U({ v: o.f }, i) ? (f.hit = !0, f.replaceable = !0, f) : (f.hit = !1, f.replaceable = !1, f) : (f.replaceable = !1, U(n, i) ? f.hit = !0 : f.hit = !1, f));
576
575
  }
577
- function P(h, e) {
578
- let t = nt(h);
579
- return t ? e.matchesTheWholeCell ? (t = st(t), e.caseSensitive ? t === e.findString : t.toLowerCase() === e.findString) : e.caseSensitive ? t.indexOf(e.findString) > -1 : t.toLowerCase().indexOf(e.findString) > -1 : !1;
576
+ function U(h, e) {
577
+ let t = et(h);
578
+ return t ? e.matchesTheWholeCell ? (t = tt(t), e.caseSensitive ? t === e.findString : t.toLowerCase() === e.findString) : e.caseSensitive ? t.indexOf(e.findString) > -1 : t.toLowerCase().indexOf(e.findString) > -1 : !1;
580
579
  }
581
- function nt(h) {
580
+ function et(h) {
582
581
  var t, i, n;
583
582
  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;
584
583
  return typeof e == "number" ? `${e}` : typeof e == "boolean" ? e ? "1" : "0" : e;
585
584
  }
586
- function st(h) {
585
+ function tt(h) {
587
586
  return h.replace(/^ +/g, "").replace(/ +$/g, "");
588
587
  }
589
- var ie = Object.defineProperty, rt = Object.getOwnPropertyDescriptor, ot = (h, e, t) => e in h ? ie(h, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : h[e] = t, ht = (h, e, t, i) => {
590
- for (var n = i > 1 ? void 0 : i ? rt(e, t) : e, r = h.length - 1, s; r >= 0; r--)
588
+ var ie = Object.defineProperty, it = Object.getOwnPropertyDescriptor, nt = (h, e, t) => e in h ? ie(h, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : h[e] = t, st = (h, e, t, i) => {
589
+ for (var n = i > 1 ? void 0 : i ? it(e, t) : e, r = h.length - 1, s; r >= 0; r--)
591
590
  (s = h[r]) && (n = (i ? s(e, t, n) : s(n)) || n);
592
591
  return i && n && ie(e, t, n), n;
593
- }, ct = (h, e) => (t, i) => e(t, i, h), ne = (h, e, t) => ot(h, typeof e != "symbol" ? e + "" : e, t);
594
- const at = "SHEET_FIND_REPLACE_PLUGIN";
595
- let y = class extends ye {
592
+ }, rt = (h, e) => (t, i) => e(t, i, h), ne = (h, e, t) => nt(h, typeof e != "symbol" ? e + "" : e, t);
593
+ const ot = "SHEET_FIND_REPLACE_PLUGIN";
594
+ let x = class extends ke {
596
595
  constructor(h, e) {
597
596
  super(), this._injector = e;
598
597
  }
599
598
  onStarting(h) {
600
- [[x]].forEach((e) => h.add(e));
599
+ [[M]].forEach((e) => h.add(e));
601
600
  }
602
601
  };
603
- ne(y, "pluginName", at);
604
- ne(y, "type", Z.UNIVER_SHEET);
605
- y = ht([
606
- xe(L, L, We),
607
- ct(1, C(O))
608
- ], y);
602
+ ne(x, "pluginName", ot);
603
+ ne(x, "type", Z.UNIVER_SHEET);
604
+ x = st([
605
+ be(L, L, Pe),
606
+ rt(1, C(T))
607
+ ], x);
609
608
  export {
610
609
  te as SheetReplaceCommand,
611
- x as SheetsFindReplaceController,
612
- y as UniverSheetsFindReplacePlugin
610
+ M as SheetsFindReplaceController,
611
+ x as UniverSheetsFindReplacePlugin
613
612
  };
@@ -0,0 +1,8 @@
1
+ {
2
+ "sheet-find-replace": {
3
+ "replace": {
4
+ "partial-failure": "Thay thế một phần ô thất bại",
5
+ "failure": "Thay thế thất bại"
6
+ }
7
+ }
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "sheet-find-replace": {
3
+ "replace": {
4
+ "partial-failure": "部分單元格替換失敗",
5
+ "failure": "替換失敗"
6
+ }
7
+ }
8
+ }
@@ -1,9 +1,8 @@
1
- import { Disposable, ICommandService, IContextService, IUniverInstanceService, ThemeService, ICellData, IRange, Nullable, Workbook, Worksheet } from '@univerjs/core';
1
+ import { ICellData, IDisposable, IRange, Nullable, Workbook, Worksheet, Disposable, ICommandService, IContextService, Injector, IUniverInstanceService, ThemeService } from '@univerjs/core';
2
2
  import { IRenderManagerService } from '@univerjs/engine-render';
3
3
  import { IFindComplete, IFindMatch, IFindMoveParams, IFindQuery, IReplaceAllResult, FindModel, FindReplaceController, IFindReplaceService } from '@univerjs/find-replace';
4
- import { SelectionManagerService } from '@univerjs/sheets';
4
+ import { SheetsSelectionsService } from '@univerjs/sheets';
5
5
  import { SheetSkeletonManagerService } from '@univerjs/sheets-ui';
6
- import { IDisposable, Injector } from '@wendellhu/redi';
7
6
 
8
7
  export declare class SheetsFindReplaceController extends Disposable implements IDisposable {
9
8
  private readonly _injector;
@@ -39,7 +38,6 @@ export declare class SheetFindModel extends FindModel {
39
38
  private readonly _commandService;
40
39
  private readonly _contextService;
41
40
  private readonly _themeService;
42
- private readonly _selectionManagerService;
43
41
  private readonly _matchesUpdate$;
44
42
  readonly matchesUpdate$: import('rxjs').Observable<ISheetCellMatch[]>;
45
43
  private readonly _activelyChangingMatch$;
@@ -60,7 +58,8 @@ export declare class SheetFindModel extends FindModel {
60
58
  get matchesCount(): number;
61
59
  get matchesPosition(): number;
62
60
  get currentMatch(): Nullable<ISheetCellMatch>;
63
- constructor(_workbook: Workbook, _sheetSkeletonManagerService: SheetSkeletonManagerService, _univerInstanceService: IUniverInstanceService, _renderManagerService: IRenderManagerService, _commandService: ICommandService, _contextService: IContextService, _themeService: ThemeService, _selectionManagerService: SelectionManagerService);
61
+ private _workbookSelections;
62
+ constructor(_workbook: Workbook, _sheetSkeletonManagerService: SheetSkeletonManagerService, _univerInstanceService: IUniverInstanceService, _renderManagerService: IRenderManagerService, _commandService: ICommandService, _contextService: IContextService, _themeService: ThemeService, _selectionManagerService: SheetsSelectionsService);
64
63
  dispose(): void;
65
64
  getMatches(): IFindMatch[];
66
65
  start(query: IFindQuery): void;
@@ -0,0 +1,4 @@
1
+ import { default as zhCN } from './zh-CN';
2
+
3
+ declare const locale: typeof zhCN;
4
+ export default locale;
@@ -0,0 +1,4 @@
1
+ import { default as zhCN } from './zh-CN';
2
+
3
+ declare const locale: typeof zhCN;
4
+ export default locale;
@@ -1,5 +1,4 @@
1
- import { Plugin, UniverInstanceType } from '@univerjs/core';
2
- import { Injector } from '@wendellhu/redi';
1
+ import { Injector, Plugin, UniverInstanceType } from '@univerjs/core';
3
2
 
4
3
  export declare class UniverSheetsFindReplacePlugin extends Plugin {
5
4
  protected readonly _injector: Injector;
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(u,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("@univerjs/find-replace"),require("@univerjs/sheets"),require("@univerjs/engine-render"),require("@univerjs/sheets-ui"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","@univerjs/find-replace","@univerjs/sheets","@univerjs/engine-render","@univerjs/sheets-ui","rxjs"],l):(u=typeof globalThis<"u"?globalThis:u||self,l(u.UniverSheetsFindReplace={},u.UniverCore,u["@wendellhu/redi"],u.UniverFindReplace,u.UniverSheets,u.UniverEngineRender,u.UniverSheetsUi,u.rxjs))})(this,function(u,l,v,S,w,k,y,R){"use strict";var ve=Object.defineProperty;var Ie=(u,l,v)=>l in u?ve(u,l,{enumerable:!0,configurable:!0,writable:!0,value:v}):u[l]=v;var m=(u,l,v)=>Ie(u,typeof l!="symbol"?l+"":l,v);class q extends k.Shape{constructor(t,n){super(t,n);m(this,"_activated",!1);m(this,"_inHiddenRange",!1);m(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})`;k.Rect.drawWith(t,{width:this.width,height:this.height,fill:i,stroke:n?r:void 0,strokeWidth:n?2:0,evented:!1})}}const x={id:"sheet.command.replace",type:l.CommandType.COMMAND,handler:async(h,e)=>{const t=h.get(l.IUndoRedoService),n=h.get(l.ICommandService),{unitId:i,replacements:r}=e,s=t.__tempBatchingUndoRedo(i),o=await Promise.all(r.map(a=>n.executeCommand(w.SetRangeValuesCommand.id,{unitId:i,subUnitId:a.subUnitId,value:a.value})));return s.dispose(),Q(o,r)}};function Q(h,e){let t=0,n=0;return h.forEach((i,r)=>{const s=e[r].count;i?t+=s:n+=s}),{success:t,failure:n}}function H(h,e){return h.startRow===e.startRow&&h.startColumn===e.startColumn}function O(h,e){return h.startRow<e.startRow||h.startRow===e.startRow&&h.startColumn<=e.startColumn}function E(h,e){return h.startColumn<e.startColumn||h.startColumn===e.startColumn&&h.startRow<=e.startRow}function X(h,e){return h.startRow>e.startRow||h.startRow===e.startRow&&h.startColumn>=e.startColumn}function Y(h,e){return h.startColumn>e.startColumn||h.startColumn===e.startColumn&&h.startRow>=e.startRow}function G(h,e){const{range:t}=h,{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 K=Object.defineProperty,z=Object.getOwnPropertyDescriptor,P=(h,e,t,n)=>{for(var i=n>1?void 0:n?z(e,t):e,r=h.length-1,s;r>=0;r--)(s=h[r])&&(i=(n?s(e,t,i):s(i))||i);return n&&i&&K(e,t,i),i},I=(h,e)=>(t,n)=>e(t,n,h);u.SheetsFindReplaceController=class extends l.Disposable{constructor(t,n,i,r,s){super();m(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(W);this._provider=t,this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(t)),this.disposeWithMe(this._contextService.subscribeContextValue$(l.EDITOR_ACTIVATED).pipe(R.filter(n=>!!n)).subscribe(()=>this._findReplaceController.closePanel()))}_initCommands(){[x].forEach(t=>this.disposeWithMe(this._commandService.registerCommand(t)))}},u.SheetsFindReplaceController=P([l.OnLifecycle(l.LifecycleStages.Steady,u.SheetsFindReplaceController),I(0,v.Inject(v.Injector)),I(1,v.Inject(S.FindReplaceController)),I(2,l.IContextService),I(3,S.IFindReplaceService),I(4,l.ICommandService)],u.SheetsFindReplaceController);const J="sheets-find-replace-provider",Z=1e4;let B=class extends S.FindModel{constructor(e,t,n,i,r,s,o,a){super();m(this,"_matchesUpdate$",new R.Subject);m(this,"matchesUpdate$",this._matchesUpdate$.asObservable());m(this,"_activelyChangingMatch$",new R.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);this._workbook=e,this._sheetSkeletonManagerService=t,this._univerInstanceService=n,this._renderManagerService=i,this._commandService=r,this._contextService=s,this._themeService=o,this._selectionManagerService=a}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}}_toggleDisplayRawFormula(e){this._contextService.setContextValue(k.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 a=this._findInWorksheet(o,e,t),d=o.getSheetId(),{results:c}=a;return c.length?this._matchesByWorksheet.set(d,a.results):this._matchesByWorksheet.delete(d),a});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.onCommandExecuted)).pipe(R.filter(([s,o])=>s.id===w.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(R.filter(([s])=>s.type===l.CommandType.MUTATION&&s.params.unitId===this._workbook.getUnitId()),R.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._selectionManagerService.getSelections();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 g;const a=this._workbook.getActiveSheet();if(!a)return!1;const d=this._selectionManagerService.getSelections();return(g=d==null?void 0:d.some(f=>!G(f,a)))!=null?g:!1};let i,r=!0,s=!1;const o=()=>{const a=this._workbook.getActiveSheet();if(!a)return{results:[]};const d=this.currentMatch;s=n();const c=this._selectionManagerService.getSelections(),g=s?this._findInSelections(a,c,e,t):this._findInWorksheet(a,e,t);return this._matches=g.results,this._matchesPosition=this._tryRestoreLastMatchesPosition(d,this._matches),r?(i=g,r=!1):this._matchesUpdate$.next(this._matches),this._updateFindHighlight(),g};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>this._updateFindHighlight())),this.disposeWithMe(R.merge(l.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(R.filter(([a])=>{if(a.type===l.CommandType.MUTATION&&a.params.unitId===this._workbook.getUnitId())return!0;if(a.id===w.SetSelectionsOperation.id&&a.params.unitId===t){const d=n();return d===!1&&s===!1?!1:(s=d,!0)}return!1})),this._workbook.activeSheet$.pipe(R.skip(1))).pipe(R.debounceTime(200)).subscribe(()=>o())),o(),i}_findInRange(e,t,n,i,r){const s=[],o=e.getSheetId(),a=(t.findDirection===S.FindDirection.COLUMN?e.iterateByColumn:e.iterateByRow).bind(e)(n);for(const d of a){const{row:c,col:g,colSpan:f,rowSpan:C,value:p}=d;if(r!=null&&r(c,g)||!p||e.getRowFiltered(c))continue;const{hit:b,replaceable:U,isFormula:M}=ee(e,c,g,t,p);if(b){const F={provider:J,unitId:i,replaceable:U,isFormula:M,range:{subUnitId:o,range:{startRow:c,startColumn:g,endColumn:g+(f!=null?f:1)-1,endRow:c+(C!=null?C:1)-1}}};s.push(F)}}return{results:s}}_findInSelections(e,t,n,i){const{findDirection:r}=n,s=r===S.FindDirection.ROW?O:E,o=new Set;return{results:t.map(d=>this._findInRange(e,n,d.range,i,(c,g)=>{const f=`${c}-${g}`;return o.has(f)?!0:(o.add(f),!1)}).results).flat().sort((d,c)=>s(d.range.range,c.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=>{t.getScene().makeDirty(),t.dispose()}),this._highlightShapes=[],(e=this._currentHighlightShape)==null||e.dispose(),this._currentHighlightShape=null}_updateFindHighlight(){var C,p;this._disposeHighlights();const e=(C=this._sheetSkeletonManagerService.getCurrent())==null?void 0:C.skeleton;if(!e||!this._getSheetObject()||((p=this._univerInstanceService.getFocusedUnit())==null?void 0:p.getUnitId())!==this._workbook.getUnitId())return;const i=this._workbook.getUnitId(),r=this._renderManagerService.getRenderById(i);if(r==null)return;const{scene:s}=r,o=this._matches,a=this._themeService.getCurrentTheme().gold400,d=new l.ColorKit(a).toRgb(),c=this._workbook.getActiveSheet();if(!c)return;const g=c.getSheetId(),f=o.filter(b=>b.range.subUnitId===g).map((b,U)=>{const{startColumn:M,startRow:F,endColumn:ce,endRow:ae}=b.range.range,le=y.getCoordByCell(F,M,s,e),de=y.getCoordByCell(ae,ce,s,e),{startX:j,startY:$}=le,{endX:ue,endY:ge}=de,L=!c.getRowRawVisible(F),V=!c.getColVisible(M),_e=L||V,fe=V?2:ue-j,Se=L?2:ge-$,me={left:j,top:$,color:d,width:fe,height:Se,evented:!1,inHiddenRange:_e,zIndex:Z};return new q(`find-highlight-${U}`,me)});s.addObjects(f),this._highlightShapes=f,s.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 y.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.syncExecuteCommand(w.SetWorksheetActivateCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:t},{fromFindReplace:!0}),this._commandService.syncExecuteCommand(y.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:a,startRow:d}=o.range.range;return a===i&&d===r});return s>-1?s+1:0}moveToNextMatch(e){var s,o,a,d;if(!this._matches.length)return null;const t=(s=e==null?void 0:e.loop)!=null?s:!1,n=(o=e==null?void 0:e.stayIfOnMatch)!=null?o:!1,i=(a=e==null?void 0:e.noFocus)!=null?a:!1,r=this._findNextMatch(t,n);if(r){const[c,g]=r;return this._matchesPosition=g+1,this._query.findScope===S.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(c.range.subUnitId).findIndex(f=>f===c):this._activeHighlightIndex=g,i||this._focusMatch(c),((d=this._workbook.getActiveSheet())==null?void 0:d.getSheetId())===c.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),c}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}moveToPreviousMatch(e){var s,o,a,d;if(!this._matches.length)return null;const t=(s=e==null?void 0:e.loop)!=null?s:!1,n=(o=e==null?void 0:e.stayIfOnMatch)!=null?o:!1,i=(a=e==null?void 0:e.noFocus)!=null?a:!1,r=this._findPreviousMatch(t,n);if(r){const[c,g]=r;return this._matchesPosition=g+1,this._query.findScope===S.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(c.range.subUnitId).findIndex(f=>f===c):this._activeHighlightIndex=g,i||this._focusMatch(c),((d=this._workbook.getActiveSheet())==null?void 0:d.getSheetId())===c.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),c}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}_findPreviousMatch(e=!1,t=!1){var s;if(this.currentMatch){const o=this._matches.findIndex(g=>g===this.currentMatch);if(t)return[this.currentMatch,o];const a=o-1;if(!e&&a<0)return null;const d=this._matches.length,c=(a+d)%d;return[this._matches[c],c]}const n=this._selectionManagerService.getSelections();if(!(n!=null&&n.length))return[this._matches[0],0];if(this._query.findScope!==S.FindScope.UNIT)return this._findPreviousMatchByRange(this._matches,n[0].range);const i=(s=this._workbook.getActiveSheet())==null?void 0:s.getSheetId();if(!i)return null;const r=this._findPreviousWorksheetThatHasAMatch(i,e);return r?this._findPreviousMatchByRange(this._matchesByWorksheet.get(r),n[0].range):null}_findNextMatch(e=!1,t=!1){var s;if(this.currentMatch){const o=this._matches.findIndex(g=>g===this.currentMatch);if(t)return[this.currentMatch,o];const a=o+1,d=this._matches.length;if(!e&&a>=d)return null;const c=a%d;return[this._matches[c],c]}const n=this._selectionManagerService.getSelections();if(!(n!=null&&n.length))return[this._matches[0],0];if(this._query.findScope!==S.FindScope.UNIT)return this._findNextMatchByRange(this._matches,n[0].range,t);const i=(s=this._workbook.getActiveSheet())==null?void 0:s.getSheetId();if(!i)return null;const r=this._findNextWorksheetThatHasAMatch(i,e);return r?this._findNextMatchByRange(this._matchesByWorksheet.get(r),n[0].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 a=o.range.range;if(!(i?O(t,a):E(t,a)))return!1;const c=H(t,a);return n?c:!c});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 a=o.range.range;if(!(i?X(t,a):Y(t,a)))return!1;const c=H(t,a);return n?c:!c});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(w.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",a=[];return l.groupBy(this._matches.filter(c=>c.replaceable),c=>c.range.subUnitId).forEach((c,g)=>{const f=new l.ObjectMatrix,C=this._workbook.getSheetBySheetId(g);c.forEach(p=>{const{startColumn:b,startRow:U}=p.range.range,M=this._getReplacedCellData(p,C,s,n,e,o);M&&f.setValue(U,b,M)}),a.push({count:c.length,subUnitId:g,value:f.getMatrix()})}),a?this._commandService.executeCommand(x.id,{unitId:t,replacements:a}):{success:0,failure:0}}_getReplacedCellData(e,t,n,i,r,s){var C;const o=e.range.range,{startRow:a,startColumn:d}=o,c=t.getCellRaw(a,d);if(e.isFormula)return n?{f:c.f.replace(new RegExp(A(i),s),r),v:null}:null;if(!!((C=c.p)!=null&&C.body)){const p=l.Tools.deepClone(c.p);return l.replaceInDocumentBody(p.body,i,r),{p}}return{v:c.v.toString().replace(new RegExp(A(i),s),r)}}};B=P([I(2,l.IUniverInstanceService),I(3,k.IRenderManagerService),I(4,l.ICommandService),I(5,l.IContextService),I(6,v.Inject(l.ThemeService)),I(7,v.Inject(w.SelectionManagerService))],B);function A(h){return h.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}let W=class extends l.Disposable{constructor(e,t,n){super();m(this,"_findModelsByUnitId",new Map);this._univerInstanceService=e,this._renderManagerService=t,this._injector=n}async find(e){this._terminate();const t=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),n=this._renderManagerService.getRenderById(t.getUnitId()).with(y.SheetSkeletonManagerService);if(t){const i=this._injector.createInstance(B,t,n);this._findModelsByUnitId.set(t.getUnitId(),i);const r=this._preprocessQuery(e);return i.start(r),[i]}return[]}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=P([I(0,l.IUniverInstanceService),I(1,k.IRenderManagerService),I(2,v.Inject(v.Injector))],W);const _={hit:!1,replaceable:!1,isFormula:!1,rawData:null};function ee(h,e,t,n,i){const{findBy:r}=n,s=r===S.FindBy.FORMULA,o=h.getCellRaw(e,t);return _.rawData=o,!(o!=null&&o.f)?(_.isFormula=!1,T(i,n)?o?(_.hit=!0,_.replaceable=!0):(_.hit=!0,_.replaceable=!1):(_.hit=!1,_.replaceable=!1),_):(_.isFormula=!0,s?T({v:o.f},n)?(_.hit=!0,_.replaceable=!0,_):(_.hit=!1,_.replaceable=!1,_):(_.replaceable=!1,T(i,n)?_.hit=!0:_.hit=!1,_))}function T(h,e){let t=te(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 te(h){var t,n,i;const e=(i=(n=(t=h==null?void 0:h.p)==null?void 0:t.body)==null?void 0:n.dataStream)!=null?i: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,"")}var D=Object.defineProperty,ie=Object.getOwnPropertyDescriptor,se=(h,e,t)=>e in h?D(h,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):h[e]=t,re=(h,e,t,n)=>{for(var i=n>1?void 0:n?ie(e,t):e,r=h.length-1,s;r>=0;r--)(s=h[r])&&(i=(n?s(e,t,i):s(i))||i);return n&&i&&D(e,t,i),i},oe=(h,e)=>(t,n)=>e(t,n,h),N=(h,e,t)=>se(h,typeof e!="symbol"?e+"":e,t);const he="SHEET_FIND_REPLACE_PLUGIN";u.UniverSheetsFindReplacePlugin=class extends l.Plugin{constructor(e,t){super(),this._injector=t}onStarting(e){[[u.SheetsFindReplaceController]].forEach(t=>e.add(t))}},N(u.UniverSheetsFindReplacePlugin,"pluginName",he),N(u.UniverSheetsFindReplacePlugin,"type",l.UniverInstanceType.UNIVER_SHEET),u.UniverSheetsFindReplacePlugin=re([l.DependentOn(w.UniverSheetsPlugin,w.UniverSheetsPlugin,S.UniverFindReplacePlugin),oe(1,v.Inject(v.Injector))],u.UniverSheetsFindReplacePlugin),u.SheetReplaceCommand=x,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
1
+ (function(_,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/find-replace"),require("@univerjs/sheets"),require("@univerjs/engine-render"),require("@univerjs/sheets-ui"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/find-replace","@univerjs/sheets","@univerjs/engine-render","@univerjs/sheets-ui","rxjs"],a):(_=typeof globalThis<"u"?globalThis:_||self,a(_.UniverSheetsFindReplace={},_.UniverCore,_.UniverFindReplace,_.UniverSheets,_.UniverEngineRender,_.UniverSheetsUi,_.rxjs))})(this,function(_,a,f,R,k,M,C){"use strict";var _e=Object.defineProperty;var fe=(_,a,f)=>a in _?_e(_,a,{enumerable:!0,configurable:!0,writable:!0,value:f}):_[a]=f;var m=(_,a,f)=>fe(_,typeof a!="symbol"?a+"":a,f);class V extends k.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})`;k.Rect.drawWith(t,{width:this.width,height:this.height,fill:n,stroke:i?r:void 0,strokeWidth:i?2:0,evented:!1})}}const F={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(R.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}}function T(h,e){return h.startRow===e.startRow&&h.startColumn===e.startColumn}function H(h,e){return h.startRow<e.startRow||h.startRow===e.startRow&&h.startColumn<=e.startColumn}function O(h,e){return h.startColumn<e.startColumn||h.startColumn===e.startColumn&&h.startRow<=e.startRow}function X(h,e){return h.startRow>e.startRow||h.startRow===e.startRow&&h.startColumn>=e.startColumn}function Y(h,e){return h.startColumn>e.startColumn||h.startColumn===e.startColumn&&h.startRow>=e.startRow}function q(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 G=Object.defineProperty,K=Object.getOwnPropertyDescriptor,U=(h,e,t,i)=>{for(var n=i>1?void 0:i?K(e,t):e,r=h.length-1,s;r>=0;r--)(s=h[r])&&(n=(i?s(e,t,n):s(n))||n);return i&&n&&G(e,t,n),n},p=(h,e)=>(t,i)=>e(t,i,h);_.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(P);this._provider=t,this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(t)),this.disposeWithMe(this._contextService.subscribeContextValue$(a.EDITOR_ACTIVATED).pipe(C.filter(i=>!!i)).subscribe(()=>this._findReplaceController.closePanel()))}_initCommands(){[F].forEach(t=>this.disposeWithMe(this._commandService.registerCommand(t)))}},_.SheetsFindReplaceController=U([a.OnLifecycle(a.LifecycleStages.Steady,_.SheetsFindReplaceController),p(0,a.Inject(a.Injector)),p(1,a.Inject(f.FindReplaceController)),p(2,a.IContextService),p(3,f.IFindReplaceService),p(4,a.ICommandService)],_.SheetsFindReplaceController);const z="sheets-find-replace-provider",J=1e4;let x=class extends f.FindModel{constructor(e,t,i,n,r,s,o,c){super();m(this,"_matchesUpdate$",new C.Subject);m(this,"matchesUpdate$",this._matchesUpdate$.asObservable());m(this,"_activelyChangingMatch$",new C.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===f.FindBy.FORMULA?this._toggleDisplayRawFormula(!0):this._toggleDisplayRawFormula(!1),e.findScope){case f.FindScope.UNIT:this.findInWorkbook(e);break;case f.FindScope.SUBUNIT:default:this.findInActiveWorksheet(e);break}}_toggleDisplayRawFormula(e){this._contextService.setContextValue(k.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.onCommandExecuted)).pipe(C.filter(([s,o])=>s.id===R.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(C.filter(([s])=>s.type===a.CommandType.MUTATION&&s.params.unitId===this._workbook.getUnitId()),C.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=>!q(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(C.merge(a.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(C.filter(([c])=>{if(c.type===a.CommandType.MUTATION&&c.params.unitId===this._workbook.getUnitId())return!0;if(c.id===R.SetSelectionsOperation.id&&c.params.unitId===t){const d=i();return d===!1&&s===!1?!1:(s=d,!0)}return!1})),this._workbook.activeSheet$.pipe(C.skip(1))).pipe(C.debounceTime(200)).subscribe(()=>o())),o(),n}_findInRange(e,t,i,n,r){const s=[],o=e.getSheetId(),c=(t.findDirection===f.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:b,replaceable:y,isFormula:w}=Z(e,l,u,t,I);if(b){const W={provider:z,unitId:n,replaceable:y,isFormula:w,range:{subUnitId:o,range:{startRow:l,startColumn:u,endColumn:u+(g!=null?g:1)-1,endRow:l+(v!=null?v:1)-1}}};s.push(W)}}return{results:s}}_findInSelections(e,t,i,n){const{findDirection:r}=i,s=r===f.FindDirection.ROW?H:O,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=>{t.getScene().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.getCurrentTheme().gold400,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:b,endColumn:y,endRow:w}=g.range.range,W=M.getCoordByCell(b,I,n,e),he=M.getCoordByCell(w,y,n,e),{startX:N,startY:$}=W,{endX:ce,endY:ae}=he,j=!c.getRowRawVisible(b),L=!c.getColVisible(I),le=j||L,de=L?2:ce-N,ue=j?2:ae-$,ge={left:N,top:$,color:o,width:de,height:ue,evented:!1,inHiddenRange:le,zIndex:J};return new V(`find-highlight-${v}`,ge)});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 M.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(R.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: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===f.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===f.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!==f.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!==f.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===f.FindDirection.ROW;let r=e.findIndex(o=>{const c=o.range.range;if(!(n?H(t,c):O(t,c)))return!1;const l=T(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===f.FindDirection.ROW;let r=this._matches.findLastIndex(o=>{const c=o.range.range;if(!(n?X(t,c):Y(t,c)))return!1;const l=T(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===f.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(R.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===f.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:b,startRow:y}=I.range.range,w=this._getReplacedCellData(I,v,s,i,e,o);w&&g.setValue(y,b,w)}),c.push({count:l.length,subUnitId:u,value:g.getMatrix()})}),c?this._commandService.executeCommand(F.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(E(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),{p:I}}return{v:l.v.toString().replace(new RegExp(E(n),s),r)}}};x=U([p(2,a.IUniverInstanceService),p(3,k.IRenderManagerService),p(4,a.ICommandService),p(5,a.IContextService),p(6,a.Inject(a.ThemeService)),p(7,a.Inject(R.SheetsSelectionsService))],x);function E(h){return h.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}let P=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.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET),i=this._preprocessQuery(e);return t.map(r=>{const s=this._renderManagerService.getRenderById(r.getUnitId()).with(M.SheetSkeletonManagerService),o=this._injector.createInstance(x,r,s);return this._findModelsByUnitId.set(r.getUnitId(),o),o.start(i),o})}terminate(){this._terminate()}_terminate(){this._findModelsByUnitId.forEach(e=>e.dispose()),this._findModelsByUnitId.clear()}_preprocessQuery(e){let t=e.caseSensitive?e.findString:e.findString.toLowerCase();return t=t.trim(),{...e,findString:t}}};P=U([p(0,a.IUniverInstanceService),p(1,k.IRenderManagerService),p(2,a.Inject(a.Injector))],P);const S={hit:!1,replaceable:!1,isFormula:!1,rawData:null};function Z(h,e,t,i,n){const{findBy:r}=i,s=r===f.FindBy.FORMULA,o=h.getCellRaw(e,t);return S.rawData=o,!(o!=null&&o.f)?(S.isFormula=!1,B(n,i)?o?(S.hit=!0,S.replaceable=!0):(S.hit=!0,S.replaceable=!1):(S.hit=!1,S.replaceable=!1),S):(S.isFormula=!0,s?B({v:o.f},i)?(S.hit=!0,S.replaceable=!0,S):(S.hit=!1,S.replaceable=!1,S):(S.replaceable=!1,B(n,i)?S.hit=!0:S.hit=!1,S))}function B(h,e){let t=ee(h);return t?e.matchesTheWholeCell?(t=te(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 ee(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 te(h){return h.replace(/^ +/g,"").replace(/ +$/g,"")}var A=Object.defineProperty,ie=Object.getOwnPropertyDescriptor,ne=(h,e,t)=>e in h?A(h,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):h[e]=t,se=(h,e,t,i)=>{for(var n=i>1?void 0:i?ie(e,t):e,r=h.length-1,s;r>=0;r--)(s=h[r])&&(n=(i?s(e,t,n):s(n))||n);return i&&n&&A(e,t,n),n},re=(h,e)=>(t,i)=>e(t,i,h),D=(h,e,t)=>ne(h,typeof e!="symbol"?e+"":e,t);const oe="SHEET_FIND_REPLACE_PLUGIN";_.UniverSheetsFindReplacePlugin=class extends a.Plugin{constructor(e,t){super(),this._injector=t}onStarting(e){[[_.SheetsFindReplaceController]].forEach(t=>e.add(t))}},D(_.UniverSheetsFindReplacePlugin,"pluginName",oe),D(_.UniverSheetsFindReplacePlugin,"type",a.UniverInstanceType.UNIVER_SHEET),_.UniverSheetsFindReplacePlugin=se([a.DependentOn(R.UniverSheetsPlugin,R.UniverSheetsPlugin,f.UniverFindReplacePlugin),re(1,a.Inject(a.Injector))],_.UniverSheetsFindReplacePlugin),_.SheetReplaceCommand=F,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-find-replace",
3
- "version": "0.2.2",
3
+ "version": "0.2.4-alpha.0",
4
4
  "private": false,
5
5
  "description": "UniverSheet find replace plugin",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -47,30 +47,28 @@
47
47
  "lib"
48
48
  ],
49
49
  "peerDependencies": {
50
- "@wendellhu/redi": "0.15.5",
51
50
  "rxjs": ">=7.0.0",
52
- "@univerjs/core": "0.2.2",
53
- "@univerjs/engine-render": "0.2.2",
54
- "@univerjs/sheets": "0.2.2",
55
- "@univerjs/find-replace": "0.2.2",
56
- "@univerjs/sheets-ui": "0.2.2"
51
+ "@univerjs/engine-render": "0.2.4-alpha.0",
52
+ "@univerjs/find-replace": "0.2.4-alpha.0",
53
+ "@univerjs/sheets": "0.2.4-alpha.0",
54
+ "@univerjs/sheets-ui": "0.2.4-alpha.0",
55
+ "@univerjs/core": "0.2.4-alpha.0"
57
56
  },
58
57
  "dependencies": {
59
- "@univerjs/protocol": "0.1.38-alpha.11"
58
+ "@univerjs/protocol": "0.1.38-alpha.23"
60
59
  },
61
60
  "devDependencies": {
62
- "@wendellhu/redi": "0.15.5",
63
61
  "rxjs": "^7.8.1",
64
62
  "typescript": "^5.5.3",
65
- "vite": "^5.3.3",
66
- "vitest": "^1.6.0",
67
- "@univerjs/engine-formula": "0.2.2",
68
- "@univerjs/core": "0.2.2",
69
- "@univerjs/engine-render": "0.2.2",
70
- "@univerjs/shared": "0.2.2",
71
- "@univerjs/sheets": "0.2.2",
72
- "@univerjs/sheets-ui": "0.2.2",
73
- "@univerjs/find-replace": "0.2.2"
63
+ "vite": "^5.3.4",
64
+ "vitest": "^2.0.3",
65
+ "@univerjs/core": "0.2.4-alpha.0",
66
+ "@univerjs/engine-formula": "0.2.4-alpha.0",
67
+ "@univerjs/engine-render": "0.2.4-alpha.0",
68
+ "@univerjs/find-replace": "0.2.4-alpha.0",
69
+ "@univerjs/shared": "0.2.4-alpha.0",
70
+ "@univerjs/sheets": "0.2.4-alpha.0",
71
+ "@univerjs/sheets-ui": "0.2.4-alpha.0"
74
72
  },
75
73
  "univerSpace": {
76
74
  ".": {