@univerjs/sheets-find-replace 0.1.13 → 0.1.15

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.
@@ -33,14 +33,13 @@ export interface ISheetCellMatch extends IFindMatch {
33
33
  */
34
34
  export declare class SheetFindModel extends FindModel {
35
35
  private readonly _workbook;
36
+ private readonly _sheetSkeletonManagerService;
36
37
  private readonly _univerInstanceService;
37
38
  private readonly _renderManagerService;
38
39
  private readonly _commandService;
39
40
  private readonly _contextService;
40
41
  private readonly _themeService;
41
- private readonly _sheetSkeletonManagerService;
42
42
  private readonly _selectionManagerService;
43
- private readonly _findReplaceController;
44
43
  private readonly _matchesUpdate$;
45
44
  readonly matchesUpdate$: import('rxjs').Observable<ISheetCellMatch[]>;
46
45
  private readonly _activelyChangingMatch$;
@@ -61,7 +60,7 @@ export declare class SheetFindModel extends FindModel {
61
60
  get matchesCount(): number;
62
61
  get matchesPosition(): number;
63
62
  get currentMatch(): Nullable<ISheetCellMatch>;
64
- constructor(_workbook: Workbook, _univerInstanceService: IUniverInstanceService, _renderManagerService: IRenderManagerService, _commandService: ICommandService, _contextService: IContextService, _themeService: ThemeService, _sheetSkeletonManagerService: SheetSkeletonManagerService, _selectionManagerService: SelectionManagerService, _findReplaceController: SheetsFindReplaceController);
63
+ constructor(_workbook: Workbook, _sheetSkeletonManagerService: SheetSkeletonManagerService, _univerInstanceService: IUniverInstanceService, _renderManagerService: IRenderManagerService, _commandService: ICommandService, _contextService: IContextService, _themeService: ThemeService, _selectionManagerService: SelectionManagerService);
65
64
  dispose(): void;
66
65
  getMatches(): IFindMatch[];
67
66
  start(query: IFindQuery): void;
@@ -104,7 +103,6 @@ export declare class SheetFindModel extends FindModel {
104
103
  replace(replaceString: string): Promise<boolean>;
105
104
  replaceAll(replaceString: string): Promise<IReplaceAllResult>;
106
105
  private _getReplacedCellData;
107
- private _getFindReplacePermissionCheck;
108
106
  }
109
107
  interface IValuePassingObject {
110
108
  hit: boolean;
@@ -1,11 +1,10 @@
1
- import { Plugin, PluginService, UniverInstanceType } from '@univerjs/core';
1
+ import { Plugin, UniverInstanceType } from '@univerjs/core';
2
2
  import { Injector } from '@wendellhu/redi';
3
3
 
4
4
  export declare class UniverSheetsFindReplacePlugin extends Plugin {
5
5
  protected readonly _injector: Injector;
6
- private readonly _pluginService;
7
6
  static pluginName: string;
8
7
  static type: UniverInstanceType;
9
- constructor(_config: unknown, _injector: Injector, _pluginService: PluginService);
8
+ constructor(_config: unknown, _injector: Injector);
10
9
  onStarting(injector: Injector): void;
11
10
  }
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(u,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("@univerjs/find-replace"),require("@univerjs/engine-render"),require("@univerjs/sheets"),require("@univerjs/sheets-ui"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","@univerjs/find-replace","@univerjs/engine-render","@univerjs/sheets","@univerjs/sheets-ui","rxjs"],d):(u=typeof globalThis<"u"?globalThis:u||self,d(u.UniverSheetsFindReplace={},u.UniverCore,u["@wendellhu/redi"],u.UniverFindReplace,u.UniverEngineRender,u.UniverSheets,u.UniverSheetsUi,u.rxjs))})(this,function(u,d,S,m,F,k,b,R){"use strict";var ve=Object.defineProperty;var Ce=(u,d,S)=>d in u?ve(u,d,{enumerable:!0,configurable:!0,writable:!0,value:S}):u[d]=S;var f=(u,d,S)=>(Ce(u,typeof d!="symbol"?d+"":d,S),S);var U;var O=(t=>(t[t.View=0]="View",t[t.Edit=1]="Edit",t[t.ManageCollaborator=2]="ManageCollaborator",t[t.Print=3]="Print",t[t.Duplicate=4]="Duplicate",t[t.Comment=5]="Comment",t[t.Copy=6]="Copy",t[t.Share=7]="Share",t[t.Export=8]="Export",t[t.MoveWorksheet=9]="MoveWorksheet",t[t.DeleteWorksheet=10]="DeleteWorksheet",t[t.HideWorksheet=11]="HideWorksheet",t[t.RenameWorksheet=12]="RenameWorksheet",t[t.CreateWorksheet=13]="CreateWorksheet",t[t.SetWorksheetStyle=14]="SetWorksheetStyle",t[t.EditWorksheetCell=15]="EditWorksheetCell",t[t.InsertHyperlink=16]="InsertHyperlink",t[t.Sort=17]="Sort",t[t.Filter=18]="Filter",t[t.PivotTable=19]="PivotTable",t[t.FloatImg=20]="FloatImg",t[t.History=21]="History",t[t.RwHgtClWdt=22]="RwHgtClWdt",t[t.ViemRwHgtClWdt=23]="ViemRwHgtClWdt",t[t.ViewFilter=24]="ViewFilter",t[t.MoveSheet=25]="MoveSheet",t[t.DeleteSheet=26]="DeleteSheet",t[t.HideSheet=27]="HideSheet",t[t.CopySheet=28]="CopySheet",t[t.RenameSheet=29]="RenameSheet",t[t.CreateSheet=30]="CreateSheet",t[t.SelectProtectedCells=31]="SelectProtectedCells",t[t.SelectUnProtectedCells=32]="SelectUnProtectedCells",t[t.SetCellStyle=33]="SetCellStyle",t[t.SetCellValue=34]="SetCellValue",t[t.SetRowStyle=35]="SetRowStyle",t[t.SetColumnStyle=36]="SetColumnStyle",t[t.InsertRow=37]="InsertRow",t[t.InsertColumn=38]="InsertColumn",t[t.DeleteRow=39]="DeleteRow",t[t.DeleteColumn=40]="DeleteColumn",t[t.EditExtraObject=41]="EditExtraObject",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED",t))(O||{});class X extends F.Shape{constructor(i,n){super(i,n);f(this,"_activated",!1);f(this,"_inHiddenRange",!1);f(this,"_color");n&&this.setShapeProps(n)}setShapeProps(i){this._activated=!!i.activated,typeof i.inHiddenRange<"u"&&(this._inHiddenRange=i.inHiddenRange),typeof i.color<"u"&&(this._color=i.color),this.transformByState({width:i.width,height:i.height})}_draw(i){const n=this._activated,r=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 0.35)`,o=`rgb(${this._color.r}, ${this._color.g}, ${this._color.b})`;F.Rect.drawWith(i,{width:this.width,height:this.height,fill:r,stroke:n?o:void 0,strokeWidth:n?2:0,evented:!1})}}const D={id:"sheet.command.replace",type:d.CommandType.COMMAND,handler:async(t,e)=>{const i=t.get(d.IUndoRedoService),n=t.get(d.ICommandService),{unitId:r,replacements:o}=e,s=i.__tempBatchingUndoRedo(r),h=await Promise.all(o.map(c=>n.executeCommand(k.SetRangeValuesCommand.id,{unitId:r,subUnitId:c.subUnitId,value:c.value})));return s.dispose(),Y(h,o)}};function Y(t,e){let i=0,n=0;return t.forEach((r,o)=>{const s=e[o].count;r?i+=s:n+=s}),{success:i,failure:n}}function A(t,e){return t.startRow===e.startRow&&t.startColumn===e.startColumn}function j(t,e){return t.startRow<e.startRow||t.startRow===e.startRow&&t.startColumn<=e.startColumn}function N(t,e){return t.startColumn<e.startColumn||t.startColumn===e.startColumn&&t.startRow<=e.startRow}function Z(t,e){return t.startRow>e.startRow||t.startRow===e.startRow&&t.startColumn>=e.startColumn}function K(t,e){return t.startColumn>e.startColumn||t.startColumn===e.startColumn&&t.startRow>=e.startRow}function z(t,e){const{range:i}=t,{startRow:n,startColumn:r}=i,o=e.getMergedCell(n,r);return o?d.Rectangle.equals(i,o):i.endRow===i.startRow&&i.endColumn===i.startColumn}var J=Object.defineProperty,E=Object.getOwnPropertyDescriptor,x=(t,e,i,n)=>{for(var r=n>1?void 0:n?E(e,i):e,o=t.length-1,s;o>=0;o--)(s=t[o])&&(r=(n?s(e,i,r):s(r))||r);return n&&r&&J(e,i,r),r},v=(t,e)=>(i,n)=>e(i,n,t);u.SheetsFindReplaceController=class extends d.Disposable{constructor(i,n,r,o,s){super();f(this,"_provider");this._injector=i,this._findReplaceController=n,this._contextService=r,this._findReplaceService=o,this._commandService=s,this._init(),this._initCommands()}dispose(){super.dispose(),this._provider.dispose()}_init(){const i=this._injector.createInstance(H);this._provider=i,this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(i)),this.disposeWithMe(this._contextService.subscribeContextValue$(d.EDITOR_ACTIVATED).pipe(R.filter(n=>!!n)).subscribe(()=>this._findReplaceController.closePanel()))}_initCommands(){[D].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}},u.SheetsFindReplaceController=x([d.OnLifecycle(d.LifecycleStages.Steady,u.SheetsFindReplaceController),v(0,S.Inject(S.Injector)),v(1,S.Inject(m.FindReplaceController)),v(2,d.IContextService),v(3,m.IFindReplaceService),v(4,d.ICommandService)],u.SheetsFindReplaceController);const ee="sheets-find-replace-provider",te=1e4;let W=class extends m.FindModel{constructor(e,i,n,r,o,s,h,c,a){super();f(this,"_matchesUpdate$",new R.Subject);f(this,"matchesUpdate$",this._matchesUpdate$.asObservable());f(this,"_activelyChangingMatch$",new R.Subject);f(this,"activelyChangingMatch$",this._activelyChangingMatch$.asObservable());f(this,"_matchesByWorksheet",new Map);f(this,"_matches",[]);f(this,"_matchesPosition",0);f(this,"_activeHighlightIndex",-1);f(this,"_highlightShapes",[]);f(this,"_currentHighlightShape",null);f(this,"_query",null);this._workbook=e,this._univerInstanceService=i,this._renderManagerService=n,this._commandService=r,this._contextService=o,this._themeService=s,this._sheetSkeletonManagerService=h,this._selectionManagerService=c,this._findReplaceController=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===m.FindBy.FORMULA?this._toggleDisplayRawFormula(!0):this._toggleDisplayRawFormula(!1),e.findScope){case m.FindScope.UNIT:this.findInWorkbook(e);break;case m.FindScope.SUBUNIT:default:this.findInActiveWorksheet(e);break}}_toggleDisplayRawFormula(e){this._contextService.setContextValue(F.RENDER_RAW_FORMULA_KEY,e)}findInWorkbook(e){const i=this._workbook.getUnitId();let n,r=!0;const o=()=>{const s=this._workbook.getSheets().filter(h=>!h.isSheetHidden()).map(h=>{const c=this._findInWorksheet(h,e,i),a=h.getSheetId(),{results:l}=c;return l.length?this._matchesByWorksheet.set(a,c.results):this._matchesByWorksheet.delete(a),c});this._matches=s.map(h=>h.results).flat(),this._updateFindHighlight(),r?(n={results:this._matches},r=!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).pipe(R.filter(([s,h])=>s.id===k.SetWorksheetActiveOperation.id&&!(h!=null&&h.fromFindReplace))).subscribe(()=>{const s=this._workbook.getActiveSheet(),h=s.getSheetId();this._matchesByWorksheet.has(h)&&this._findNextMatchOnActiveSheetChange(s)})),this.disposeWithMe(d.fromCallback(this._commandService.onCommandExecuted).pipe(R.filter(([s])=>s.type===d.CommandType.MUTATION&&s.params.unitId===this._workbook.getUnitId()),R.throttleTime(600,void 0,{leading:!1,trailing:!0})).subscribe(()=>o())),o(),n}_findNextMatchOnActiveSheetChange(e){let i,n,r=0;const o=this._matchesByWorksheet.get(e.getSheetId()),s=this._selectionManagerService.getSelections();s!=null&&s.length?([i,r]=this._findNextMatchByRange(o,s[0].range),n=o.findIndex(h=>h===i)):(i=o[0],n=0,r=this._matches.findIndex(h=>h===i)),this._matchesPosition=r+1,this._activelyChangingMatch$.next(i),this._activeHighlightIndex=n,this._updateFindHighlight(),this._updateCurrentHighlightShape(n)}findInActiveWorksheet(e){const i=this._workbook.getUnitId(),n=()=>{var g;const c=this._workbook.getActiveSheet(),a=this._selectionManagerService.getSelections();return(g=a==null?void 0:a.some(C=>!z(C,c)))!=null?g:!1};let r,o=!0,s=!1;const h=()=>{const c=this._workbook.getActiveSheet(),a=this.currentMatch;s=n();const l=this._selectionManagerService.getSelections(),g=s?this._findInSelections(c,l,e,i):this._findInWorksheet(c,e,i);return this._matches=g.results,this._matchesPosition=this._tryRestoreLastMatchesPosition(a,this._matches),o?(r=g,o=!1):this._matchesUpdate$.next(this._matches),this._updateFindHighlight(),g};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>this._updateFindHighlight())),this.disposeWithMe(R.merge(d.fromCallback(this._commandService.onCommandExecuted).pipe(R.filter(([c])=>{if(c.type===d.CommandType.MUTATION&&c.params.unitId===this._workbook.getUnitId())return!0;if(c.id===k.SetSelectionsOperation.id&&c.params.unitId===i){const a=n();return a===!1&&s===!1?!1:(s=a,!0)}return!1})),this._workbook.activeSheet$.pipe(R.skip(1))).pipe(R.debounceTime(200)).subscribe(()=>h())),h(),r}_findInRange(e,i,n,r,o){const s=[],h=e.getSheetId(),c=(i.findDirection===m.FindDirection.COLUMN?e.iterateByColumn:e.iterateByRow).bind(e)(n);for(const a of c){const{row:l,col:g,colSpan:C,rowSpan:p,value:I}=a;if(!this._getFindReplacePermissionCheck({row:l,col:g,unitId:r,subUnitId:h})||o!=null&&o(l,g)||!I||e.getRowFiltered(l))continue;const{hit:M,replaceable:w,isFormula:P}=ie(e,l,g,i,I);if(M){const T={provider:ee,unitId:r,replaceable:w,isFormula:P,range:{subUnitId:h,range:{startRow:l,startColumn:g,endColumn:g+(C!=null?C:1)-1,endRow:l+(p!=null?p:1)-1}}};s.push(T)}}return{results:s}}_findInSelections(e,i,n,r){const{findDirection:o}=n,s=o===m.FindDirection.ROW?j:N,h=new Set;return{results:i.map(a=>this._findInRange(e,n,a.range,r,(l,g)=>{const C=`${l}-${g}`;return h.has(C)?!0:(h.add(C),!1)}).results).flat().sort((a,l)=>s(a.range.range,l.range.range)?-1:1)}}_findInWorksheet(e,i,n){const r=e.getRowCount(),o=e.getColumnCount(),s={startRow:0,startColumn:0,endRow:r-1,endColumn:o-1};return this._findInRange(e,i,s,n)}_disposeHighlights(){var e;this._highlightShapes.forEach(i=>{i.getScene().makeDirty(),i.dispose()}),this._highlightShapes=[],(e=this._currentHighlightShape)==null||e.dispose(),this._currentHighlightShape=null}_updateFindHighlight(){var p,I;this._disposeHighlights();const e=(p=this._sheetSkeletonManagerService.getCurrent())==null?void 0:p.skeleton;if(!e||!this._getSheetObject()||((I=this._univerInstanceService.getFocusedUnit())==null?void 0:I.getUnitId())!==this._workbook.getUnitId())return;const r=this._workbook.getUnitId(),o=this._renderManagerService.getRenderById(r);if(o==null)return;const{scene:s}=o,h=this._matches,c=this._themeService.getCurrentTheme().gold400,a=new d.ColorKit(c).toRgb(),l=this._workbook.getActiveSheet(),g=l.getSheetId(),C=h.filter(y=>y.range.subUnitId===g).map((y,M)=>{const{startColumn:w,startRow:P,endColumn:T,endRow:ae}=y.range.range,le=b.getCoordByCell(P,w,s,e),de=b.getCoordByCell(ae,T,s,e),{startX:L,startY:G}=le,{endX:ue,endY:ge}=de,q=!l.getRowRawVisible(P),Q=!l.getColVisible(w),_e=q||Q,fe=Q?2:ue-L,Se=q?2:ge-G,me={left:L,top:G,color:a,width:fe,height:Se,evented:!1,inHiddenRange:_e,zIndex:te};return new X(`find-highlight-${M}`,me)});s.addObjects(C),this._highlightShapes=C,s.makeDirty()}_updateCurrentHighlightShape(e){var i;if((i=this._currentHighlightShape)==null||i.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 b.getSheetObject(this._univerInstanceService,this._renderManagerService)}_focusMatch(e){const i=e.range.subUnitId;i!==this._workbook.getActiveSheet().getSheetId()&&this._commandService.syncExecuteCommand(k.SetWorksheetActivateCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:i},{fromFindReplace:!0}),this._commandService.syncExecuteCommand(b.ScrollToCellCommand.id,{range:e.range.range},{fromFindReplace:!0})}_tryRestoreLastMatchesPosition(e,i){if(!e)return 0;const{subUnitId:n}=e.range,{startColumn:r,startRow:o}=e.range.range,s=i.findIndex(h=>{if(n!==h.range.subUnitId)return!1;const{startColumn:c,startRow:a}=h.range.range;return c===r&&a===o});return s>-1?s+1:0}moveToNextMatch(e){var s,h,c;if(!this._matches.length)return null;const i=(s=e==null?void 0:e.loop)!=null?s:!1,n=(h=e==null?void 0:e.stayIfOnMatch)!=null?h:!1,r=(c=e==null?void 0:e.noFocus)!=null?c:!1,o=this._findNextMatch(i,n);if(o){const[a,l]=o;return this._matchesPosition=l+1,this._query.findScope===m.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(a.range.subUnitId).findIndex(g=>g===a):this._activeHighlightIndex=l,r||this._focusMatch(a),this._workbook.getActiveSheet().getSheetId()===a.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),a}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}moveToPreviousMatch(e){var s,h,c;if(!this._matches.length)return null;const i=(s=e==null?void 0:e.loop)!=null?s:!1,n=(h=e==null?void 0:e.stayIfOnMatch)!=null?h:!1,r=(c=e==null?void 0:e.noFocus)!=null?c:!1,o=this._findPreviousMatch(i,n);if(o){const[a,l]=o;return this._matchesPosition=l+1,this._query.findScope===m.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(a.range.subUnitId).findIndex(g=>g===a):this._activeHighlightIndex=l,r||this._focusMatch(a),this._workbook.getActiveSheet().getSheetId()===a.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),a}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}_findPreviousMatch(e=!1,i=!1){if(this.currentMatch){const s=this._matches.findIndex(l=>l===this.currentMatch);if(i)return[this.currentMatch,s];const h=s-1;if(!e&&h<0)return null;const c=this._matches.length,a=(h+c)%c;return[this._matches[a],a]}const n=this._selectionManagerService.getSelections();if(!(n!=null&&n.length))return[this._matches[0],0];if(this._query.findScope!==m.FindScope.UNIT)return this._findPreviousMatchByRange(this._matches,n[0].range);const r=this._workbook.getActiveSheet().getSheetId(),o=this._findPreviousWorksheetThatHasAMatch(r,e);return o?this._findPreviousMatchByRange(this._matchesByWorksheet.get(o),n[0].range):null}_findNextMatch(e=!1,i=!1){if(this.currentMatch){const s=this._matches.findIndex(l=>l===this.currentMatch);if(i)return[this.currentMatch,s];const h=s+1,c=this._matches.length;if(!e&&h>=c)return null;const a=h%c;return[this._matches[a],a]}const n=this._selectionManagerService.getSelections();if(!(n!=null&&n.length))return[this._matches[0],0];if(this._query.findScope!==m.FindScope.UNIT)return this._findNextMatchByRange(this._matches,n[0].range,i);const r=this._workbook.getActiveSheet().getSheetId(),o=this._findNextWorksheetThatHasAMatch(r,e);return o?this._findNextMatchByRange(this._matchesByWorksheet.get(o),n[0].range):null}_findPreviousWorksheetThatHasAMatch(e,i=!1){const n=this._workbook.getSheetOrders(),r=n.findIndex(h=>h===e),s=(i?d.rotate(n,r+1):n.slice(0,r+1)).findLast(h=>this._matchesByWorksheet.has(h));return s!=null?s:null}_findNextWorksheetThatHasAMatch(e,i=!1){const n=this._workbook.getSheetOrders(),r=n.findIndex(h=>h===e),s=(i?d.rotate(n,r):n.slice(r)).find(h=>this._matchesByWorksheet.has(h));return s!=null?s:null}_findNextMatchByRange(e,i,n=!1){const r=this._query.findDirection===m.FindDirection.ROW;let o=e.findIndex(h=>{const c=h.range.range;if(!(r?j(i,c):N(i,c)))return!1;const l=A(i,c);return n?l:!l});o===-1&&(o=e.length-1);const s=e[o];return[s,this._matches.findIndex(h=>h===s)]}_findPreviousMatchByRange(e,i,n=!1){const r=this._query.findDirection===m.FindDirection.ROW;let o=this._matches.findLastIndex(h=>{const c=h.range.range;if(!(r?Z(i,c):K(i,c)))return!1;const l=A(i,c);return n?l:!l});o===-1&&(o=0);const s=e[o];return[s,this._matches.findIndex(h=>h===s)]}async replace(e){if(this._matchesCount===0||!this.currentMatch||!this._query||!this.currentMatch.replaceable)return!1;const i=this.currentMatch.range,n=this._workbook.getSheetBySheetId(this.currentMatch.range.subUnitId),r=this._getReplacedCellData(this.currentMatch,n,this._query.findBy===m.FindBy.FORMULA,this._query.findString,e,this._query.caseSensitive?"g":"ig"),o={unitId:this.currentMatch.unitId,subUnitId:i.subUnitId,value:{[i.range.startRow]:{[i.range.startColumn]:r}}};return this._commandService.executeCommand(k.SetRangeValuesCommand.id,o)}async replaceAll(e){if(this._matchesCount===0||!this._query)return{success:0,failure:0};const i=this._workbook.getUnitId(),{findString:n,caseSensitive:r,findBy:o}=this._query,s=o===m.FindBy.FORMULA,h=r?"g":"ig",c=[];return d.groupBy(this._matches.filter(l=>l.replaceable),l=>l.range.subUnitId).forEach((l,g)=>{const C=new d.ObjectMatrix,p=this._workbook.getSheetBySheetId(g);l.forEach(I=>{const{startColumn:y,startRow:M}=I.range.range,w=this._getReplacedCellData(I,p,s,n,e,h);w&&C.setValue(M,y,w)}),c.push({count:l.length,subUnitId:g,value:C.getMatrix()})}),c?this._commandService.executeCommand(D.id,{unitId:i,replacements:c}):{success:0,failure:0}}_getReplacedCellData(e,i,n,r,o,s){var p;const h=e.range.range,{startRow:c,startColumn:a}=h,l=i.getCellRaw(c,a);if(e.isFormula)return n?{f:l.f.replace(new RegExp($(r),s),o),v:null}:null;if(!!((p=l.p)!=null&&p.body)){const I=d.Tools.deepClone(l.p);return d.replaceInDocumentBody(I.body,r,o),{p:I}}return{v:l.v.toString().replace(new RegExp($(r),s),o)}}_getFindReplacePermissionCheck(e){var a,l;const{row:i,col:n,subUnitId:r}=e,s=this._univerInstanceService.getCurrentUnitForType(d.UniverInstanceType.UNIVER_SHEET).getSheetBySheetId(r);if(!s)return!1;const h=(l=(a=s.getCell(i,n))==null?void 0:a.selectionProtection)==null?void 0:l[0];return(h==null?void 0:h[O.View])!==!1}};W=x([v(1,d.IUniverInstanceService),v(2,F.IRenderManagerService),v(3,d.ICommandService),v(4,d.IContextService),v(5,S.Inject(d.ThemeService)),v(6,S.Inject(b.SheetSkeletonManagerService)),v(7,S.Inject(k.SelectionManagerService)),v(8,S.Inject(u.SheetsFindReplaceController))],W);function $(t){return t.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}let H=class extends d.Disposable{constructor(e,i){super();f(this,"_findModelsByUnitId",new Map);this._univerInstanceService=e,this._injector=i}async find(e){this._terminate();const i=this._univerInstanceService.getCurrentUnitForType(d.UniverInstanceType.UNIVER_SHEET);if(i){const n=this._injector.createInstance(W,i);this._findModelsByUnitId.set(i.getUnitId(),n);const r=this._preprocessQuery(e);return n.start(r),[n]}return[]}terminate(){this._terminate()}_terminate(){this._findModelsByUnitId.forEach(e=>e.dispose()),this._findModelsByUnitId.clear()}_preprocessQuery(e){let i=e.caseSensitive?e.findString:e.findString.toLowerCase();return i=i.trim(),{...e,findString:i}}};H=x([v(0,d.IUniverInstanceService),v(1,S.Inject(S.Injector))],H);const _={hit:!1,replaceable:!1,isFormula:!1,rawData:null};function ie(t,e,i,n,r){const{findBy:o}=n,s=o===m.FindBy.FORMULA,h=t.getCellRaw(e,i);return _.rawData=h,!(h!=null&&h.f)?(_.isFormula=!1,B(r,n)?h?(_.hit=!0,_.replaceable=!0):(_.hit=!0,_.replaceable=!1):(_.hit=!1,_.replaceable=!1),_):(_.isFormula=!0,s?B({v:h.f},n)?(_.hit=!0,_.replaceable=!0,_):(_.hit=!1,_.replaceable=!1,_):(_.replaceable=!1,B(r,n)?_.hit=!0:_.hit=!1,_))}function B(t,e){let i=ne(t);return i?e.matchesTheWholeCell?(i=se(i),e.caseSensitive?i===e.findString:i.toLowerCase()===e.findString):e.caseSensitive?i.indexOf(e.findString)>-1:i.toLowerCase().indexOf(e.findString)>-1:!1}function ne(t){var i,n,r;const e=(r=(n=(i=t==null?void 0:t.p)==null?void 0:i.body)==null?void 0:n.dataStream)!=null?r:t==null?void 0:t.v;return typeof e=="number"?`${e}`:typeof e=="boolean"?e?"1":"0":e}function se(t){return t.replace(/^ +/g,"").replace(/ +$/g,"")}var re=Object.defineProperty,oe=Object.getOwnPropertyDescriptor,he=(t,e,i,n)=>{for(var r=n>1?void 0:n?oe(e,i):e,o=t.length-1,s;o>=0;o--)(s=t[o])&&(r=(n?s(e,i,r):s(r))||r);return n&&r&&re(e,i,r),r},V=(t,e)=>(i,n)=>e(i,n,t);const ce="SHEET_FIND_REPLACE_PLUGIN";u.UniverSheetsFindReplacePlugin=(U=class extends d.Plugin{constructor(e,i,n){super(),this._injector=i,this._pluginService=n,this._pluginService.registerPlugin(m.UniverFindReplacePlugin)}onStarting(e){[[u.SheetsFindReplaceController]].forEach(i=>e.add(i))}},f(U,"pluginName",ce),f(U,"type",d.UniverInstanceType.UNIVER_SHEET),U),u.UniverSheetsFindReplacePlugin=he([V(1,S.Inject(S.Injector)),V(2,S.Inject(d.PluginService))],u.UniverSheetsFindReplacePlugin),Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
1
+ (function(u,d){typeof exports=="object"&&typeof module<"u"?d(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"],d):(u=typeof globalThis<"u"?globalThis:u||self,d(u.UniverSheetsFindReplace={},u.UniverCore,u["@wendellhu/redi"],u.UniverFindReplace,u.UniverSheets,u.UniverEngineRender,u.UniverSheetsUi,u.rxjs))})(this,function(u,d,m,f,w,k,y,R){"use strict";var ve=Object.defineProperty;var Ie=(u,d,m)=>d in u?ve(u,d,{enumerable:!0,configurable:!0,writable:!0,value:m}):u[d]=m;var S=(u,d,m)=>(Ie(u,typeof d!="symbol"?d+"":d,m),m);class q extends k.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})`;k.Rect.drawWith(t,{width:this.width,height:this.height,fill:i,stroke:n?r:void 0,strokeWidth:n?2:0,evented:!1})}}const T={id:"sheet.command.replace",type:d.CommandType.COMMAND,handler:async(h,e)=>{const t=h.get(d.IUndoRedoService),n=h.get(d.ICommandService),{unitId:i,replacements:r}=e,s=t.__tempBatchingUndoRedo(i),o=await Promise.all(r.map(c=>n.executeCommand(w.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?d.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},I=(h,e)=>(t,n)=>e(t,n,h);u.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(B);this._provider=t,this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(t)),this.disposeWithMe(this._contextService.subscribeContextValue$(d.EDITOR_ACTIVATED).pipe(R.filter(n=>!!n)).subscribe(()=>this._findReplaceController.closePanel()))}_initCommands(){[T].forEach(t=>this.disposeWithMe(this._commandService.registerCommand(t)))}},u.SheetsFindReplaceController=x([d.OnLifecycle(d.LifecycleStages.Steady,u.SheetsFindReplaceController),I(0,m.Inject(m.Injector)),I(1,m.Inject(f.FindReplaceController)),I(2,d.IContextService),I(3,f.IFindReplaceService),I(4,d.ICommandService)],u.SheetsFindReplaceController);const J="sheets-find-replace-provider",Z=1e4;let P=class extends f.FindModel{constructor(e,t,n,i,r,s,o,c){super();S(this,"_matchesUpdate$",new R.Subject);S(this,"matchesUpdate$",this._matchesUpdate$.asObservable());S(this,"_activelyChangingMatch$",new R.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=c}get _matchesCount(){return this._matches.length}get unitId(){return this._workbook.getUnitId()}get matchesCount(){return this._matchesCount}get matchesPosition(){return this._matchesPosition}get currentMatch(){return this._matchesPosition>0?this._matches[this._matchesPosition-1]:null}dispose(){super.dispose(),this._disposeHighlights(),this._toggleDisplayRawFormula(!1)}getMatches(){return this._matches}start(e){switch(this._query=e,e.findBy===f.FindBy.FORMULA?this._toggleDisplayRawFormula(!0):this._toggleDisplayRawFormula(!1),e.findScope){case f.FindScope.UNIT:this.findInWorkbook(e);break;case f.FindScope.SUBUNIT:default:this.findInActiveWorksheet(e);break}}_toggleDisplayRawFormula(e){this._contextService.setContextValue(k.RENDER_RAW_FORMULA_KEY,e)}findInWorkbook(e){const t=this._workbook.getUnitId();let n,i=!0;const r=()=>{const s=this._workbook.getSheets().filter(o=>!o.isSheetHidden()).map(o=>{const c=this._findInWorksheet(o,e,t),l=o.getSheetId(),{results:a}=c;return a.length?this._matchesByWorksheet.set(l,c.results):this._matchesByWorksheet.delete(l),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(d.fromCallback(this._commandService.onCommandExecuted).pipe(R.filter(([s,o])=>s.id===w.SetWorksheetActiveOperation.id&&!(o!=null&&o.fromFindReplace))).subscribe(()=>{const s=this._workbook.getActiveSheet(),o=s.getSheetId();this._matchesByWorksheet.has(o)&&this._findNextMatchOnActiveSheetChange(s)})),this.disposeWithMe(d.fromCallback(this._commandService.onCommandExecuted).pipe(R.filter(([s])=>s.type===d.CommandType.MUTATION&&s.params.unitId===this._workbook.getUnitId()),R.throttleTime(600,void 0,{leading:!1,trailing:!0})).subscribe(()=>r())),r(),n}_findNextMatchOnActiveSheetChange(e){let t,n,i=0;const r=this._matchesByWorksheet.get(e.getSheetId()),s=this._selectionManagerService.getSelections();s!=null&&s.length?([t,i]=this._findNextMatchByRange(r,s[0].range),n=r.findIndex(o=>o===t)):(t=r[0],n=0,i=this._matches.findIndex(o=>o===t)),this._matchesPosition=i+1,this._activelyChangingMatch$.next(t),this._activeHighlightIndex=n,this._updateFindHighlight(),this._updateCurrentHighlightShape(n)}findInActiveWorksheet(e){const t=this._workbook.getUnitId(),n=()=>{var g;const c=this._workbook.getActiveSheet(),l=this._selectionManagerService.getSelections();return(g=l==null?void 0:l.some(v=>!G(v,c)))!=null?g:!1};let i,r=!0,s=!1;const o=()=>{const c=this._workbook.getActiveSheet(),l=this.currentMatch;s=n();const a=this._selectionManagerService.getSelections(),g=s?this._findInSelections(c,a,e,t):this._findInWorksheet(c,e,t);return this._matches=g.results,this._matchesPosition=this._tryRestoreLastMatchesPosition(l,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(d.fromCallback(this._commandService.onCommandExecuted).pipe(R.filter(([c])=>{if(c.type===d.CommandType.MUTATION&&c.params.unitId===this._workbook.getUnitId())return!0;if(c.id===w.SetSelectionsOperation.id&&c.params.unitId===t){const l=n();return l===!1&&s===!1?!1:(s=l,!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(),c=(t.findDirection===f.FindDirection.COLUMN?e.iterateByColumn:e.iterateByRow).bind(e)(n);for(const l of c){const{row:a,col:g,colSpan:v,rowSpan:C,value:p}=l;if(r!=null&&r(a,g)||!p||e.getRowFiltered(a))continue;const{hit:b,replaceable:U,isFormula:M}=ee(e,a,g,t,p);if(b){const F={provider:J,unitId:i,replaceable:U,isFormula:M,range:{subUnitId:o,range:{startRow:a,startColumn:g,endColumn:g+(v!=null?v:1)-1,endRow:a+(C!=null?C:1)-1}}};s.push(F)}}return{results:s}}_findInSelections(e,t,n,i){const{findDirection:r}=n,s=r===f.FindDirection.ROW?O:E,o=new Set;return{results:t.map(l=>this._findInRange(e,n,l.range,i,(a,g)=>{const v=`${a}-${g}`;return o.has(v)?!0:(o.add(v),!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 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,c=this._themeService.getCurrentTheme().gold400,l=new d.ColorKit(c).toRgb(),a=this._workbook.getActiveSheet(),g=a.getSheetId(),v=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=!a.getRowRawVisible(F),V=!a.getColVisible(M),_e=L||V,fe=V?2:ue-j,Se=L?2:ge-$,me={left:j,top:$,color:l,width:fe,height:Se,evented:!1,inHiddenRange:_e,zIndex:Z};return new q(`find-highlight-${U}`,me)});s.addObjects(v),this._highlightShapes=v,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){const t=e.range.subUnitId;t!==this._workbook.getActiveSheet().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:c,startRow:l}=o.range.range;return c===i&&l===r});return s>-1?s+1:0}moveToNextMatch(e){var s,o,c;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=(c=e==null?void 0:e.noFocus)!=null?c:!1,r=this._findNextMatch(t,n);if(r){const[l,a]=r;return this._matchesPosition=a+1,this._query.findScope===f.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(l.range.subUnitId).findIndex(g=>g===l):this._activeHighlightIndex=a,i||this._focusMatch(l),this._workbook.getActiveSheet().getSheetId()===l.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),l}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}moveToPreviousMatch(e){var s,o,c;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=(c=e==null?void 0:e.noFocus)!=null?c:!1,r=this._findPreviousMatch(t,n);if(r){const[l,a]=r;return this._matchesPosition=a+1,this._query.findScope===f.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(l.range.subUnitId).findIndex(g=>g===l):this._activeHighlightIndex=a,i||this._focusMatch(l),this._workbook.getActiveSheet().getSheetId()===l.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),l}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}_findPreviousMatch(e=!1,t=!1){if(this.currentMatch){const s=this._matches.findIndex(a=>a===this.currentMatch);if(t)return[this.currentMatch,s];const o=s-1;if(!e&&o<0)return null;const c=this._matches.length,l=(o+c)%c;return[this._matches[l],l]}const n=this._selectionManagerService.getSelections();if(!(n!=null&&n.length))return[this._matches[0],0];if(this._query.findScope!==f.FindScope.UNIT)return this._findPreviousMatchByRange(this._matches,n[0].range);const i=this._workbook.getActiveSheet().getSheetId(),r=this._findPreviousWorksheetThatHasAMatch(i,e);return r?this._findPreviousMatchByRange(this._matchesByWorksheet.get(r),n[0].range):null}_findNextMatch(e=!1,t=!1){if(this.currentMatch){const s=this._matches.findIndex(a=>a===this.currentMatch);if(t)return[this.currentMatch,s];const o=s+1,c=this._matches.length;if(!e&&o>=c)return null;const l=o%c;return[this._matches[l],l]}const n=this._selectionManagerService.getSelections();if(!(n!=null&&n.length))return[this._matches[0],0];if(this._query.findScope!==f.FindScope.UNIT)return this._findNextMatchByRange(this._matches,n[0].range,t);const i=this._workbook.getActiveSheet().getSheetId(),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===f.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===f.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===f.FindBy.FORMULA,this._query.findString,e,this._query.caseSensitive?"g":"ig"),r={unitId:this.currentMatch.unitId,subUnitId:t.subUnitId,value:{[t.range.startRow]:{[t.range.startColumn]: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===f.FindBy.FORMULA,o=i?"g":"ig",c=[];return d.groupBy(this._matches.filter(a=>a.replaceable),a=>a.range.subUnitId).forEach((a,g)=>{const v=new d.ObjectMatrix,C=this._workbook.getSheetBySheetId(g);a.forEach(p=>{const{startColumn:b,startRow:U}=p.range.range,M=this._getReplacedCellData(p,C,s,n,e,o);M&&v.setValue(U,b,M)}),c.push({count:a.length,subUnitId:g,value:v.getMatrix()})}),c?this._commandService.executeCommand(T.id,{unitId:t,replacements:c}):{success:0,failure:0}}_getReplacedCellData(e,t,n,i,r,s){var C;const o=e.range.range,{startRow:c,startColumn:l}=o,a=t.getCellRaw(c,l);if(e.isFormula)return n?{f:a.f.replace(new RegExp(A(i),s),r),v:null}:null;if(!!((C=a.p)!=null&&C.body)){const p=d.Tools.deepClone(a.p);return d.replaceInDocumentBody(p.body,i,r),{p}}return{v:a.v.toString().replace(new RegExp(A(i),s),r)}}};P=x([I(2,d.IUniverInstanceService),I(3,k.IRenderManagerService),I(4,d.ICommandService),I(5,d.IContextService),I(6,m.Inject(d.ThemeService)),I(7,m.Inject(w.SelectionManagerService))],P);function A(h){return h.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}let B=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(y.SheetSkeletonManagerService);if(t){const i=this._injector.createInstance(P,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}}};B=x([I(0,d.IUniverInstanceService),I(1,k.IRenderManagerService),I(2,m.Inject(m.Injector))],B);const _={hit:!1,replaceable:!1,isFormula:!1,rawData:null};function ee(h,e,t,n,i){const{findBy:r}=n,s=r===f.FindBy.FORMULA,o=h.getCellRaw(e,t);return _.rawData=o,!(o!=null&&o.f)?(_.isFormula=!1,W(i,n)?o?(_.hit=!0,_.replaceable=!0):(_.hit=!0,_.replaceable=!1):(_.hit=!1,_.replaceable=!1),_):(_.isFormula=!0,s?W({v:o.f},n)?(_.hit=!0,_.replaceable=!0,_):(_.hit=!1,_.replaceable=!1,_):(_.replaceable=!1,W(i,n)?_.hit=!0:_.hit=!1,_))}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),t);const he="SHEET_FIND_REPLACE_PLUGIN";u.UniverSheetsFindReplacePlugin=class extends d.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",d.UniverInstanceType.UNIVER_SHEET),u.UniverSheetsFindReplacePlugin=re([d.DependentOn(w.UniverSheetsPlugin,w.UniverSheetsPlugin,f.UniverFindReplacePlugin),oe(1,m.Inject(m.Injector))],u.UniverSheetsFindReplacePlugin),Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-find-replace",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "private": false,
5
5
  "description": "UniverSheet find replace plugin",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -31,8 +31,8 @@
31
31
  "require": "./lib/cjs/*",
32
32
  "types": "./lib/types/index.d.ts"
33
33
  },
34
- "./locale/*": "./lib/locale/*.json",
35
- "./lib/*": "./lib/*"
34
+ "./lib/*": "./lib/*",
35
+ "./locale/*": "./lib/locale/*.json"
36
36
  },
37
37
  "main": "./lib/cjs/index.js",
38
38
  "module": "./lib/es/index.js",
@@ -46,41 +46,52 @@
46
46
  "files": [
47
47
  "lib"
48
48
  ],
49
- "engines": {
50
- "node": ">=16.0.0",
51
- "npm": ">=8.0.0"
52
- },
53
49
  "peerDependencies": {
54
- "@wendellhu/redi": "0.15.2",
50
+ "@wendellhu/redi": "0.15.4",
55
51
  "rxjs": ">=7.0.0",
56
- "@univerjs/core": "0.1.13",
57
- "@univerjs/find-replace": "0.1.13",
58
- "@univerjs/engine-render": "0.1.13",
59
- "@univerjs/sheets-ui": "0.1.13",
60
- "@univerjs/sheets": "0.1.13"
52
+ "@univerjs/core": "0.1.15",
53
+ "@univerjs/engine-render": "0.1.15",
54
+ "@univerjs/find-replace": "0.1.15",
55
+ "@univerjs/sheets": "0.1.15",
56
+ "@univerjs/sheets-ui": "0.1.15"
61
57
  },
62
58
  "dependencies": {
63
- "@univerjs/protocol": "0.1.34"
59
+ "@univerjs/protocol": "0.1.38-alpha.3"
64
60
  },
65
61
  "devDependencies": {
66
- "@wendellhu/redi": "0.15.2",
62
+ "@wendellhu/redi": "0.15.4",
67
63
  "rxjs": "^7.8.1",
68
64
  "typescript": "^5.4.5",
69
- "vite": "^5.2.12",
65
+ "vite": "^5.2.13",
70
66
  "vitest": "^1.6.0",
71
- "@univerjs/core": "0.1.13",
72
- "@univerjs/engine-render": "0.1.13",
73
- "@univerjs/shared": "0.1.13",
74
- "@univerjs/engine-formula": "0.1.13",
75
- "@univerjs/sheets": "0.1.13",
76
- "@univerjs/find-replace": "0.1.13",
77
- "@univerjs/sheets-ui": "0.1.13"
67
+ "@univerjs/core": "0.1.15",
68
+ "@univerjs/engine-formula": "0.1.15",
69
+ "@univerjs/find-replace": "0.1.15",
70
+ "@univerjs/engine-render": "0.1.15",
71
+ "@univerjs/shared": "0.1.15",
72
+ "@univerjs/sheets": "0.1.15",
73
+ "@univerjs/sheets-ui": "0.1.15"
74
+ },
75
+ "univerSpace": {
76
+ ".": {
77
+ "import": "./lib/es/index.js",
78
+ "require": "./lib/cjs/index.js",
79
+ "types": "./lib/types/index.d.ts"
80
+ },
81
+ "./*": {
82
+ "import": "./lib/es/*",
83
+ "require": "./lib/cjs/*",
84
+ "types": "./lib/types/index.d.ts"
85
+ },
86
+ "./lib/*": "./lib/*",
87
+ "./locale/*": "./lib/locale/*.json"
78
88
  },
79
89
  "scripts": {
80
90
  "test": "vitest run",
81
91
  "test:watch": "vitest",
82
92
  "coverage": "vitest run --coverage",
83
93
  "lint:types": "tsc --noEmit",
84
- "build": "tsc && vite build"
94
+ "build": "tsc && vite build",
95
+ "sync:cnpm": "cnpm sync"
85
96
  }
86
97
  }