@univerjs/sheets-find-replace 0.5.4 → 0.5.5-experimental.20250123-34738ff

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/facade.js CHANGED
@@ -1 +1 @@
1
- "use strict";var u=Object.defineProperty;var _=(i,e,t)=>e in i?u(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var l=(i,e,t)=>_(i,typeof e!="symbol"?e+"":e,t);const o=require("@univerjs/core"),c=require("@univerjs/find-replace"),p=require("@univerjs/sheets/facade");var m=Object.defineProperty,f=Object.getOwnPropertyDescriptor,v=(i,e,t,s)=>{for(var n=s>1?void 0:s?f(e,t):e,r=i.length-1,a;r>=0;r--)(a=i[r])&&(n=(s?a(e,t,n):a(n))||n);return s&&n&&m(e,t,n),n},h=(i,e)=>(t,s)=>e(t,s,i);let d=class extends o.Disposable{constructor(e,t,s,n){super();l(this,"_state",new c.FindReplaceState);l(this,"_model");l(this,"_complete");this._injector=t,this._univerInstanceService=s,this._findReplaceService=n;const r=this._findReplaceService.getProviders();this._model=this._injector.createInstance(c.FindReplaceModel,this._state,r);const a={...c.createInitFindReplaceState(),...e};this._state.changeState(a)}findAll(){return!this._state.findCompleted||!this._complete?[]:this._complete.results.map(e=>this._findMatchToFRange(e))}findNext(){var t;if(!this._state.findCompleted||!this._complete)return null;const e=(t=this._model)==null?void 0:t.moveToNextMatch();return e?this._findMatchToFRange(e):null}findPrevious(){var t;const e=(t=this._model)==null?void 0:t.moveToPreviousMatch();return e?this._findMatchToFRange(e):null}getCurrentMatch(){var t;if(!this._state.findCompleted||!this._complete)throw new Error("Find operation is not completed.");const e=(t=this._model)==null?void 0:t.currentMatch$.value;return e?this._findMatchToFRange(e):null}async matchCaseAsync(e){return this._state.changeState({caseSensitive:e}),new Promise(t=>{const s=this._state.stateUpdates$.subscribe(n=>{n.findCompleted===!0&&(s.unsubscribe(),t(this))})})}async matchEntireCellAsync(e){return this._state.changeState({matchesTheWholeCell:e}),new Promise(t=>{const s=this._state.stateUpdates$.subscribe(n=>{n.findCompleted===!0&&(s.unsubscribe(),t(this))})})}async matchFormulaTextAsync(e){return this._state.changeState({findBy:e?c.FindBy.FORMULA:c.FindBy.VALUE}),new Promise(t=>{const s=this._state.stateUpdates$.subscribe(n=>{n.findCompleted===!0&&(s.unsubscribe(),t(this))})})}async replaceAllWithAsync(e){var s,n,r;await this._state.changeState({replaceRevealed:!0,replaceString:e});const t=(r=(n=await((s=this._model)==null?void 0:s.replaceAll()))==null?void 0:n.success)!=null?r:0;return this._state.changeState({replaceRevealed:!1}),t}async replaceWithAsync(e){var t;return await this._state.changeState({replaceRevealed:!0,replaceString:e}),await((t=this._model)==null?void 0:t.replace()),this._state.changeState({replaceRevealed:!1}),!0}async ensureCompleteAsync(){var e;return(!this._state.findCompleted||!this._complete)&&(this._complete=await((e=this._model)==null?void 0:e.start())),this._complete}_findMatchToFRange(e){const{unitId:t}=e,{subUnitId:s,range:n}=e.range,r=this._univerInstanceService.getUnit(t),a=r.getSheetBySheetId(s);return this._injector.createInstance(p.FRange,r,a,n)}};d=v([h(1,o.Inject(o.Injector)),h(2,o.IUniverInstanceService),h(3,c.IFindReplaceService)],d);class b extends o.FUniver{async createTextFinderAsync(e){const t={findString:e},s=this._injector.createInstance(d,t);return await s.ensureCompleteAsync(),s}}o.FUniver.extend(b);
1
+ "use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);const core=require("@univerjs/core"),findReplace=require("@univerjs/find-replace"),facade=require("@univerjs/sheets/facade");var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam"),_a;let FTextFinder=(_a=class extends core.Disposable{constructor(_initialState,_injector,_univerInstanceService,_findReplaceService){super();__publicField(this,"_state",new findReplace.FindReplaceState);__publicField(this,"_model");__publicField(this,"_complete");this._injector=_injector,this._univerInstanceService=_univerInstanceService,this._findReplaceService=_findReplaceService;const providers=this._findReplaceService.getProviders();this._model=this._injector.createInstance(findReplace.FindReplaceModel,this._state,providers);const newState={...findReplace.createInitFindReplaceState(),..._initialState};this._state.changeState(newState)}findAll(){return!this._state.findCompleted||!this._complete?[]:this._complete.results.map(result=>this._findMatchToFRange(result))}findNext(){var _a2;if(!this._state.findCompleted||!this._complete)return null;const match=(_a2=this._model)==null?void 0:_a2.moveToNextMatch();return match?this._findMatchToFRange(match):null}findPrevious(){var _a2;const match=(_a2=this._model)==null?void 0:_a2.moveToPreviousMatch();return match?this._findMatchToFRange(match):null}getCurrentMatch(){var _a2;if(!this._state.findCompleted||!this._complete)throw new Error("Find operation is not completed.");const match=(_a2=this._model)==null?void 0:_a2.currentMatch$.value;return match?this._findMatchToFRange(match):null}async matchCaseAsync(matchCase){return this._state.changeState({caseSensitive:matchCase}),new Promise(resolve=>{const subscribe=this._state.stateUpdates$.subscribe(state=>{state.findCompleted===!0&&(subscribe.unsubscribe(),resolve(this))})})}async matchEntireCellAsync(matchEntireCell){return this._state.changeState({matchesTheWholeCell:matchEntireCell}),new Promise(resolve=>{const subscribe=this._state.stateUpdates$.subscribe(state=>{state.findCompleted===!0&&(subscribe.unsubscribe(),resolve(this))})})}async matchFormulaTextAsync(matchFormulaText){return this._state.changeState({findBy:matchFormulaText?findReplace.FindBy.FORMULA:findReplace.FindBy.VALUE}),new Promise(resolve=>{const subscribe=this._state.stateUpdates$.subscribe(state=>{state.findCompleted===!0&&(subscribe.unsubscribe(),resolve(this))})})}async replaceAllWithAsync(replaceText){var _a2,_b,_c;await this._state.changeState({replaceRevealed:!0,replaceString:replaceText});const res=(_c=(_b=await((_a2=this._model)==null?void 0:_a2.replaceAll()))==null?void 0:_b.success)!=null?_c:0;return this._state.changeState({replaceRevealed:!1}),res}async replaceWithAsync(replaceText){var _a2;return await this._state.changeState({replaceRevealed:!0,replaceString:replaceText}),await((_a2=this._model)==null?void 0:_a2.replace()),this._state.changeState({replaceRevealed:!1}),!0}async ensureCompleteAsync(){var _a2;return(!this._state.findCompleted||!this._complete)&&(this._complete=await((_a2=this._model)==null?void 0:_a2.start())),this._complete}_findMatchToFRange(match){const{unitId}=match,{subUnitId,range}=match.range,workbook=this._univerInstanceService.getUnit(unitId),worksheet=workbook.getSheetBySheetId(subUnitId);return this._injector.createInstance(facade.FRange,workbook,worksheet,range)}},__name(_a,"FTextFinder"),_a);FTextFinder=__decorateClass([__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.IUniverInstanceService),__decorateParam(3,findReplace.IFindReplaceService)],FTextFinder);const _FUniverFindReplaceMixin=class _FUniverFindReplaceMixin extends core.FUniver{async createTextFinderAsync(text){const state={findString:text},textFinder=this._injector.createInstance(FTextFinder,state);return await textFinder.ensureCompleteAsync(),textFinder}};__name(_FUniverFindReplaceMixin,"FUniverFindReplaceMixin");let FUniverFindReplaceMixin=_FUniverFindReplaceMixin;core.FUniver.extend(FUniverFindReplaceMixin);
package/lib/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var J=Object.defineProperty;var Z=(c,e,t)=>e in c?J(c,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):c[e]=t;var _=(c,e,t)=>Z(c,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@univerjs/core"),S=require("@univerjs/find-replace"),C=require("@univerjs/sheets"),M=require("@univerjs/engine-render"),k=require("@univerjs/sheets-ui"),v=require("rxjs"),ee="sheets-find-replace.config",O={},U={id:"sheet.command.replace",type:l.CommandType.COMMAND,handler:async(c,e)=>{const t=c.get(l.IUndoRedoService),n=c.get(l.ICommandService),{unitId:i,replacements:r}=e,s=t.__tempBatchingUndoRedo(i),o=await Promise.all(r.map(h=>n.executeCommand(C.SetRangeValuesCommand.id,{unitId:i,subUnitId:h.subUnitId,value:h.value})));return s.dispose(),te(o,r)}};function te(c,e){let t=0,n=0;return c.forEach((i,r)=>{const s=e[r].count;i?t+=s:n+=s}),{success:t,failure:n}}class ne extends M.Shape{constructor(t,n){super(t,n);_(this,"_activated",!1);_(this,"_inHiddenRange",!1);_(this,"_color");n&&this.setShapeProps(n)}setShapeProps(t){this._activated=!!t.activated,typeof t.inHiddenRange<"u"&&(this._inHiddenRange=t.inHiddenRange),typeof t.color<"u"&&(this._color=t.color),this.transformByState({width:t.width,height:t.height})}_draw(t){const n=this._activated,i=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 0.35)`,r=`rgb(${this._color.r}, ${this._color.g}, ${this._color.b})`;M.Rect.drawWith(t,{width:this.width,height:this.height,fill:i,stroke:n?r:void 0,strokeWidth:n?2:0,evented:!1})}}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 ie(c,e){return c.startRow>e.startRow||c.startRow===e.startRow&&c.startColumn>=e.startColumn}function se(c,e){return c.startColumn>e.startColumn||c.startColumn===e.startColumn&&c.startRow>=e.startRow}function re(c,e){const{range:t}=c,{startRow:n,startColumn:i}=t,r=e.getMergedCell(n,i);return r?l.Rectangle.equals(t,r):t.endRow===t.startRow&&t.endColumn===t.startColumn}var oe=Object.defineProperty,ce=Object.getOwnPropertyDescriptor,B=(c,e,t,n)=>{for(var i=n>1?void 0:n?ce(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&&oe(e,t,i),i},I=(c,e)=>(t,n)=>e(t,n,c);exports.SheetsFindReplaceController=class extends l.Disposable{constructor(t,n,i,r,s){super();_(this,"_provider");this._injector=t,this._findReplaceController=n,this._contextService=i,this._findReplaceService=r,this._commandService=s,this._init(),this._initCommands()}dispose(){super.dispose(),this._findReplaceController.closePanel(),this._provider.dispose()}_init(){const t=this._injector.createInstance(P);this._provider=t,this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(t)),this.disposeWithMe(this._contextService.subscribeContextValue$(l.EDITOR_ACTIVATED).pipe(v.filter(n=>!!n)).subscribe(()=>this._findReplaceController.closePanel()))}_initCommands(){[U].forEach(t=>this.disposeWithMe(this._commandService.registerCommand(t)))}};exports.SheetsFindReplaceController=B([I(0,l.Inject(l.Injector)),I(1,l.Inject(S.FindReplaceController)),I(2,l.IContextService),I(3,S.IFindReplaceService),I(4,l.ICommandService)],exports.SheetsFindReplaceController);const he="sheets-find-replace-provider",ae=1e4;let F=class extends S.FindModel{constructor(e,t,n,i,r,s,o,h){super();_(this,"_matchesUpdate$",new v.Subject);_(this,"matchesUpdate$",this._matchesUpdate$.asObservable());_(this,"_activelyChangingMatch$",new v.Subject);_(this,"activelyChangingMatch$",this._activelyChangingMatch$.asObservable());_(this,"_matchesByWorksheet",new Map);_(this,"_matches",[]);_(this,"_matchesPosition",0);_(this,"_activeHighlightIndex",-1);_(this,"_highlightShapes",[]);_(this,"_currentHighlightShape",null);_(this,"_query",null);_(this,"_workbookSelections");this._workbook=e,this._sheetSkeletonManagerService=t,this._univerInstanceService=n,this._renderManagerService=i,this._commandService=r,this._contextService=s,this._themeService=o,this._workbookSelections=h.getWorkbookSelections(this.unitId)}get _matchesCount(){return this._matches.length}get unitId(){return this._workbook.getUnitId()}get matchesCount(){return this._matchesCount}get matchesPosition(){return this._matchesPosition}get currentMatch(){return this._matchesPosition>0?this._matches[this._matchesPosition-1]:null}dispose(){super.dispose(),this._disposeHighlights(),this._toggleDisplayRawFormula(!1)}getMatches(){return this._matches}start(e){switch(this._query=e,e.findBy===S.FindBy.FORMULA?this._toggleDisplayRawFormula(!0):this._toggleDisplayRawFormula(!1),e.findScope){case S.FindScope.UNIT:this.findInWorkbook(e);break;case S.FindScope.SUBUNIT:default:this.findInActiveWorksheet(e);break}}_toggleDisplayRawFormula(e){this._contextService.setContextValue(M.RENDER_RAW_FORMULA_KEY,e)}findInWorkbook(e){const t=this._workbook.getUnitId();let n,i=!0;const r=()=>{const s=this._workbook.getSheets().filter(o=>!o.isSheetHidden()).map(o=>{const h=this._findInWorksheet(o,e,t),d=o.getSheetId(),{results:a}=h;return a.length?this._matchesByWorksheet.set(d,h.results):this._matchesByWorksheet.delete(d),h});this._matches=s.map(o=>o.results).flat(),this._updateFindHighlight(),i?(n={results:this._matches},i=!1):this._matchesUpdate$.next(this._matches)};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>{this._updateFindHighlight(),this._updateCurrentHighlightShape(this._activeHighlightIndex)})),this.disposeWithMe(l.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(v.filter(([s,o])=>s.id===C.SetWorksheetActiveOperation.id&&!(o!=null&&o.fromFindReplace))).subscribe(()=>{const s=this._workbook.getActiveSheet();if(!s)return;const o=s.getSheetId();this._matchesByWorksheet.has(o)&&this._findNextMatchOnActiveSheetChange(s)})),this.disposeWithMe(l.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(v.filter(([s])=>s.type===l.CommandType.MUTATION&&s.params.unitId===this._workbook.getUnitId()),v.throttleTime(600,void 0,{leading:!1,trailing:!0})).subscribe(()=>r())),r(),n}_findNextMatchOnActiveSheetChange(e){let t,n,i=0;const r=this._matchesByWorksheet.get(e.getSheetId()),s=this._workbookSelections.getCurrentSelections();s!=null&&s.length?([t,i]=this._findNextMatchByRange(r,s[0].range),n=r.findIndex(o=>o===t)):(t=r[0],n=0,i=this._matches.findIndex(o=>o===t)),this._matchesPosition=i+1,this._activelyChangingMatch$.next(t),this._activeHighlightIndex=n,this._updateFindHighlight(),this._updateCurrentHighlightShape(n)}findInActiveWorksheet(e){const t=this._workbook.getUnitId(),n=()=>{var u;const h=this._workbook.getActiveSheet();if(!h)return!1;const d=this._workbookSelections.getCurrentSelections();return(u=d==null?void 0:d.some(g=>!re(g,h)))!=null?u:!1};let i,r=!0,s=!1;const o=()=>{const h=this._workbook.getActiveSheet();if(!h)return{results:[]};const d=this.currentMatch;s=n();const a=this._workbookSelections.getCurrentSelections(),u=s?this._findInSelections(h,a,e,t):this._findInWorksheet(h,e,t);return this._matches=u.results,this._matchesPosition=this._tryRestoreLastMatchesPosition(d,this._matches),r?(i=u,r=!1):this._matchesUpdate$.next(this._matches),this._updateFindHighlight(),u};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>this._updateFindHighlight())),this.disposeWithMe(v.merge(l.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(v.filter(([h])=>{if(h.type===l.CommandType.MUTATION&&h.params.unitId===this._workbook.getUnitId())return!0;if(h.id===C.SetSelectionsOperation.id&&h.params.unitId===t){const d=n();return d===!1&&s===!1?!1:(s=d,!0)}return!1})),this._workbook.activeSheet$.pipe(v.skip(1))).pipe(v.debounceTime(200)).subscribe(()=>o())),o(),i}_findInRange(e,t,n,i,r){const s=[],o=e.getSheetId(),h=(t.findDirection===S.FindDirection.COLUMN?e.iterateByColumn:e.iterateByRow).bind(e)(n);for(const d of h){const{row:a,col:u,colSpan:g,rowSpan:m,value:p}=d;if(r!=null&&r(a,u)||!p||e.getRowFiltered(a))continue;const{hit:R,replaceable:w,isFormula:b}=le(e,a,u,t,p);if(R){const y={provider:he,unitId:i,replaceable:w,isFormula:b,range:{subUnitId:o,range:{startRow:a,startColumn:u,endColumn:u+(g!=null?g:1)-1,endRow:a+(m!=null?m:1)-1}}};s.push(y)}}return{results:s}}_findInSelections(e,t,n,i){const{findDirection:r}=n,s=r===S.FindDirection.ROW?D:N,o=new Set;return{results:t.map(d=>this._findInRange(e,n,d.range,i,(a,u)=>{const g=`${a}-${u}`;return o.has(g)?!0:(o.add(g),!1)}).results).flat().sort((d,a)=>s(d.range.range,a.range.range)?-1:1)}}_findInWorksheet(e,t,n){const i=e.getRowCount(),r=e.getColumnCount(),s={startRow:0,startColumn:0,endRow:i-1,endColumn:r-1};return this._findInRange(e,t,s,n)}_disposeHighlights(){var e;this._highlightShapes.forEach(t=>{var n;(n=t.getScene())==null||n.makeDirty(),t.dispose()}),this._highlightShapes=[],(e=this._currentHighlightShape)==null||e.dispose(),this._currentHighlightShape=null}_updateFindHighlight(){var u;this._disposeHighlights();const e=(u=this._sheetSkeletonManagerService.getCurrent())==null?void 0:u.skeleton;if(!e)return;const t=this._workbook.getUnitId(),n=this._renderManagerService.getRenderById(t);if(n==null)return;const{scene:i}=n,r=this._matches,s=this._themeService.getCurrentTheme().gold400,o=new l.ColorKit(s).toRgb(),h=this._workbook.getActiveSheet();if(!h)return;const d=h.getSheetId(),a=r.filter(g=>g.range.subUnitId===d).map((g,m)=>{const{startColumn:p,startRow:R,endColumn:w,endRow:b}=g.range.range,y=k.getCoordByCell(R,p,i,e),G=k.getCoordByCell(b,w,i,e),{startX:W,startY:H}=y,{endX:Y,endY:q}=G,T=!h.getRowRawVisible(R),E=!h.getColVisible(p),K=T||E,Q=E?2:Y-W,X=T?2:q-H,z={left:W,top:H,color:o,width:Q,height:X,evented:!1,inHiddenRange:K,zIndex:ae};return new ne(`find-highlight-${m}`,z)});i.addObjects(a),this._highlightShapes=a,i.makeDirty()}_updateCurrentHighlightShape(e){var t;if((t=this._currentHighlightShape)==null||t.setShapeProps({activated:!1}),this._currentHighlightShape=null,e!==void 0){const n=this._highlightShapes[e];if(!n)return;this._currentHighlightShape=n,n.setShapeProps({activated:!0})}}_getSheetObject(){return k.getSheetObject(this._univerInstanceService,this._renderManagerService)}_focusMatch(e){var n;const t=e.range.subUnitId;t!==((n=this._workbook.getActiveSheet())==null?void 0:n.getSheetId())&&this._commandService.executeCommand(C.SetWorksheetActivateCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:t},{fromFindReplace:!0}),this._commandService.executeCommand(k.ScrollToCellCommand.id,{range:e.range.range},{fromFindReplace:!0})}_tryRestoreLastMatchesPosition(e,t){if(!e)return 0;const{subUnitId:n}=e.range,{startColumn:i,startRow:r}=e.range.range,s=t.findIndex(o=>{if(n!==o.range.subUnitId)return!1;const{startColumn:h,startRow:d}=o.range.range;return h===i&&d===r});return s>-1?s+1:0}moveToNextMatch(e){var o,h,d,a,u;if(!this._matches.length)return null;const t=(o=e==null?void 0:e.loop)!=null?o:!1,n=(h=e==null?void 0:e.stayIfOnMatch)!=null?h:!1,i=(d=e==null?void 0:e.noFocus)!=null?d:!1,r=(a=e==null?void 0:e.ignoreSelection)!=null?a:!1,s=this._findNextMatch(t,n,r);if(s){const[g,m]=s;return this._matchesPosition=m+1,this._query.findScope===S.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(g.range.subUnitId).findIndex(p=>p===g):this._activeHighlightIndex=m,i||this._focusMatch(g),((u=this._workbook.getActiveSheet())==null?void 0:u.getSheetId())===g.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),g}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}moveToPreviousMatch(e){var o,h,d,a,u;if(!this._matches.length)return null;const t=(o=e==null?void 0:e.loop)!=null?o:!1,n=(h=e==null?void 0:e.stayIfOnMatch)!=null?h:!1,i=(d=e==null?void 0:e.noFocus)!=null?d:!1,r=(a=e==null?void 0:e.ignoreSelection)!=null?a:!1,s=this._findPreviousMatch(t,n,r);if(s){const[g,m]=s;return this._matchesPosition=m+1,this._query.findScope===S.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(g.range.subUnitId).findIndex(p=>p===g):this._activeHighlightIndex=m,i||this._focusMatch(g),((u=this._workbook.getActiveSheet())==null?void 0:u.getSheetId())===g.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),g}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}_findPreviousMatch(e=!1,t=!1,n=!1){var o;if(this.currentMatch){const h=this._matches.findIndex(g=>g===this.currentMatch);if(t)return[this.currentMatch,h];const d=h-1;if(!e&&d<0)return null;const a=this._matches.length,u=(d+a)%a;return[this._matches[u],u]}const i=this._workbookSelections.getCurrentLastSelection();if(n||!i){const h=this._matches.length-1;return[this._matches[h],h]}if(this._query.findScope!==S.FindScope.UNIT)return this._findPreviousMatchByRange(this._matches,i.range);const r=(o=this._workbook.getActiveSheet())==null?void 0:o.getSheetId();if(!r)return null;const s=this._findPreviousWorksheetThatHasAMatch(r,e);return s?this._findPreviousMatchByRange(this._matchesByWorksheet.get(s),i.range):null}_findNextMatch(e=!1,t=!1,n=!1){var o;if(this.currentMatch){const h=this._matches.findIndex(g=>g===this.currentMatch);if(t)return[this.currentMatch,h];const d=h+1,a=this._matches.length;if(!e&&d>=a)return null;const u=d%a;return[this._matches[u],u]}const i=this._workbookSelections.getCurrentLastSelection();if(n||!i)return[this._matches[0],0];if(this._query.findScope!==S.FindScope.UNIT)return this._findNextMatchByRange(this._matches,i.range,t);const r=(o=this._workbook.getActiveSheet())==null?void 0:o.getSheetId();if(!r)return null;const s=this._findNextWorksheetThatHasAMatch(r,e);return s?this._findNextMatchByRange(this._matchesByWorksheet.get(s),i.range):null}_findPreviousWorksheetThatHasAMatch(e,t=!1){const n=this._workbook.getSheetOrders(),i=n.findIndex(o=>o===e),s=(t?l.rotate(n,i+1):n.slice(0,i+1)).findLast(o=>this._matchesByWorksheet.has(o));return s!=null?s:null}_findNextWorksheetThatHasAMatch(e,t=!1){const n=this._workbook.getSheetOrders(),i=n.findIndex(o=>o===e),s=(t?l.rotate(n,i):n.slice(i)).find(o=>this._matchesByWorksheet.has(o));return s!=null?s:null}_findNextMatchByRange(e,t,n=!1){const i=this._query.findDirection===S.FindDirection.ROW;let r=e.findIndex(o=>{const h=o.range.range;if(!(i?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?ie(t,h):se(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(C.SetRangeValuesCommand.id,r)}async replaceAll(e){if(this._matchesCount===0||!this._query)return{success:0,failure:0};const t=this._workbook.getUnitId(),{findString:n,caseSensitive:i,findBy:r}=this._query,s=r===S.FindBy.FORMULA,o=i?"g":"ig",h=[];return l.groupBy(this._matches.filter(a=>a.replaceable),a=>a.range.subUnitId).forEach((a,u)=>{const g=new l.ObjectMatrix,m=this._workbook.getSheetBySheetId(u);a.forEach(p=>{const{startColumn:R,startRow:w}=p.range.range,b=this._getReplacedCellData(p,m,s,n,e,o);b&&g.setValue(w,R,b)}),h.push({count:a.length,subUnitId:u,value:g.getMatrix()})}),h?this._commandService.executeCommand(U.id,{unitId:t,replacements:h}):{success:0,failure:0}}_getReplacedCellData(e,t,n,i,r,s){var m;const o=e.range.range,{startRow:h,startColumn:d}=o,a=t.getCellRaw(h,d);if(e.isFormula)return n?{f:a.f.replace(new RegExp($(i),s),r),v:null}:null;if(!!((m=a.p)!=null&&m.body)){const p=l.Tools.deepClone(a.p);return l.replaceInDocumentBody(p.body,i,r,this._query.caseSensitive),{p}}return{v:a.v.toString().replace(new RegExp($(i),s),r)}}};F=B([I(2,l.IUniverInstanceService),I(3,M.IRenderManagerService),I(4,l.ICommandService),I(5,l.IContextService),I(6,l.Inject(l.ThemeService)),I(7,l.Inject(C.SheetsSelectionsService))],F);function $(c){return c.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}let P=class extends l.Disposable{constructor(e,t,n){super();_(this,"_findModelsByUnitId",new Map);this._univerInstanceService=e,this._renderManagerService=t,this._injector=n}async find(e){this._terminate();const t=this._univerInstanceService.getAllUnitsForType(l.UniverInstanceType.UNIVER_SHEET),n=this._preprocessQuery(e);return t.map(r=>{const s=this._renderManagerService.getRenderById(r.getUnitId()).with(k.SheetSkeletonManagerService),o=this._injector.createInstance(F,r,s);return this._findModelsByUnitId.set(r.getUnitId(),o),o.start(n),o})}terminate(){this._terminate()}_terminate(){this._findModelsByUnitId.forEach(e=>e.dispose()),this._findModelsByUnitId.clear()}_preprocessQuery(e){let t=e.caseSensitive?e.findString:e.findString.toLowerCase();return t=t.trim(),{...e,findString:t}}};P=B([I(0,l.IUniverInstanceService),I(1,M.IRenderManagerService),I(2,l.Inject(l.Injector))],P);const f={hit:!1,replaceable:!1,isFormula:!1,rawData:null};function le(c,e,t,n,i){const{findBy:r}=n,s=r===S.FindBy.FORMULA,o=c.getCellRaw(e,t);return f.rawData=o,!(o!=null&&o.f)?(f.isFormula=!1,x(i,n)?o?(f.hit=!0,f.replaceable=!0):(f.hit=!0,f.replaceable=!1):(f.hit=!1,f.replaceable=!1),f):(f.isFormula=!0,s?x({v:o.f},n)?(f.hit=!0,f.replaceable=!0,f):(f.hit=!1,f.replaceable=!1,f):(f.replaceable=!1,x(i,n)?f.hit=!0:f.hit=!1,f))}function x(c,e){let t=de(c);return t?e.matchesTheWholeCell?(t=ue(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 de(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 ue(c){return c.replace(/^ +/g,"").replace(/ +$/g,"")}var L=Object.defineProperty,ge=Object.getOwnPropertyDescriptor,fe=(c,e,t)=>e in c?L(c,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):c[e]=t,_e=(c,e,t,n)=>{for(var i=n>1?void 0:n?ge(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&&L(e,t,i),i},j=(c,e)=>(t,n)=>e(t,n,c),V=(c,e,t)=>fe(c,typeof e!="symbol"?e+"":e,t);const Se="SHEET_FIND_REPLACE_PLUGIN";exports.UniverSheetsFindReplacePlugin=class extends l.Plugin{constructor(e=O,t,n){super(),this._config=e,this._injector=t,this._configService=n;const{...i}=l.merge({},O,this._config);this._configService.setConfig(ee,i)}onStarting(){[[exports.SheetsFindReplaceController]].forEach(e=>this._injector.add(e))}onSteady(){this._injector.get(exports.SheetsFindReplaceController)}};V(exports.UniverSheetsFindReplacePlugin,"pluginName",Se);V(exports.UniverSheetsFindReplacePlugin,"type",l.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsFindReplacePlugin=_e([l.DependentOn(C.UniverSheetsPlugin,C.UniverSheetsPlugin,S.UniverFindReplacePlugin),j(1,l.Inject(l.Injector)),j(2,l.IConfigService)],exports.UniverSheetsFindReplacePlugin);exports.SheetReplaceCommand=U;
1
+ "use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const core=require("@univerjs/core"),findReplace=require("@univerjs/find-replace"),sheets=require("@univerjs/sheets"),engineRender=require("@univerjs/engine-render"),sheetsUi=require("@univerjs/sheets-ui"),rxjs=require("rxjs"),SHEETS_FIND_REPLACE_PLUGIN_CONFIG_KEY="sheets-find-replace.config",defaultPluginConfig={},SheetReplaceCommand={id:"sheet.command.replace",type:core.CommandType.COMMAND,handler:__name(async(accessor,params)=>{const undoRedoService=accessor.get(core.IUndoRedoService),commandService=accessor.get(core.ICommandService),{unitId,replacements}=params,disposeBatchingHandler=undoRedoService.__tempBatchingUndoRedo(unitId),results=await Promise.all(replacements.map(replacement=>commandService.executeCommand(sheets.SetRangeValuesCommand.id,{unitId,subUnitId:replacement.subUnitId,value:replacement.value})));return disposeBatchingHandler.dispose(),getReplaceAllResult(results,replacements)},"handler")};function getReplaceAllResult(results,replacements){let success=0,failure=0;return results.forEach((r,index)=>{const count=replacements[index].count;r?success+=count:failure+=count}),{success,failure}}__name(getReplaceAllResult,"getReplaceAllResult");const _SheetFindReplaceHighlightShape=class _SheetFindReplaceHighlightShape extends engineRender.Shape{constructor(key,props){super(key,props);__publicField(this,"_activated",!1);__publicField(this,"_inHiddenRange",!1);__publicField(this,"_color");props&&this.setShapeProps(props)}setShapeProps(props){this._activated=!!props.activated,typeof props.inHiddenRange<"u"&&(this._inHiddenRange=props.inHiddenRange),typeof props.color<"u"&&(this._color=props.color),this.transformByState({width:props.width,height:props.height})}_draw(ctx){const activated=this._activated,color=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 0.35)`,borderColor=`rgb(${this._color.r}, ${this._color.g}, ${this._color.b})`;engineRender.Rect.drawWith(ctx,{width:this.width,height:this.height,fill:color,stroke:activated?borderColor:void 0,strokeWidth:activated?2:0,evented:!1})}};__name(_SheetFindReplaceHighlightShape,"SheetFindReplaceHighlightShape");let SheetFindReplaceHighlightShape=_SheetFindReplaceHighlightShape;function isSamePosition(range1,range2){return range1.startRow===range2.startRow&&range1.startColumn===range2.startColumn}__name(isSamePosition,"isSamePosition");function isBehindPositionWithRowPriority(range1,range2){return range1.startRow<range2.startRow||range1.startRow===range2.startRow&&range1.startColumn<=range2.startColumn}__name(isBehindPositionWithRowPriority,"isBehindPositionWithRowPriority");function isBehindPositionWithColumnPriority(range1,range2){return range1.startColumn<range2.startColumn||range1.startColumn===range2.startColumn&&range1.startRow<=range2.startRow}__name(isBehindPositionWithColumnPriority,"isBehindPositionWithColumnPriority");function isBeforePositionWithRowPriority(range1,range2){return range1.startRow>range2.startRow||range1.startRow===range2.startRow&&range1.startColumn>=range2.startColumn}__name(isBeforePositionWithRowPriority,"isBeforePositionWithRowPriority");function isBeforePositionWithColumnPriority(range1,range2){return range1.startColumn>range2.startColumn||range1.startColumn===range2.startColumn&&range1.startRow>=range2.startRow}__name(isBeforePositionWithColumnPriority,"isBeforePositionWithColumnPriority");function isSelectionSingleCell(selection,worksheet){const{range}=selection,{startRow,startColumn}=range,hasMergedCell=worksheet.getMergedCell(startRow,startColumn);return hasMergedCell?core.Rectangle.equals(range,hasMergedCell):range.endRow===range.startRow&&range.endColumn===range.startColumn}__name(isSelectionSingleCell,"isSelectionSingleCell");var __defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$1"),_a;exports.SheetsFindReplaceController=(_a=class extends core.Disposable{constructor(_injector,_findReplaceController,_contextService,_findReplaceService,_commandService){super();__publicField(this,"_provider");this._injector=_injector,this._findReplaceController=_findReplaceController,this._contextService=_contextService,this._findReplaceService=_findReplaceService,this._commandService=_commandService,this._init(),this._initCommands()}dispose(){super.dispose(),this._findReplaceController.closePanel(),this._provider.dispose()}_init(){const provider=this._injector.createInstance(SheetsFindReplaceProvider);this._provider=provider,this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(provider)),this.disposeWithMe(this._contextService.subscribeContextValue$(core.EDITOR_ACTIVATED).pipe(rxjs.filter(v=>!!v)).subscribe(()=>this._findReplaceController.closePanel()))}_initCommands(){[SheetReplaceCommand].forEach(command=>this.disposeWithMe(this._commandService.registerCommand(command)))}},__name(_a,"SheetsFindReplaceController"),_a);exports.SheetsFindReplaceController=__decorateClass$1([__decorateParam$1(0,core.Inject(core.Injector)),__decorateParam$1(1,core.Inject(findReplace.FindReplaceController)),__decorateParam$1(2,core.IContextService),__decorateParam$1(3,findReplace.IFindReplaceService),__decorateParam$1(4,core.ICommandService)],exports.SheetsFindReplaceController);const SHEETS_FIND_REPLACE_PROVIDER_NAME="sheets-find-replace-provider",FIND_REPLACE_Z_INDEX=1e4;var _a2;let SheetFindModel=(_a2=class extends findReplace.FindModel{constructor(_workbook,_sheetSkeletonManagerService,_univerInstanceService,_renderManagerService,_commandService,_contextService,_themeService,_selectionManagerService){super();__publicField(this,"_matchesUpdate$",new rxjs.Subject);__publicField(this,"matchesUpdate$",this._matchesUpdate$.asObservable());__publicField(this,"_activelyChangingMatch$",new rxjs.Subject);__publicField(this,"activelyChangingMatch$",this._activelyChangingMatch$.asObservable());__publicField(this,"_matchesByWorksheet",new Map);__publicField(this,"_matches",[]);__publicField(this,"_matchesPosition",0);__publicField(this,"_activeHighlightIndex",-1);__publicField(this,"_highlightShapes",[]);__publicField(this,"_currentHighlightShape",null);__publicField(this,"_query",null);__publicField(this,"_workbookSelections");this._workbook=_workbook,this._sheetSkeletonManagerService=_sheetSkeletonManagerService,this._univerInstanceService=_univerInstanceService,this._renderManagerService=_renderManagerService,this._commandService=_commandService,this._contextService=_contextService,this._themeService=_themeService,this._workbookSelections=_selectionManagerService.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(query){switch(this._query=query,query.findBy===findReplace.FindBy.FORMULA?this._toggleDisplayRawFormula(!0):this._toggleDisplayRawFormula(!1),query.findScope){case findReplace.FindScope.UNIT:this.findInWorkbook(query);break;case findReplace.FindScope.SUBUNIT:default:this.findInActiveWorksheet(query);break}}_toggleDisplayRawFormula(force){this._contextService.setContextValue(engineRender.RENDER_RAW_FORMULA_KEY,force)}findInWorkbook(query){const unitId=this._workbook.getUnitId();let complete,firstSearch=!0;const findInWorkbook=__name(()=>{const allCompletes=this._workbook.getSheets().filter(worksheet=>!worksheet.isSheetHidden()).map(worksheet=>{const complete2=this._findInWorksheet(worksheet,query,unitId),sheetId=worksheet.getSheetId(),{results}=complete2;return results.length?this._matchesByWorksheet.set(sheetId,complete2.results):this._matchesByWorksheet.delete(sheetId),complete2});this._matches=allCompletes.map(c=>c.results).flat(),this._updateFindHighlight(),firstSearch?(complete={results:this._matches},firstSearch=!1):this._matchesUpdate$.next(this._matches)},"findInWorkbook");return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>{this._updateFindHighlight(),this._updateCurrentHighlightShape(this._activeHighlightIndex)})),this.disposeWithMe(core.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(rxjs.filter(([command,options])=>command.id===sheets.SetWorksheetActiveOperation.id&&!(options!=null&&options.fromFindReplace))).subscribe(()=>{const activeSheet=this._workbook.getActiveSheet();if(!activeSheet)return;const activeSheetId=activeSheet.getSheetId();this._matchesByWorksheet.has(activeSheetId)&&this._findNextMatchOnActiveSheetChange(activeSheet)})),this.disposeWithMe(core.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(rxjs.filter(([command])=>command.type===core.CommandType.MUTATION&&command.params.unitId===this._workbook.getUnitId()),rxjs.throttleTime(600,void 0,{leading:!1,trailing:!0})).subscribe(()=>findInWorkbook())),findInWorkbook(),complete}_findNextMatchOnActiveSheetChange(activeSheet){let match,index,globalIndex=0;const matchesByWorksheet=this._matchesByWorksheet.get(activeSheet.getSheetId()),selections=this._workbookSelections.getCurrentSelections();selections!=null&&selections.length?([match,globalIndex]=this._findNextMatchByRange(matchesByWorksheet,selections[0].range),index=matchesByWorksheet.findIndex(m=>m===match)):(match=matchesByWorksheet[0],index=0,globalIndex=this._matches.findIndex(m=>m===match)),this._matchesPosition=globalIndex+1,this._activelyChangingMatch$.next(match),this._activeHighlightIndex=index,this._updateFindHighlight(),this._updateCurrentHighlightShape(index)}findInActiveWorksheet(query){const unitId=this._workbook.getUnitId(),checkShouldFindInSelections=__name(()=>{var _a5;const currentWorksheet=this._workbook.getActiveSheet();if(!currentWorksheet)return!1;const currentSelections=this._workbookSelections.getCurrentSelections();return(_a5=currentSelections==null?void 0:currentSelections.some(selection=>!isSelectionSingleCell(selection,currentWorksheet)))!=null?_a5:!1},"checkShouldFindInSelections");let complete,firstSearch=!0,findBySelections=!1;const performFindInWorksheet=__name(()=>{const currentWorksheet=this._workbook.getActiveSheet();if(!currentWorksheet)return{results:[]};const lastMatch=this.currentMatch;findBySelections=checkShouldFindInSelections();const currentSelections=this._workbookSelections.getCurrentSelections(),newComplete=findBySelections?this._findInSelections(currentWorksheet,currentSelections,query,unitId):this._findInWorksheet(currentWorksheet,query,unitId);return this._matches=newComplete.results,this._matchesPosition=this._tryRestoreLastMatchesPosition(lastMatch,this._matches),firstSearch?(complete=newComplete,firstSearch=!1):this._matchesUpdate$.next(this._matches),this._updateFindHighlight(),newComplete},"performFindInWorksheet");return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>this._updateFindHighlight())),this.disposeWithMe(rxjs.merge(core.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(rxjs.filter(([command])=>{if(command.type===core.CommandType.MUTATION&&command.params.unitId===this._workbook.getUnitId())return!0;if(command.id===sheets.SetSelectionsOperation.id&&command.params.unitId===unitId){const shouldFindBySelections=checkShouldFindInSelections();return shouldFindBySelections===!1&&findBySelections===!1?!1:(findBySelections=shouldFindBySelections,!0)}return!1})),this._workbook.activeSheet$.pipe(rxjs.skip(1))).pipe(rxjs.debounceTime(200)).subscribe(()=>performFindInWorksheet())),performFindInWorksheet(),complete}_findInRange(worksheet,query,range,unitId,dedupeFn){const results=[],subUnitId=worksheet.getSheetId(),iter=(query.findDirection===findReplace.FindDirection.COLUMN?worksheet.iterateByColumn:worksheet.iterateByRow).bind(worksheet)(range);for(const value of iter){const{row,col,colSpan,rowSpan,value:cellData}=value;if(dedupeFn!=null&&dedupeFn(row,col)||!cellData||worksheet.getRowFiltered(row))continue;const{hit,replaceable,isFormula}=hitCell(worksheet,row,col,query,cellData);if(hit){const result={provider:SHEETS_FIND_REPLACE_PROVIDER_NAME,unitId,replaceable,isFormula,range:{subUnitId,range:{startRow:row,startColumn:col,endColumn:col+(colSpan!=null?colSpan:1)-1,endRow:row+(rowSpan!=null?rowSpan:1)-1}}};results.push(result)}}return{results}}_findInSelections(worksheet,selections,query,unitId){const{findDirection}=query,sortFn=findDirection===findReplace.FindDirection.ROW?isBehindPositionWithRowPriority:isBehindPositionWithColumnPriority,dedupeSet=new Set;return{results:selections.map(selection=>this._findInRange(worksheet,query,selection.range,unitId,(row,col)=>{const key=`${row}-${col}`;return dedupeSet.has(key)?!0:(dedupeSet.add(key),!1)}).results).flat().sort((a,b)=>sortFn(a.range.range,b.range.range)?-1:1)}}_findInWorksheet(worksheet,query,unitId){const rowCount=worksheet.getRowCount(),colCount=worksheet.getColumnCount(),range={startRow:0,startColumn:0,endRow:rowCount-1,endColumn:colCount-1};return this._findInRange(worksheet,query,range,unitId)}_disposeHighlights(){var _a5;this._highlightShapes.forEach(shape=>{var _a6;(_a6=shape.getScene())==null||_a6.makeDirty(),shape.dispose()}),this._highlightShapes=[],(_a5=this._currentHighlightShape)==null||_a5.dispose(),this._currentHighlightShape=null}_updateFindHighlight(){var _a5;this._disposeHighlights();const skeleton=(_a5=this._sheetSkeletonManagerService.getCurrent())==null?void 0:_a5.skeleton;if(!skeleton)return;const unitId=this._workbook.getUnitId(),currentRender=this._renderManagerService.getRenderById(unitId);if(currentRender==null)return;const{scene}=currentRender,matches=this._matches,searchBackgroundColor=this._themeService.getCurrentTheme().gold400,color=new core.ColorKit(searchBackgroundColor).toRgb(),worksheet=this._workbook.getActiveSheet();if(!worksheet)return;const activeSheetId=worksheet.getSheetId(),highlightShapes=matches.filter(match=>match.range.subUnitId===activeSheetId).map((find,index)=>{const{startColumn,startRow,endColumn,endRow}=find.range.range,startPosition=sheetsUi.getCoordByCell(startRow,startColumn,scene,skeleton),endPosition=sheetsUi.getCoordByCell(endRow,endColumn,scene,skeleton),{startX,startY}=startPosition,{endX,endY}=endPosition,rowHidden=!worksheet.getRowRawVisible(startRow),columnHidden=!worksheet.getColVisible(startColumn),inHiddenRange=rowHidden||columnHidden,width=columnHidden?2:endX-startX,height=rowHidden?2:endY-startY,props={left:startX,top:startY,color,width,height,evented:!1,inHiddenRange,zIndex:FIND_REPLACE_Z_INDEX};return new SheetFindReplaceHighlightShape(`find-highlight-${index}`,props)});scene.addObjects(highlightShapes),this._highlightShapes=highlightShapes,scene.makeDirty()}_updateCurrentHighlightShape(matchIndex){var _a5;if((_a5=this._currentHighlightShape)==null||_a5.setShapeProps({activated:!1}),this._currentHighlightShape=null,matchIndex!==void 0){const shape=this._highlightShapes[matchIndex];if(!shape)return;this._currentHighlightShape=shape,shape.setShapeProps({activated:!0})}}_getSheetObject(){return sheetsUi.getSheetObject(this._univerInstanceService,this._renderManagerService)}_focusMatch(match){var _a5;const subUnitId=match.range.subUnitId;subUnitId!==((_a5=this._workbook.getActiveSheet())==null?void 0:_a5.getSheetId())&&this._commandService.executeCommand(sheets.SetWorksheetActivateCommand.id,{unitId:this._workbook.getUnitId(),subUnitId},{fromFindReplace:!0}),this._commandService.executeCommand(sheetsUi.ScrollToCellCommand.id,{range:match.range.range},{fromFindReplace:!0})}_tryRestoreLastMatchesPosition(lastMatch,newMatches){if(!lastMatch)return 0;const{subUnitId:lastSubUnitId}=lastMatch.range,{startColumn:lastStartColumn,startRow:lastStartRow}=lastMatch.range.range,index=newMatches.findIndex(match=>{if(lastSubUnitId!==match.range.subUnitId)return!1;const{startColumn,startRow}=match.range.range;return startColumn===lastStartColumn&&startRow===lastStartRow});return index>-1?index+1:0}moveToNextMatch(params){var _a5,_b,_c,_d,_e;if(!this._matches.length)return null;const loop=(_a5=params==null?void 0:params.loop)!=null?_a5:!1,stayIfOnMatch=(_b=params==null?void 0:params.stayIfOnMatch)!=null?_b:!1,noFocus=(_c=params==null?void 0:params.noFocus)!=null?_c:!1,ignoreSelection=(_d=params==null?void 0:params.ignoreSelection)!=null?_d:!1,matchToMove=this._findNextMatch(loop,stayIfOnMatch,ignoreSelection);if(matchToMove){const[match,index]=matchToMove;return this._matchesPosition=index+1,this._query.findScope===findReplace.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(match.range.subUnitId).findIndex(m=>m===match):this._activeHighlightIndex=index,noFocus||this._focusMatch(match),((_e=this._workbook.getActiveSheet())==null?void 0:_e.getSheetId())===match.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),match}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}moveToPreviousMatch(params){var _a5,_b,_c,_d,_e;if(!this._matches.length)return null;const loop=(_a5=params==null?void 0:params.loop)!=null?_a5:!1,stayIfOnMatch=(_b=params==null?void 0:params.stayIfOnMatch)!=null?_b:!1,noFocus=(_c=params==null?void 0:params.noFocus)!=null?_c:!1,ignoreSelection=(_d=params==null?void 0:params.ignoreSelection)!=null?_d:!1,matchToMove=this._findPreviousMatch(loop,stayIfOnMatch,ignoreSelection);if(matchToMove){const[match,index]=matchToMove;return this._matchesPosition=index+1,this._query.findScope===findReplace.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(match.range.subUnitId).findIndex(m=>m===match):this._activeHighlightIndex=index,noFocus||this._focusMatch(match),((_e=this._workbook.getActiveSheet())==null?void 0:_e.getSheetId())===match.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),match}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}_findPreviousMatch(loop=!1,stayIfOnMatch=!1,ignoreSelection=!1){var _a5;if(this.currentMatch){const currentMatchIndex=this._matches.findIndex(match=>match===this.currentMatch);if(stayIfOnMatch)return[this.currentMatch,currentMatchIndex];const nextMatchIndex=currentMatchIndex-1;if(!loop&&nextMatchIndex<0)return null;const length=this._matches.length,modded=(nextMatchIndex+length)%length;return[this._matches[modded],modded]}const lastSelection=this._workbookSelections.getCurrentLastSelection();if(ignoreSelection||!lastSelection){const lastIndex=this._matches.length-1;return[this._matches[lastIndex],lastIndex]}if(this._query.findScope!==findReplace.FindScope.UNIT)return this._findPreviousMatchByRange(this._matches,lastSelection.range);const currentSheetId=(_a5=this._workbook.getActiveSheet())==null?void 0:_a5.getSheetId();if(!currentSheetId)return null;const worksheetThatHasMatch=this._findPreviousWorksheetThatHasAMatch(currentSheetId,loop);return worksheetThatHasMatch?this._findPreviousMatchByRange(this._matchesByWorksheet.get(worksheetThatHasMatch),lastSelection.range):null}_findNextMatch(loop=!1,stayIfOnMatch=!1,ignoreSelection=!1){var _a5;if(this.currentMatch){const currentMatchIndex=this._matches.findIndex(match=>match===this.currentMatch);if(stayIfOnMatch)return[this.currentMatch,currentMatchIndex];const nextMatchIndex=currentMatchIndex+1,length=this._matches.length;if(!loop&&nextMatchIndex>=length)return null;const modded=nextMatchIndex%length;return[this._matches[modded],modded]}const last=this._workbookSelections.getCurrentLastSelection();if(ignoreSelection||!last)return[this._matches[0],0];if(this._query.findScope!==findReplace.FindScope.UNIT)return this._findNextMatchByRange(this._matches,last.range,stayIfOnMatch);const currentSheetId=(_a5=this._workbook.getActiveSheet())==null?void 0:_a5.getSheetId();if(!currentSheetId)return null;const worksheetThatHasMatch=this._findNextWorksheetThatHasAMatch(currentSheetId,loop);return worksheetThatHasMatch?this._findNextMatchByRange(this._matchesByWorksheet.get(worksheetThatHasMatch),last.range):null}_findPreviousWorksheetThatHasAMatch(currentWorksheet,loop=!1){const rawWorksheetsInOrder=this._workbook.getSheetOrders(),currentSheetIndex=rawWorksheetsInOrder.findIndex(sheet=>sheet===currentWorksheet),first=(loop?core.rotate(rawWorksheetsInOrder,currentSheetIndex+1):rawWorksheetsInOrder.slice(0,currentSheetIndex+1)).findLast(worksheet=>this._matchesByWorksheet.has(worksheet));return first!=null?first:null}_findNextWorksheetThatHasAMatch(currentWorksheet,loop=!1){const rawWorksheetsInOrder=this._workbook.getSheetOrders(),currentSheetIndex=rawWorksheetsInOrder.findIndex(sheet=>sheet===currentWorksheet),first=(loop?core.rotate(rawWorksheetsInOrder,currentSheetIndex):rawWorksheetsInOrder.slice(currentSheetIndex)).find(worksheet=>this._matchesByWorksheet.has(worksheet));return first!=null?first:null}_findNextMatchByRange(matches,range,stayIfOnMatch=!1){const findByRow=this._query.findDirection===findReplace.FindDirection.ROW;let index=matches.findIndex(match2=>{const matchRange=match2.range.range;if(!(findByRow?isBehindPositionWithRowPriority(range,matchRange):isBehindPositionWithColumnPriority(range,matchRange)))return!1;const isSame=isSamePosition(range,matchRange);return stayIfOnMatch?isSame:!isSame});index===-1&&(index=matches.length-1);const match=matches[index];return[match,this._matches.findIndex(m=>m===match)]}_findPreviousMatchByRange(matches,range,stayIfOnMatch=!1){const findByRow=this._query.findDirection===findReplace.FindDirection.ROW;let index=this._matches.findLastIndex(match2=>{const matchRange=match2.range.range;if(!(findByRow?isBeforePositionWithRowPriority(range,matchRange):isBeforePositionWithColumnPriority(range,matchRange)))return!1;const isSame=isSamePosition(range,matchRange);return stayIfOnMatch?isSame:!isSame});index===-1&&(index=0);const match=matches[index];return[match,this._matches.findIndex(m=>m===match)]}async replace(replaceString){if(this._matchesCount===0||!this.currentMatch||!this._query||!this.currentMatch.replaceable)return!1;const range=this.currentMatch.range,targetWorksheet=this._workbook.getSheetBySheetId(this.currentMatch.range.subUnitId),newContent=this._getReplacedCellData(this.currentMatch,targetWorksheet,this._query.findBy===findReplace.FindBy.FORMULA,this._query.findString,replaceString,this._query.caseSensitive?"g":"ig"),params={unitId:this.currentMatch.unitId,subUnitId:range.subUnitId,value:{[range.range.startRow]:{[range.range.startColumn]:newContent}}};return this._commandService.executeCommand(sheets.SetRangeValuesCommand.id,params)}async replaceAll(replaceString){if(this._matchesCount===0||!this._query)return{success:0,failure:0};const unitId=this._workbook.getUnitId(),{findString,caseSensitive,findBy}=this._query,shouldReplaceFormula=findBy===findReplace.FindBy.FORMULA,replaceFlag=caseSensitive?"g":"ig",replacements=[];return core.groupBy(this._matches.filter(m=>m.replaceable),match=>match.range.subUnitId).forEach((matches,subUnitId)=>{const matrix=new core.ObjectMatrix,worksheet=this._workbook.getSheetBySheetId(subUnitId);matches.forEach(match=>{const{startColumn,startRow}=match.range.range,newCellData=this._getReplacedCellData(match,worksheet,shouldReplaceFormula,findString,replaceString,replaceFlag);newCellData&&matrix.setValue(startRow,startColumn,newCellData)}),replacements.push({count:matches.length,subUnitId,value:matrix.getMatrix()})}),replacements?this._commandService.executeCommand(SheetReplaceCommand.id,{unitId,replacements}):{success:0,failure:0}}_getReplacedCellData(match,worksheet,shouldReplaceFormula,findString,replaceString,replaceFlag){var _a5;const range=match.range.range,{startRow,startColumn}=range,currentContent=worksheet.getCellRaw(startRow,startColumn);if(match.isFormula)return shouldReplaceFormula?{f:currentContent.f.replace(new RegExp(escapeRegExp(findString),replaceFlag),replaceString),v:null}:null;if(!!((_a5=currentContent.p)!=null&&_a5.body)){const clonedRichText=core.Tools.deepClone(currentContent.p);return core.replaceInDocumentBody(clonedRichText.body,findString,replaceString,this._query.caseSensitive),{p:clonedRichText}}return{v:currentContent.v.toString().replace(new RegExp(escapeRegExp(findString),replaceFlag),replaceString)}}},__name(_a2,"SheetFindModel"),_a2);SheetFindModel=__decorateClass$1([__decorateParam$1(2,core.IUniverInstanceService),__decorateParam$1(3,engineRender.IRenderManagerService),__decorateParam$1(4,core.ICommandService),__decorateParam$1(5,core.IContextService),__decorateParam$1(6,core.Inject(core.ThemeService)),__decorateParam$1(7,core.Inject(sheets.SheetsSelectionsService))],SheetFindModel);function escapeRegExp(text){return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}__name(escapeRegExp,"escapeRegExp");var _a3;let SheetsFindReplaceProvider=(_a3=class extends core.Disposable{constructor(_univerInstanceService,_renderManagerService,_injector){super();__publicField(this,"_findModelsByUnitId",new Map);this._univerInstanceService=_univerInstanceService,this._renderManagerService=_renderManagerService,this._injector=_injector}async find(query){this._terminate();const allWorkbooks=this._univerInstanceService.getAllUnitsForType(core.UniverInstanceType.UNIVER_SHEET),parsedQuery=this._preprocessQuery(query);return allWorkbooks.map(workbook=>{const skeletonManagerService=this._renderManagerService.getRenderById(workbook.getUnitId()).with(sheetsUi.SheetSkeletonManagerService),sheetFind=this._injector.createInstance(SheetFindModel,workbook,skeletonManagerService);return this._findModelsByUnitId.set(workbook.getUnitId(),sheetFind),sheetFind.start(parsedQuery),sheetFind})}terminate(){this._terminate()}_terminate(){this._findModelsByUnitId.forEach(model=>model.dispose()),this._findModelsByUnitId.clear()}_preprocessQuery(query){let findString=query.caseSensitive?query.findString:query.findString.toLowerCase();return findString=findString.trim(),{...query,findString}}},__name(_a3,"SheetsFindReplaceProvider"),_a3);SheetsFindReplaceProvider=__decorateClass$1([__decorateParam$1(0,core.IUniverInstanceService),__decorateParam$1(1,engineRender.IRenderManagerService),__decorateParam$1(2,core.Inject(core.Injector))],SheetsFindReplaceProvider);const VALUE_PASSING_OBJECT={hit:!1,replaceable:!1,isFormula:!1,rawData:null};function hitCell(worksheet,row,col,query,cellData){const{findBy}=query,findByFormula=findBy===findReplace.FindBy.FORMULA,rawData=worksheet.getCellRaw(row,col);return VALUE_PASSING_OBJECT.rawData=rawData,!(rawData!=null&&rawData.f)?(VALUE_PASSING_OBJECT.isFormula=!1,matchCellData(cellData,query)?rawData?(VALUE_PASSING_OBJECT.hit=!0,VALUE_PASSING_OBJECT.replaceable=!0):(VALUE_PASSING_OBJECT.hit=!0,VALUE_PASSING_OBJECT.replaceable=!1):(VALUE_PASSING_OBJECT.hit=!1,VALUE_PASSING_OBJECT.replaceable=!1),VALUE_PASSING_OBJECT):(VALUE_PASSING_OBJECT.isFormula=!0,findByFormula?matchCellData({v:rawData.f},query)?(VALUE_PASSING_OBJECT.hit=!0,VALUE_PASSING_OBJECT.replaceable=!0,VALUE_PASSING_OBJECT):(VALUE_PASSING_OBJECT.hit=!1,VALUE_PASSING_OBJECT.replaceable=!1,VALUE_PASSING_OBJECT):(VALUE_PASSING_OBJECT.replaceable=!1,matchCellData(cellData,query)?VALUE_PASSING_OBJECT.hit=!0:VALUE_PASSING_OBJECT.hit=!1,VALUE_PASSING_OBJECT))}__name(hitCell,"hitCell");function matchCellData(cellData,query){let value=extractPureValue(cellData);return value?query.matchesTheWholeCell?(value=trimLeadingTrailingWhitespace(value),query.caseSensitive?value===query.findString:value.toLowerCase()===query.findString):query.caseSensitive?value.indexOf(query.findString)>-1:value.toLowerCase().indexOf(query.findString)>-1:!1}__name(matchCellData,"matchCellData");function extractPureValue(cell){var _a5,_b,_c;const rawValue=(_c=(_b=(_a5=cell==null?void 0:cell.p)==null?void 0:_a5.body)==null?void 0:_b.dataStream)!=null?_c:cell==null?void 0:cell.v;return typeof rawValue=="number"?`${rawValue}`:typeof rawValue=="boolean"?rawValue?"1":"0":rawValue}__name(extractPureValue,"extractPureValue");function trimLeadingTrailingWhitespace(value){return value.replace(/^ +/g,"").replace(/ +$/g,"")}__name(trimLeadingTrailingWhitespace,"trimLeadingTrailingWhitespace");var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__defNormalProp2=__name((obj,key,value)=>key in obj?__defProp2(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value,"__defNormalProp"),__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam"),__publicField2=__name((obj,key,value)=>__defNormalProp2(obj,typeof key!="symbol"?key+"":key,value),"__publicField");const NAME="SHEET_FIND_REPLACE_PLUGIN";var _a4;exports.UniverSheetsFindReplacePlugin=(_a4=class extends core.Plugin{constructor(_config=defaultPluginConfig,_injector,_configService){super(),this._config=_config,this._injector=_injector,this._configService=_configService;const{...rest}=core.merge({},defaultPluginConfig,this._config);this._configService.setConfig(SHEETS_FIND_REPLACE_PLUGIN_CONFIG_KEY,rest)}onStarting(){[[exports.SheetsFindReplaceController]].forEach(d=>this._injector.add(d))}onSteady(){this._injector.get(exports.SheetsFindReplaceController)}},__name(_a4,"UniverSheetsFindReplacePlugin"),_a4);__publicField2(exports.UniverSheetsFindReplacePlugin,"pluginName",NAME);__publicField2(exports.UniverSheetsFindReplacePlugin,"type",core.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsFindReplacePlugin=__decorateClass([core.DependentOn(sheets.UniverSheetsPlugin,sheets.UniverSheetsPlugin,findReplace.UniverFindReplacePlugin),__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.IConfigService)],exports.UniverSheetsFindReplacePlugin);exports.SheetReplaceCommand=SheetReplaceCommand;
@@ -1 +1 @@
1
- "use strict";const e={"sheet-find-replace":{replace:{"partial-failure":"Failed to replace some cells",failure:"Failed to replace all cells"}}};module.exports=e;
1
+ "use strict";const locale={"sheet-find-replace":{replace:{"partial-failure":"Failed to replace some cells",failure:"Failed to replace all cells"}}};module.exports=locale;
@@ -1 +1 @@
1
- "use strict";const e={"sheet-find-replace":{replace:{"partial-failure":"جایگزینی برخی سلول‌ها ناموفق بود",failure:"جایگزینی همه سلول‌ها ناموفق بود"}}};module.exports=e;
1
+ "use strict";const locale={"sheet-find-replace":{replace:{"partial-failure":"جایگزینی برخی سلول‌ها ناموفق بود",failure:"جایگزینی همه سلول‌ها ناموفق بود"}}};module.exports=locale;
@@ -1 +1 @@
1
- "use strict";const e={"sheet-find-replace":{replace:{"partial-failure":"Échec du remplacement de certaines cellules",failure:"Échec du remplacement de toutes les cellules"}}};module.exports=e;
1
+ "use strict";const locale={"sheet-find-replace":{replace:{"partial-failure":"Échec du remplacement de certaines cellules",failure:"Échec du remplacement de toutes les cellules"}}};module.exports=locale;
@@ -1 +1 @@
1
- "use strict";const e={"sheet-find-replace":{replace:{"partial-failure":"Не удалось заменить некоторые ячейки",failure:"Не удалось заменить все ячейки"}}};module.exports=e;
1
+ "use strict";const locale={"sheet-find-replace":{replace:{"partial-failure":"Не удалось заменить некоторые ячейки",failure:"Не удалось заменить все ячейки"}}};module.exports=locale;
@@ -1 +1 @@
1
- "use strict";const t={"sheet-find-replace":{replace:{"partial-failure":"Thay thế một phần ô thất bại",failure:"Thay thế thất bại"}}};module.exports=t;
1
+ "use strict";const locale={"sheet-find-replace":{replace:{"partial-failure":"Thay thế một phần ô thất bại",failure:"Thay thế thất bại"}}};module.exports=locale;
@@ -1 +1 @@
1
- "use strict";const e={"sheet-find-replace":{replace:{"partial-failure":"部分单元格替换失败",failure:"替换失败"}}};module.exports=e;
1
+ "use strict";const zhCN={"sheet-find-replace":{replace:{"partial-failure":"部分单元格替换失败",failure:"替换失败"}}};module.exports=zhCN;
@@ -1 +1 @@
1
- "use strict";const e={"sheet-find-replace":{replace:{"partial-failure":"部分單元格替換失敗",failure:"替換失敗"}}};module.exports=e;
1
+ "use strict";const locale={"sheet-find-replace":{replace:{"partial-failure":"部分單元格替換失敗",failure:"替換失敗"}}};module.exports=locale;
package/lib/es/facade.js CHANGED
@@ -1,100 +1,103 @@
1
- var u = Object.defineProperty;
2
- var _ = (i, e, t) => e in i ? u(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
- var c = (i, e, t) => _(i, typeof e != "symbol" ? e + "" : e, t);
4
- import { Inject as p, Injector as m, IUniverInstanceService as f, Disposable as v, FUniver as d } from "@univerjs/core";
5
- import { IFindReplaceService as b, FindReplaceModel as g, createInitFindReplaceState as S, FindReplaceState as F, FindBy as h } from "@univerjs/find-replace";
6
- import { FRange as y } from "@univerjs/sheets/facade";
7
- var R = Object.defineProperty, w = Object.getOwnPropertyDescriptor, C = (i, e, t, s) => {
8
- for (var n = s > 1 ? void 0 : s ? w(e, t) : e, r = i.length - 1, a; r >= 0; r--)
9
- (a = i[r]) && (n = (s ? a(e, t, n) : a(n)) || n);
10
- return s && n && R(e, t, n), n;
11
- }, o = (i, e) => (t, s) => e(t, s, i);
12
- let l = class extends v {
13
- constructor(e, t, s, n) {
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
3
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
4
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
5
+ import { Inject, Injector, IUniverInstanceService, Disposable, FUniver } from "@univerjs/core";
6
+ import { IFindReplaceService, FindReplaceModel, createInitFindReplaceState, FindReplaceState, FindBy } from "@univerjs/find-replace";
7
+ import { FRange } from "@univerjs/sheets/facade";
8
+ var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
9
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
10
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
11
+ return kind && result && __defProp2(target, key, result), result;
12
+ }, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), _a;
13
+ let FTextFinder = (_a = class extends Disposable {
14
+ constructor(_initialState, _injector, _univerInstanceService, _findReplaceService) {
14
15
  super();
15
- c(this, "_state", new F());
16
- c(this, "_model");
17
- c(this, "_complete");
18
- this._injector = t, this._univerInstanceService = s, this._findReplaceService = n;
19
- const r = this._findReplaceService.getProviders();
20
- this._model = this._injector.createInstance(g, this._state, r);
21
- const a = {
22
- ...S(),
23
- ...e
16
+ __publicField(this, "_state", new FindReplaceState());
17
+ __publicField(this, "_model");
18
+ __publicField(this, "_complete");
19
+ this._injector = _injector, this._univerInstanceService = _univerInstanceService, this._findReplaceService = _findReplaceService;
20
+ const providers = this._findReplaceService.getProviders();
21
+ this._model = this._injector.createInstance(FindReplaceModel, this._state, providers);
22
+ const newState = {
23
+ ...createInitFindReplaceState(),
24
+ ..._initialState
24
25
  };
25
- this._state.changeState(a);
26
+ this._state.changeState(newState);
26
27
  }
27
28
  findAll() {
28
- return !this._state.findCompleted || !this._complete ? [] : this._complete.results.map((e) => this._findMatchToFRange(e));
29
+ return !this._state.findCompleted || !this._complete ? [] : this._complete.results.map((result) => this._findMatchToFRange(result));
29
30
  }
30
31
  findNext() {
31
- var t;
32
+ var _a2;
32
33
  if (!this._state.findCompleted || !this._complete)
33
34
  return null;
34
- const e = (t = this._model) == null ? void 0 : t.moveToNextMatch();
35
- return e ? this._findMatchToFRange(e) : null;
35
+ const match = (_a2 = this._model) == null ? void 0 : _a2.moveToNextMatch();
36
+ return match ? this._findMatchToFRange(match) : null;
36
37
  }
37
38
  findPrevious() {
38
- var t;
39
- const e = (t = this._model) == null ? void 0 : t.moveToPreviousMatch();
40
- return e ? this._findMatchToFRange(e) : null;
39
+ var _a2;
40
+ const match = (_a2 = this._model) == null ? void 0 : _a2.moveToPreviousMatch();
41
+ return match ? this._findMatchToFRange(match) : null;
41
42
  }
42
43
  getCurrentMatch() {
43
- var t;
44
+ var _a2;
44
45
  if (!this._state.findCompleted || !this._complete)
45
46
  throw new Error("Find operation is not completed.");
46
- const e = (t = this._model) == null ? void 0 : t.currentMatch$.value;
47
- return e ? this._findMatchToFRange(e) : null;
47
+ const match = (_a2 = this._model) == null ? void 0 : _a2.currentMatch$.value;
48
+ return match ? this._findMatchToFRange(match) : null;
48
49
  }
49
- async matchCaseAsync(e) {
50
- return this._state.changeState({ caseSensitive: e }), new Promise((t) => {
51
- const s = this._state.stateUpdates$.subscribe((n) => {
52
- n.findCompleted === !0 && (s.unsubscribe(), t(this));
50
+ async matchCaseAsync(matchCase) {
51
+ return this._state.changeState({ caseSensitive: matchCase }), new Promise((resolve) => {
52
+ const subscribe = this._state.stateUpdates$.subscribe((state) => {
53
+ state.findCompleted === !0 && (subscribe.unsubscribe(), resolve(this));
53
54
  });
54
55
  });
55
56
  }
56
- async matchEntireCellAsync(e) {
57
- return this._state.changeState({ matchesTheWholeCell: e }), new Promise((t) => {
58
- const s = this._state.stateUpdates$.subscribe((n) => {
59
- n.findCompleted === !0 && (s.unsubscribe(), t(this));
57
+ async matchEntireCellAsync(matchEntireCell) {
58
+ return this._state.changeState({ matchesTheWholeCell: matchEntireCell }), new Promise((resolve) => {
59
+ const subscribe = this._state.stateUpdates$.subscribe((state) => {
60
+ state.findCompleted === !0 && (subscribe.unsubscribe(), resolve(this));
60
61
  });
61
62
  });
62
63
  }
63
- async matchFormulaTextAsync(e) {
64
- return this._state.changeState({ findBy: e ? h.FORMULA : h.VALUE }), new Promise((t) => {
65
- const s = this._state.stateUpdates$.subscribe((n) => {
66
- n.findCompleted === !0 && (s.unsubscribe(), t(this));
64
+ async matchFormulaTextAsync(matchFormulaText) {
65
+ return this._state.changeState({ findBy: matchFormulaText ? FindBy.FORMULA : FindBy.VALUE }), new Promise((resolve) => {
66
+ const subscribe = this._state.stateUpdates$.subscribe((state) => {
67
+ state.findCompleted === !0 && (subscribe.unsubscribe(), resolve(this));
67
68
  });
68
69
  });
69
70
  }
70
- async replaceAllWithAsync(e) {
71
- var s, n, r;
72
- await this._state.changeState({ replaceRevealed: !0, replaceString: e });
73
- const t = (r = (n = await ((s = this._model) == null ? void 0 : s.replaceAll())) == null ? void 0 : n.success) != null ? r : 0;
74
- return this._state.changeState({ replaceRevealed: !1 }), t;
71
+ async replaceAllWithAsync(replaceText) {
72
+ var _a2, _b, _c;
73
+ await this._state.changeState({ replaceRevealed: !0, replaceString: replaceText });
74
+ const res = (_c = (_b = await ((_a2 = this._model) == null ? void 0 : _a2.replaceAll())) == null ? void 0 : _b.success) != null ? _c : 0;
75
+ return this._state.changeState({ replaceRevealed: !1 }), res;
75
76
  }
76
- async replaceWithAsync(e) {
77
- var t;
78
- return await this._state.changeState({ replaceRevealed: !0, replaceString: e }), await ((t = this._model) == null ? void 0 : t.replace()), this._state.changeState({ replaceRevealed: !1 }), !0;
77
+ async replaceWithAsync(replaceText) {
78
+ var _a2;
79
+ return await this._state.changeState({ replaceRevealed: !0, replaceString: replaceText }), await ((_a2 = this._model) == null ? void 0 : _a2.replace()), this._state.changeState({ replaceRevealed: !1 }), !0;
79
80
  }
80
81
  async ensureCompleteAsync() {
81
- var e;
82
- return (!this._state.findCompleted || !this._complete) && (this._complete = await ((e = this._model) == null ? void 0 : e.start())), this._complete;
82
+ var _a2;
83
+ return (!this._state.findCompleted || !this._complete) && (this._complete = await ((_a2 = this._model) == null ? void 0 : _a2.start())), this._complete;
83
84
  }
84
- _findMatchToFRange(e) {
85
- const { unitId: t } = e, { subUnitId: s, range: n } = e.range, r = this._univerInstanceService.getUnit(t), a = r.getSheetBySheetId(s);
86
- return this._injector.createInstance(y, r, a, n);
85
+ _findMatchToFRange(match) {
86
+ const { unitId } = match, { subUnitId, range } = match.range, workbook = this._univerInstanceService.getUnit(unitId), worksheet = workbook.getSheetBySheetId(subUnitId);
87
+ return this._injector.createInstance(FRange, workbook, worksheet, range);
87
88
  }
88
- };
89
- l = C([
90
- o(1, p(m)),
91
- o(2, f),
92
- o(3, b)
93
- ], l);
94
- class I extends d {
95
- async createTextFinderAsync(e) {
96
- const t = { findString: e }, s = this._injector.createInstance(l, t);
97
- return await s.ensureCompleteAsync(), s;
89
+ }, __name(_a, "FTextFinder"), _a);
90
+ FTextFinder = __decorateClass([
91
+ __decorateParam(1, Inject(Injector)),
92
+ __decorateParam(2, IUniverInstanceService),
93
+ __decorateParam(3, IFindReplaceService)
94
+ ], FTextFinder);
95
+ const _FUniverFindReplaceMixin = class _FUniverFindReplaceMixin extends FUniver {
96
+ async createTextFinderAsync(text) {
97
+ const state = { findString: text }, textFinder = this._injector.createInstance(FTextFinder, state);
98
+ return await textFinder.ensureCompleteAsync(), textFinder;
98
99
  }
99
- }
100
- d.extend(I);
100
+ };
101
+ __name(_FUniverFindReplaceMixin, "FUniverFindReplaceMixin");
102
+ let FUniverFindReplaceMixin = _FUniverFindReplaceMixin;
103
+ FUniver.extend(FUniverFindReplaceMixin);