@univerjs/sheets-find-replace 0.2.3 → 0.2.4

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