@univerjs/sheets-find-replace 0.6.10 → 0.7.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var z=Object.defineProperty;var J=(c,e,t)=>e in c?z(c,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):c[e]=t;var f=(c,e,t)=>J(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"),w=require("@univerjs/sheets-ui"),I=require("rxjs"),Z="sheets-find-replace.config",O={},P={id:"sheet.command.replace",type:l.CommandType.COMMAND,handler:async(c,e)=>{const t=c.get(l.IUndoRedoService),n=c.get(l.ICommandService),{unitId:i,replacements:r}=e,s=t.__tempBatchingUndoRedo(i),o=await Promise.all(r.map(h=>n.executeCommand(C.SetRangeValuesCommand.id,{unitId:i,subUnitId:h.subUnitId,value:h.value})));return s.dispose(),ee(o,r)}};function ee(c,e){let t=0,n=0;return c.forEach((i,r)=>{const s=e[r].count;i?t+=s:n+=s}),{success:t,failure:n}}class te extends M.Shape{constructor(t,n){super(t,n);f(this,"_activated",!1);f(this,"_inHiddenRange",!1);f(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 ne(c,e){return c.startRow>e.startRow||c.startRow===e.startRow&&c.startColumn>=e.startColumn}function ie(c,e){return c.startColumn>e.startColumn||c.startColumn===e.startColumn&&c.startRow>=e.startRow}function se(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 re=Object.getOwnPropertyDescriptor,B=(c,e,t,n)=>{for(var i=n>1?void 0:n?re(e,t):e,r=c.length-1,s;r>=0;r--)(s=c[r])&&(i=s(i)||i);return i},v=(c,e)=>(t,n)=>e(t,n,c);exports.SheetsFindReplaceController=class extends l.Disposable{constructor(t,n,i,r,s){super();f(this,"_provider");this._injector=t,this._findReplaceController=n,this._contextService=i,this._findReplaceService=r,this._commandService=s,this._init(),this._initCommands()}dispose(){super.dispose(),this._findReplaceController.closePanel(),this._provider.dispose()}_init(){const t=this._injector.createInstance(U);this._provider=t,this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(t)),this.disposeWithMe(this._contextService.subscribeContextValue$(l.EDITOR_ACTIVATED).pipe(I.filter(n=>!!n)).subscribe(()=>this._findReplaceController.closePanel()))}_initCommands(){[P].forEach(t=>this.disposeWithMe(this._commandService.registerCommand(t)))}};exports.SheetsFindReplaceController=B([v(0,l.Inject(l.Injector)),v(1,l.Inject(S.FindReplaceController)),v(2,l.IContextService),v(3,S.IFindReplaceService),v(4,l.ICommandService)],exports.SheetsFindReplaceController);const oe="sheets-find-replace-provider",ce=1e4;let F=class extends S.FindModel{constructor(e,t,n,i,r,s,o,h){super();f(this,"_matchesUpdate$",new I.Subject);f(this,"matchesUpdate$",this._matchesUpdate$.asObservable());f(this,"_activelyChangingMatch$",new I.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);f(this,"_workbookSelections");this._workbook=e,this._sheetSkeletonManagerService=t,this._univerInstanceService=n,this._renderManagerService=i,this._commandService=r,this._contextService=s,this._themeService=o,this._workbookSelections=h.getWorkbookSelections(this.unitId)}get _matchesCount(){return this._matches.length}get unitId(){return this._workbook.getUnitId()}get matchesCount(){return this._matchesCount}get matchesPosition(){return this._matchesPosition}get currentMatch(){return this._matchesPosition>0?this._matches[this._matchesPosition-1]:null}dispose(){super.dispose(),this._disposeHighlights(),this._toggleDisplayRawFormula(!1)}getMatches(){return this._matches}start(e){switch(this._query=e,e.findBy===S.FindBy.FORMULA?this._toggleDisplayRawFormula(!0):this._toggleDisplayRawFormula(!1),e.findScope){case S.FindScope.UNIT:this.findInWorkbook(e);break;case S.FindScope.SUBUNIT:default:this.findInActiveWorksheet(e);break}}focusSelection(){const e=this.currentMatch;e&&this._commandService.executeCommand(C.SelectRangeCommand.id,{unitId:e.unitId,subUnit:e.range.subUnitId,range:e.range.range})}_toggleDisplayRawFormula(e){this._contextService.setContextValue(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(I.filter(([s,o])=>s.id===C.SetWorksheetActiveOperation.id&&!(o!=null&&o.fromFindReplace))).subscribe(()=>{const s=this._workbook.getActiveSheet();if(!s)return;const o=s.getSheetId();this._matchesByWorksheet.has(o)&&this._findNextMatchOnActiveSheetChange(s)})),this.disposeWithMe(l.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(I.filter(([s])=>s.type===l.CommandType.MUTATION&&s.params.unitId===this._workbook.getUnitId()),I.throttleTime(600,void 0,{leading:!1,trailing:!0})).subscribe(()=>r())),r(),n}_findNextMatchOnActiveSheetChange(e){let t,n,i=0;const r=this._matchesByWorksheet.get(e.getSheetId()),s=this._workbookSelections.getCurrentSelections();s!=null&&s.length?([t,i]=this._findNextMatchByRange(r,s[0].range),n=r.findIndex(o=>o===t)):(t=r[0],n=0,i=this._matches.findIndex(o=>o===t)),this._matchesPosition=i+1,this._activelyChangingMatch$.next(t),this._activeHighlightIndex=n,this._updateFindHighlight(),this._updateCurrentHighlightShape(n)}findInActiveWorksheet(e){const t=this._workbook.getUnitId(),n=()=>{var u;const h=this._workbook.getActiveSheet();if(!h)return!1;const d=this._workbookSelections.getCurrentSelections();return(u=d==null?void 0:d.some(g=>!se(g,h)))!=null?u:!1};let i,r=!0,s=!1;const o=()=>{const h=this._workbook.getActiveSheet();if(!h)return{results:[]};const d=this.currentMatch;s=n();const a=this._workbookSelections.getCurrentSelections(),u=s?this._findInSelections(h,a,e,t):this._findInWorksheet(h,e,t);return this._matches=u.results,this._matchesPosition=this._tryRestoreLastMatchesPosition(d,this._matches),r?(i=u,r=!1):this._matchesUpdate$.next(this._matches),this._updateFindHighlight(),u};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>this._updateFindHighlight())),this.disposeWithMe(I.merge(l.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(I.filter(([h])=>{if(h.type===l.CommandType.MUTATION&&h.params.unitId===this._workbook.getUnitId())return!0;if(h.id===C.SetSelectionsOperation.id&&h.params.unitId===t){const d=n();return d===!1&&s===!1?!1:(s=d,!0)}return!1})),this._workbook.activeSheet$.pipe(I.skip(1))).pipe(I.debounceTime(200)).subscribe(()=>o())),o(),i}_findInRange(e,t,n,i,r){const s=[],o=e.getSheetId(),h=(t.findDirection===S.FindDirection.COLUMN?e.iterateByColumn:e.iterateByRow).bind(e)(n);for(const d of h){const{row:a,col:u,colSpan:g,rowSpan:m,value:p}=d;if(r!=null&&r(a,u)||!p||e.getRowFiltered(a))continue;const{hit:R,replaceable:k,isFormula:b}=he(e,a,u,t,p);if(R){const y={provider:oe,unitId:i,replaceable:k,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:k,endRow:b}=g.range.range,y=w.getCoordByCell(R,p,i,e),V=w.getCoordByCell(b,k,i,e),{startX:W,startY:H}=y,{endX:G,endY:Y}=V,T=!h.getRowRawVisible(R),E=!h.getColVisible(p),q=T||E,K=E?2:G-W,Q=T?2:Y-H,X={left:W,top:H,color:o,width:K,height:Q,evented:!1,inHiddenRange:q,zIndex:ce};return new te(`find-highlight-${m}`,X)});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 w.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(w.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?ne(t,h):ie(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:k}=p.range.range,b=this._getReplacedCellData(p,m,s,n,e,o);b&&g.setValue(k,R,b)}),h.push({count:a.length,subUnitId:u,value:g.getMatrix()})}),h?this._commandService.executeCommand(P.id,{unitId:t,replacements:h}):{success:0,failure:0}}_getReplacedCellData(e,t,n,i,r,s){var m;const o=e.range.range,{startRow:h,startColumn:d}=o,a=t.getCellRaw(h,d);if(e.isFormula)return n?{f:a.f.replace(new RegExp($(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([v(2,l.IUniverInstanceService),v(3,M.IRenderManagerService),v(4,l.ICommandService),v(5,l.IContextService),v(6,l.Inject(l.ThemeService)),v(7,l.Inject(C.SheetsSelectionsService))],F);function $(c){return c.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}let U=class extends l.Disposable{constructor(e,t,n){super();f(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(w.SheetSkeletonManagerService),o=this._injector.createInstance(F,r,s);return this._findModelsByUnitId.set(r.getUnitId(),o),o.start(n),o})}terminate(){this._terminate()}_terminate(){this._findModelsByUnitId.forEach(e=>e.dispose()),this._findModelsByUnitId.clear()}_preprocessQuery(e){let t=e.caseSensitive?e.findString:e.findString.toLowerCase();return t=t.trim(),{...e,findString:t}}};U=B([v(0,l.IUniverInstanceService),v(1,M.IRenderManagerService),v(2,l.Inject(l.Injector))],U);const _={hit:!1,replaceable:!1,isFormula:!1,rawData:null};function he(c,e,t,n,i){const{findBy:r}=n,s=r===S.FindBy.FORMULA,o=c.getCellRaw(e,t);return _.rawData=o,!(o!=null&&o.f)?(_.isFormula=!1,x(i,n)?o?(_.hit=!0,_.replaceable=!0):(_.hit=!0,_.replaceable=!1):(_.hit=!1,_.replaceable=!1),_):(_.isFormula=!0,s?x({v:o.f},n)?(_.hit=!0,_.replaceable=!0,_):(_.hit=!1,_.replaceable=!1,_):(_.replaceable=!1,x(i,n)?_.hit=!0:_.hit=!1,_))}function x(c,e){let t=ae(c);return t?e.matchesTheWholeCell?(t=le(t),e.caseSensitive?t===e.findString:t.toLowerCase()===e.findString):e.caseSensitive?t.indexOf(e.findString)>-1:t.toLowerCase().indexOf(e.findString)>-1:!1}function ae(c){var t,n,i;const e=(i=(n=(t=c==null?void 0:c.p)==null?void 0:t.body)==null?void 0:n.dataStream)!=null?i:c==null?void 0:c.v;return typeof e=="number"?`${e}`:typeof e=="boolean"?e?"1":"0":e}function le(c){return c.replace(/^ +/g,"").replace(/ +$/g,"")}var de=Object.defineProperty,ue=Object.getOwnPropertyDescriptor,ge=(c,e,t)=>e in c?de(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?ue(e,t):e,r=c.length-1,s;r>=0;r--)(s=c[r])&&(i=s(i)||i);return i},j=(c,e)=>(t,n)=>e(t,n,c),L=(c,e,t)=>ge(c,typeof e!="symbol"?e+"":e,t);const fe="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(Z,i)}onStarting(){[[exports.SheetsFindReplaceController]].forEach(e=>this._injector.add(e))}onSteady(){this._injector.get(exports.SheetsFindReplaceController)}};L(exports.UniverSheetsFindReplacePlugin,"pluginName",fe);L(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=P;
1
+ "use strict";var z=Object.defineProperty;var J=(c,e,t)=>e in c?z(c,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):c[e]=t;var f=(c,e,t)=>J(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"),w=require("@univerjs/sheets-ui"),I=require("rxjs"),Z="sheets-find-replace.config",O={},P={id:"sheet.command.replace",type:l.CommandType.COMMAND,handler:async(c,e)=>{const t=c.get(l.IUndoRedoService),n=c.get(l.ICommandService),{unitId:i,replacements:r}=e,s=t.__tempBatchingUndoRedo(i),o=await Promise.all(r.map(h=>n.executeCommand(C.SetRangeValuesCommand.id,{unitId:i,subUnitId:h.subUnitId,value:h.value})));return s.dispose(),ee(o,r)}};function ee(c,e){let t=0,n=0;return c.forEach((i,r)=>{const s=e[r].count;i?t+=s:n+=s}),{success:t,failure:n}}class te extends M.Shape{constructor(t,n){super(t,n);f(this,"_activated",!1);f(this,"_inHiddenRange",!1);f(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 ne(c,e){return c.startRow>e.startRow||c.startRow===e.startRow&&c.startColumn>=e.startColumn}function ie(c,e){return c.startColumn>e.startColumn||c.startColumn===e.startColumn&&c.startRow>=e.startRow}function se(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 re=Object.getOwnPropertyDescriptor,B=(c,e,t,n)=>{for(var i=n>1?void 0:n?re(e,t):e,r=c.length-1,s;r>=0;r--)(s=c[r])&&(i=s(i)||i);return i},v=(c,e)=>(t,n)=>e(t,n,c);exports.SheetsFindReplaceController=class extends l.Disposable{constructor(t,n,i,r,s){super();f(this,"_provider");this._injector=t,this._findReplaceController=n,this._contextService=i,this._findReplaceService=r,this._commandService=s,this._init(),this._initCommands()}dispose(){super.dispose(),this._findReplaceController.closePanel(),this._provider.dispose()}_init(){const t=this._injector.createInstance(U);this._provider=t,this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(t)),this.disposeWithMe(this._contextService.subscribeContextValue$(l.EDITOR_ACTIVATED).pipe(I.filter(n=>!!n)).subscribe(()=>this._findReplaceController.closePanel()))}_initCommands(){[P].forEach(t=>this.disposeWithMe(this._commandService.registerCommand(t)))}};exports.SheetsFindReplaceController=B([v(0,l.Inject(l.Injector)),v(1,l.Inject(S.FindReplaceController)),v(2,l.IContextService),v(3,S.IFindReplaceService),v(4,l.ICommandService)],exports.SheetsFindReplaceController);const oe="sheets-find-replace-provider",ce=1e4;let F=class extends S.FindModel{constructor(e,t,n,i,r,s,o,h){super();f(this,"_matchesUpdate$",new I.Subject);f(this,"matchesUpdate$",this._matchesUpdate$.asObservable());f(this,"_activelyChangingMatch$",new I.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);f(this,"_workbookSelections");this._workbook=e,this._sheetSkeletonManagerService=t,this._univerInstanceService=n,this._renderManagerService=i,this._commandService=r,this._contextService=s,this._themeService=o,this._workbookSelections=h.getWorkbookSelections(this.unitId)}get _matchesCount(){return this._matches.length}get unitId(){return this._workbook.getUnitId()}get matchesCount(){return this._matchesCount}get matchesPosition(){return this._matchesPosition}get currentMatch(){return this._matchesPosition>0?this._matches[this._matchesPosition-1]:null}dispose(){super.dispose(),this._disposeHighlights(),this._toggleDisplayRawFormula(!1)}getMatches(){return this._matches}start(e){switch(this._query=e,e.findBy===S.FindBy.FORMULA?this._toggleDisplayRawFormula(!0):this._toggleDisplayRawFormula(!1),e.findScope){case S.FindScope.UNIT:this.findInWorkbook(e);break;case S.FindScope.SUBUNIT:default:this.findInActiveWorksheet(e);break}}focusSelection(){const e=this.currentMatch;e&&this._commandService.executeCommand(C.SelectRangeCommand.id,{unitId:e.unitId,subUnit:e.range.subUnitId,range:e.range.range})}_toggleDisplayRawFormula(e){this._contextService.setContextValue(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(I.filter(([s,o])=>s.id===C.SetWorksheetActiveOperation.id&&!(o!=null&&o.fromFindReplace))).subscribe(()=>{const s=this._workbook.getActiveSheet();if(!s)return;const o=s.getSheetId();this._matchesByWorksheet.has(o)&&this._findNextMatchOnActiveSheetChange(s)})),this.disposeWithMe(l.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(I.filter(([s])=>s.type===l.CommandType.MUTATION&&s.params.unitId===this._workbook.getUnitId()),I.throttleTime(600,void 0,{leading:!1,trailing:!0})).subscribe(()=>r())),r(),n}_findNextMatchOnActiveSheetChange(e){let t,n,i=0;const r=this._matchesByWorksheet.get(e.getSheetId()),s=this._workbookSelections.getCurrentSelections();s!=null&&s.length?([t,i]=this._findNextMatchByRange(r,s[0].range),n=r.findIndex(o=>o===t)):(t=r[0],n=0,i=this._matches.findIndex(o=>o===t)),this._matchesPosition=i+1,this._activelyChangingMatch$.next(t),this._activeHighlightIndex=n,this._updateFindHighlight(),this._updateCurrentHighlightShape(n)}findInActiveWorksheet(e){const t=this._workbook.getUnitId(),n=()=>{var u;const h=this._workbook.getActiveSheet();if(!h)return!1;const d=this._workbookSelections.getCurrentSelections();return(u=d==null?void 0:d.some(g=>!se(g,h)))!=null?u:!1};let i,r=!0,s=!1;const o=()=>{const h=this._workbook.getActiveSheet();if(!h)return{results:[]};const d=this.currentMatch;s=n();const a=this._workbookSelections.getCurrentSelections(),u=s?this._findInSelections(h,a,e,t):this._findInWorksheet(h,e,t);return this._matches=u.results,this._matchesPosition=this._tryRestoreLastMatchesPosition(d,this._matches),r?(i=u,r=!1):this._matchesUpdate$.next(this._matches),this._updateFindHighlight(),u};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>this._updateFindHighlight())),this.disposeWithMe(I.merge(l.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(I.filter(([h])=>{if(h.type===l.CommandType.MUTATION&&h.params.unitId===this._workbook.getUnitId())return!0;if(h.id===C.SetSelectionsOperation.id&&h.params.unitId===t){const d=n();return d===!1&&s===!1?!1:(s=d,!0)}return!1})),this._workbook.activeSheet$.pipe(I.skip(1))).pipe(I.debounceTime(200)).subscribe(()=>o())),o(),i}_findInRange(e,t,n,i,r){const s=[],o=e.getSheetId(),h=(t.findDirection===S.FindDirection.COLUMN?e.iterateByColumn:e.iterateByRow).bind(e)(n);for(const d of h){const{row:a,col:u,colSpan:g,rowSpan:m,value:p}=d;if(r!=null&&r(a,u)||!p||e.getRowFiltered(a))continue;const{hit:R,replaceable:k,isFormula:b}=he(e,a,u,t,p);if(R){const y={provider:oe,unitId:i,replaceable:k,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.getColorFromTheme("yellow.400"),o=new l.ColorKit(s).toRgb(),h=this._workbook.getActiveSheet();if(!h)return;const d=h.getSheetId(),a=r.filter(g=>g.range.subUnitId===d).map((g,m)=>{const{startColumn:p,startRow:R,endColumn:k,endRow:b}=g.range.range,y=w.getCoordByCell(R,p,i,e),V=w.getCoordByCell(b,k,i,e),{startX:W,startY:H}=y,{endX:G,endY:Y}=V,T=!h.getRowRawVisible(R),E=!h.getColVisible(p),q=T||E,K=E?2:G-W,Q=T?2:Y-H,X={left:W,top:H,color:o,width:K,height:Q,evented:!1,inHiddenRange:q,zIndex:ce};return new te(`find-highlight-${m}`,X)});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 w.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(w.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?ne(t,h):ie(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:k}=p.range.range,b=this._getReplacedCellData(p,m,s,n,e,o);b&&g.setValue(k,R,b)}),h.push({count:a.length,subUnitId:u,value:g.getMatrix()})}),h?this._commandService.executeCommand(P.id,{unitId:t,replacements:h}):{success:0,failure:0}}_getReplacedCellData(e,t,n,i,r,s){var m;const o=e.range.range,{startRow:h,startColumn:d}=o,a=t.getCellRaw(h,d);if(e.isFormula)return n?{f:a.f.replace(new RegExp($(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([v(2,l.IUniverInstanceService),v(3,M.IRenderManagerService),v(4,l.ICommandService),v(5,l.IContextService),v(6,l.Inject(l.ThemeService)),v(7,l.Inject(C.SheetsSelectionsService))],F);function $(c){return c.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}let U=class extends l.Disposable{constructor(e,t,n){super();f(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(w.SheetSkeletonManagerService),o=this._injector.createInstance(F,r,s);return this._findModelsByUnitId.set(r.getUnitId(),o),o.start(n),o})}terminate(){this._terminate()}_terminate(){this._findModelsByUnitId.forEach(e=>e.dispose()),this._findModelsByUnitId.clear()}_preprocessQuery(e){let t=e.caseSensitive?e.findString:e.findString.toLowerCase();return t=t.trim(),{...e,findString:t}}};U=B([v(0,l.IUniverInstanceService),v(1,M.IRenderManagerService),v(2,l.Inject(l.Injector))],U);const _={hit:!1,replaceable:!1,isFormula:!1,rawData:null};function he(c,e,t,n,i){const{findBy:r}=n,s=r===S.FindBy.FORMULA,o=c.getCellRaw(e,t);return _.rawData=o,!(o!=null&&o.f)?(_.isFormula=!1,x(i,n)?o?(_.hit=!0,_.replaceable=!0):(_.hit=!0,_.replaceable=!1):(_.hit=!1,_.replaceable=!1),_):(_.isFormula=!0,s?x({v:o.f},n)?(_.hit=!0,_.replaceable=!0,_):(_.hit=!1,_.replaceable=!1,_):(_.replaceable=!1,x(i,n)?_.hit=!0:_.hit=!1,_))}function x(c,e){let t=ae(c);return t?e.matchesTheWholeCell?(t=le(t),e.caseSensitive?t===e.findString:t.toLowerCase()===e.findString):e.caseSensitive?t.indexOf(e.findString)>-1:t.toLowerCase().indexOf(e.findString)>-1:!1}function ae(c){var t,n,i;const e=(i=(n=(t=c==null?void 0:c.p)==null?void 0:t.body)==null?void 0:n.dataStream)!=null?i:c==null?void 0:c.v;return typeof e=="number"?`${e}`:typeof e=="boolean"?e?"1":"0":e}function le(c){return c.replace(/^ +/g,"").replace(/ +$/g,"")}var de=Object.defineProperty,ue=Object.getOwnPropertyDescriptor,ge=(c,e,t)=>e in c?de(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?ue(e,t):e,r=c.length-1,s;r>=0;r--)(s=c[r])&&(i=s(i)||i);return i},j=(c,e)=>(t,n)=>e(t,n,c),L=(c,e,t)=>ge(c,typeof e!="symbol"?e+"":e,t);const fe="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(Z,i)}onStarting(){[[exports.SheetsFindReplaceController]].forEach(e=>this._injector.add(e))}onSteady(){this._injector.get(exports.SheetsFindReplaceController)}};L(exports.UniverSheetsFindReplacePlugin,"pluginName",fe);L(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=P;
package/lib/es/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  var ue = Object.defineProperty;
2
2
  var ge = (h, e, t) => e in h ? ue(h, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : h[e] = t;
3
3
  var _ = (h, e, t) => ge(h, typeof e != "symbol" ? e + "" : e, t);
4
- import { CommandType as B, IUndoRedoService as _e, ICommandService as H, Rectangle as fe, Inject as C, Injector as T, IContextService as J, IUniverInstanceService as Z, ThemeService as Se, Disposable as q, EDITOR_ACTIVATED as me, UniverInstanceType as ee, fromCallback as U, ColorKit as pe, rotate as $, groupBy as ve, ObjectMatrix as Ie, Tools as Ce, replaceInDocumentBody as Re, DependentOn as be, IConfigService as ke, Plugin as we, merge as Me } from "@univerjs/core";
5
- import { FindReplaceController as xe, IFindReplaceService as ye, FindModel as Ue, FindBy as k, FindScope as I, FindDirection as b, UniverFindReplacePlugin as Pe } from "@univerjs/find-replace";
6
- import { SetRangeValuesCommand as te, SheetsSelectionsService as Be, SelectRangeCommand as We, SetWorksheetActiveOperation as Fe, SetSelectionsOperation as He, SetWorksheetActivateCommand as Te, UniverSheetsPlugin as L } from "@univerjs/sheets";
4
+ import { CommandType as B, IUndoRedoService as _e, ICommandService as H, Rectangle as fe, Inject as C, Injector as T, IContextService as J, IUniverInstanceService as Z, ThemeService as me, Disposable as q, EDITOR_ACTIVATED as Se, UniverInstanceType as ee, fromCallback as U, ColorKit as pe, rotate as $, groupBy as ve, ObjectMatrix as Ie, Tools as Ce, replaceInDocumentBody as Re, DependentOn as we, IConfigService as be, Plugin as ke, merge as Me } from "@univerjs/core";
5
+ import { FindReplaceController as xe, IFindReplaceService as ye, FindModel as Ue, FindBy as b, FindScope as I, FindDirection as w, UniverFindReplacePlugin as Pe } from "@univerjs/find-replace";
6
+ import { SetRangeValuesCommand as te, SheetsSelectionsService as Be, SelectRangeCommand as Fe, SetWorksheetActiveOperation as We, SetSelectionsOperation as He, SetWorksheetActivateCommand as Te, UniverSheetsPlugin as L } from "@univerjs/sheets";
7
7
  import { Shape as Ee, Rect as Oe, IRenderManagerService as ie, RENDER_RAW_FORMULA_KEY as Ae } from "@univerjs/engine-render";
8
8
  import { SheetSkeletonManagerService as Ne, getCoordByCell as j, getSheetObject as De, ScrollToCellCommand as $e } from "@univerjs/sheets-ui";
9
- import { filter as w, Subject as V, throttleTime as Le, merge as je, skip as Ve, debounceTime as Ge } from "rxjs";
9
+ import { filter as k, Subject as V, throttleTime as Le, merge as je, skip as Ve, debounceTime as Ge } from "rxjs";
10
10
  const Ye = "sheets-find-replace.config", G = {}, ne = {
11
11
  id: "sheet.command.replace",
12
12
  type: B.COMMAND,
@@ -75,7 +75,7 @@ var Ze = Object.getOwnPropertyDescriptor, E = (h, e, t, i) => {
75
75
  for (var n = i > 1 ? void 0 : i ? Ze(e, t) : e, r = h.length - 1, s; r >= 0; r--)
76
76
  (s = h[r]) && (n = s(n) || n);
77
77
  return n;
78
- }, m = (h, e) => (t, i) => e(t, i, h);
78
+ }, S = (h, e) => (t, i) => e(t, i, h);
79
79
  let M = class extends q {
80
80
  constructor(e, t, i, n, r) {
81
81
  super();
@@ -86,22 +86,22 @@ let M = class extends q {
86
86
  super.dispose(), this._findReplaceController.closePanel(), this._provider.dispose();
87
87
  }
88
88
  _init() {
89
- const e = this._injector.createInstance(F);
90
- this._provider = e, this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(e)), this.disposeWithMe(this._contextService.subscribeContextValue$(me).pipe(w((t) => !!t)).subscribe(() => this._findReplaceController.closePanel()));
89
+ const e = this._injector.createInstance(W);
90
+ this._provider = e, this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(e)), this.disposeWithMe(this._contextService.subscribeContextValue$(Se).pipe(k((t) => !!t)).subscribe(() => this._findReplaceController.closePanel()));
91
91
  }
92
92
  _initCommands() {
93
93
  [ne].forEach((e) => this.disposeWithMe(this._commandService.registerCommand(e)));
94
94
  }
95
95
  };
96
96
  M = E([
97
- m(0, C(T)),
98
- m(1, C(xe)),
99
- m(2, J),
100
- m(3, ye),
101
- m(4, H)
97
+ S(0, C(T)),
98
+ S(1, C(xe)),
99
+ S(2, J),
100
+ S(3, ye),
101
+ S(4, H)
102
102
  ], M);
103
103
  const qe = "sheets-find-replace-provider", et = 1e4;
104
- let W = class extends Ue {
104
+ let F = class extends Ue {
105
105
  constructor(e, t, i, n, r, s, o, c) {
106
106
  super();
107
107
  // We can directly inject the `FindReplaceService` here, and call its methods instead of using the observables.
@@ -145,7 +145,7 @@ let W = class extends Ue {
145
145
  return this._matches;
146
146
  }
147
147
  start(e) {
148
- switch (this._query = e, e.findBy === k.FORMULA ? this._toggleDisplayRawFormula(!0) : this._toggleDisplayRawFormula(!1), e.findScope) {
148
+ switch (this._query = e, e.findBy === b.FORMULA ? this._toggleDisplayRawFormula(!0) : this._toggleDisplayRawFormula(!1), e.findScope) {
149
149
  case I.UNIT:
150
150
  this.findInWorkbook(e);
151
151
  break;
@@ -157,7 +157,7 @@ let W = class extends Ue {
157
157
  }
158
158
  focusSelection() {
159
159
  const e = this.currentMatch;
160
- e && this._commandService.executeCommand(We.id, {
160
+ e && this._commandService.executeCommand(Fe.id, {
161
161
  unitId: e.unitId,
162
162
  subUnit: e.range.subUnitId,
163
163
  range: e.range.range
@@ -184,7 +184,7 @@ let W = class extends Ue {
184
184
  return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(() => {
185
185
  this._updateFindHighlight(), this._updateCurrentHighlightShape(this._activeHighlightIndex);
186
186
  })), this.disposeWithMe(
187
- U(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(w(([s, o]) => s.id === Fe.id && !(o != null && o.fromFindReplace))).subscribe(() => {
187
+ U(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(k(([s, o]) => s.id === We.id && !(o != null && o.fromFindReplace))).subscribe(() => {
188
188
  const s = this._workbook.getActiveSheet();
189
189
  if (!s)
190
190
  return;
@@ -193,7 +193,7 @@ let W = class extends Ue {
193
193
  })
194
194
  ), this.disposeWithMe(
195
195
  U(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(
196
- w(
196
+ k(
197
197
  ([s]) => s.type === B.MUTATION && s.params.unitId === this._workbook.getUnitId()
198
198
  ),
199
199
  Le(600, void 0, { leading: !1, trailing: !0 })
@@ -234,7 +234,7 @@ let W = class extends Ue {
234
234
  return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(() => this._updateFindHighlight())), this.disposeWithMe(
235
235
  je(
236
236
  U(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(
237
- w(([c]) => {
237
+ k(([c]) => {
238
238
  if (c.type === B.MUTATION && c.params.unitId === this._workbook.getUnitId())
239
239
  return !0;
240
240
  if (c.id === He.id && c.params.unitId === t) {
@@ -250,12 +250,12 @@ let W = class extends Ue {
250
250
  ), o(), n;
251
251
  }
252
252
  _findInRange(e, t, i, n, r) {
253
- const s = [], o = e.getSheetId(), c = (t.findDirection === b.COLUMN ? e.iterateByColumn : e.iterateByRow).bind(e)(i);
253
+ const s = [], o = e.getSheetId(), c = (t.findDirection === w.COLUMN ? e.iterateByColumn : e.iterateByRow).bind(e)(i);
254
254
  for (const l of c) {
255
- const { row: a, col: d, colSpan: u, rowSpan: f, value: S } = l;
256
- if (r != null && r(a, d) || !S || e.getRowFiltered(a))
255
+ const { row: a, col: d, colSpan: u, rowSpan: f, value: m } = l;
256
+ if (r != null && r(a, d) || !m || e.getRowFiltered(a))
257
257
  continue;
258
- const { hit: p, replaceable: R, isFormula: v } = tt(e, a, d, t, S);
258
+ const { hit: p, replaceable: R, isFormula: v } = tt(e, a, d, t, m);
259
259
  if (p) {
260
260
  const y = {
261
261
  provider: qe,
@@ -278,7 +278,7 @@ let W = class extends Ue {
278
278
  return { results: s };
279
279
  }
280
280
  _findInSelections(e, t, i, n) {
281
- const { findDirection: r } = i, s = r === b.ROW ? K : Q, o = /* @__PURE__ */ new Set();
281
+ const { findDirection: r } = i, s = r === w.ROW ? K : Q, o = /* @__PURE__ */ new Set();
282
282
  return { results: t.map((l) => this._findInRange(e, i, l.range, n, (a, d) => {
283
283
  const u = `${a}-${d}`;
284
284
  return o.has(u) ? !0 : (o.add(u), !1);
@@ -305,11 +305,11 @@ let W = class extends Ue {
305
305
  const t = this._workbook.getUnitId(), i = this._renderManagerService.getRenderById(t);
306
306
  if (i == null)
307
307
  return;
308
- const { scene: n } = i, r = this._matches, s = this._themeService.getCurrentTheme().gold400, o = new pe(s).toRgb(), c = this._workbook.getActiveSheet();
308
+ const { scene: n } = i, r = this._matches, s = this._themeService.getColorFromTheme("yellow.400"), o = new pe(s).toRgb(), c = this._workbook.getActiveSheet();
309
309
  if (!c)
310
310
  return;
311
311
  const l = c.getSheetId(), a = r.filter((u) => u.range.subUnitId === l).map((u, f) => {
312
- const { startColumn: S, startRow: p, endColumn: R, endRow: v } = u.range.range, y = j(p, S, n, e), re = j(v, R, n, e), { startX: O, startY: A } = y, { endX: oe, endY: he } = re, N = !c.getRowRawVisible(p), D = !c.getColVisible(S), ce = N || D, ae = D ? 2 : oe - O, le = N ? 2 : he - A, de = {
312
+ const { startColumn: m, startRow: p, endColumn: R, endRow: v } = u.range.range, y = j(p, m, n, e), re = j(v, R, n, e), { startX: O, startY: A } = y, { endX: oe, endY: he } = re, N = !c.getRowRawVisible(p), D = !c.getColVisible(m), ce = N || D, ae = D ? 2 : oe - O, le = N ? 2 : he - A, de = {
313
313
  left: O,
314
314
  top: A,
315
315
  color: o,
@@ -361,7 +361,7 @@ let W = class extends Ue {
361
361
  const t = (o = e == null ? void 0 : e.loop) != null ? o : !1, i = (c = e == null ? void 0 : e.stayIfOnMatch) != null ? c : !1, n = (l = e == null ? void 0 : e.noFocus) != null ? l : !1, r = (a = e == null ? void 0 : e.ignoreSelection) != null ? a : !1, s = this._findNextMatch(t, i, r);
362
362
  if (s) {
363
363
  const [u, f] = s;
364
- return this._matchesPosition = f + 1, this._query.findScope === I.UNIT ? this._activeHighlightIndex = this._matchesByWorksheet.get(u.range.subUnitId).findIndex((S) => S === u) : this._activeHighlightIndex = f, n || this._focusMatch(u), ((d = this._workbook.getActiveSheet()) == null ? void 0 : d.getSheetId()) === u.range.subUnitId && this._updateCurrentHighlightShape(this._activeHighlightIndex), u;
364
+ return this._matchesPosition = f + 1, this._query.findScope === I.UNIT ? this._activeHighlightIndex = this._matchesByWorksheet.get(u.range.subUnitId).findIndex((m) => m === u) : this._activeHighlightIndex = f, n || this._focusMatch(u), ((d = this._workbook.getActiveSheet()) == null ? void 0 : d.getSheetId()) === u.range.subUnitId && this._updateCurrentHighlightShape(this._activeHighlightIndex), u;
365
365
  }
366
366
  return this._matchesPosition = 0, this._updateCurrentHighlightShape(), null;
367
367
  }
@@ -372,7 +372,7 @@ let W = class extends Ue {
372
372
  const t = (o = e == null ? void 0 : e.loop) != null ? o : !1, i = (c = e == null ? void 0 : e.stayIfOnMatch) != null ? c : !1, n = (l = e == null ? void 0 : e.noFocus) != null ? l : !1, r = (a = e == null ? void 0 : e.ignoreSelection) != null ? a : !1, s = this._findPreviousMatch(t, i, r);
373
373
  if (s) {
374
374
  const [u, f] = s;
375
- return this._matchesPosition = f + 1, this._query.findScope === I.UNIT ? this._activeHighlightIndex = this._matchesByWorksheet.get(u.range.subUnitId).findIndex((S) => S === u) : this._activeHighlightIndex = f, n || this._focusMatch(u), ((d = this._workbook.getActiveSheet()) == null ? void 0 : d.getSheetId()) === u.range.subUnitId && this._updateCurrentHighlightShape(this._activeHighlightIndex), u;
375
+ return this._matchesPosition = f + 1, this._query.findScope === I.UNIT ? this._activeHighlightIndex = this._matchesByWorksheet.get(u.range.subUnitId).findIndex((m) => m === u) : this._activeHighlightIndex = f, n || this._focusMatch(u), ((d = this._workbook.getActiveSheet()) == null ? void 0 : d.getSheetId()) === u.range.subUnitId && this._updateCurrentHighlightShape(this._activeHighlightIndex), u;
376
376
  }
377
377
  return this._matchesPosition = 0, this._updateCurrentHighlightShape(), null;
378
378
  }
@@ -433,7 +433,7 @@ let W = class extends Ue {
433
433
  return s != null ? s : null;
434
434
  }
435
435
  _findNextMatchByRange(e, t, i = !1) {
436
- const n = this._query.findDirection === b.ROW;
436
+ const n = this._query.findDirection === w.ROW;
437
437
  let r = e.findIndex((o) => {
438
438
  const c = o.range.range;
439
439
  if (!(n ? K(t, c) : Q(t, c)))
@@ -446,7 +446,7 @@ let W = class extends Ue {
446
446
  return [s, this._matches.findIndex((o) => o === s)];
447
447
  }
448
448
  _findPreviousMatchByRange(e, t, i = !1) {
449
- const n = this._query.findDirection === b.ROW;
449
+ const n = this._query.findDirection === w.ROW;
450
450
  let r = this._matches.findLastIndex((o) => {
451
451
  const c = o.range.range;
452
452
  if (!(n ? Xe(t, c) : ze(t, c)))
@@ -464,7 +464,7 @@ let W = class extends Ue {
464
464
  const t = this.currentMatch.range, i = this._workbook.getSheetBySheetId(this.currentMatch.range.subUnitId), n = this._getReplacedCellData(
465
465
  this.currentMatch,
466
466
  i,
467
- this._query.findBy === k.FORMULA,
467
+ this._query.findBy === b.FORMULA,
468
468
  this._query.findString,
469
469
  e,
470
470
  this._query.caseSensitive ? "g" : "ig"
@@ -482,11 +482,11 @@ let W = class extends Ue {
482
482
  async replaceAll(e) {
483
483
  if (this._matchesCount === 0 || !this._query)
484
484
  return { success: 0, failure: 0 };
485
- const t = this._workbook.getUnitId(), { findString: i, caseSensitive: n, findBy: r } = this._query, s = r === k.FORMULA, o = n ? "g" : "ig", c = [];
485
+ const t = this._workbook.getUnitId(), { findString: i, caseSensitive: n, findBy: r } = this._query, s = r === b.FORMULA, o = n ? "g" : "ig", c = [];
486
486
  return ve(this._matches.filter((a) => a.replaceable), (a) => a.range.subUnitId).forEach((a, d) => {
487
487
  const u = new Ie(), f = this._workbook.getSheetBySheetId(d);
488
- a.forEach((S) => {
489
- const { startColumn: p, startRow: R } = S.range.range, v = this._getReplacedCellData(S, f, s, i, e, o);
488
+ a.forEach((m) => {
489
+ const { startColumn: p, startRow: R } = m.range.range, v = this._getReplacedCellData(m, f, s, i, e, o);
490
490
  v && u.setValue(R, p, v);
491
491
  }), c.push({
492
492
  count: a.length,
@@ -504,24 +504,24 @@ let W = class extends Ue {
504
504
  if (e.isFormula)
505
505
  return i ? { f: a.f.replace(new RegExp(X(n), s), r), v: null } : null;
506
506
  if (!!((f = a.p) != null && f.body)) {
507
- const S = Ce.deepClone(a.p);
508
- return Re(S.body, n, r, this._query.caseSensitive), { p: S };
507
+ const m = Ce.deepClone(a.p);
508
+ return Re(m.body, n, r, this._query.caseSensitive), { p: m };
509
509
  }
510
510
  return { v: a.v.toString().replace(new RegExp(X(n), s), r) };
511
511
  }
512
512
  };
513
- W = E([
514
- m(2, Z),
515
- m(3, ie),
516
- m(4, H),
517
- m(5, J),
518
- m(6, C(Se)),
519
- m(7, C(Be))
520
- ], W);
513
+ F = E([
514
+ S(2, Z),
515
+ S(3, ie),
516
+ S(4, H),
517
+ S(5, J),
518
+ S(6, C(me)),
519
+ S(7, C(Be))
520
+ ], F);
521
521
  function X(h) {
522
522
  return h.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
523
523
  }
524
- let F = class extends q {
524
+ let W = class extends q {
525
525
  constructor(e, t, i) {
526
526
  super();
527
527
  /**
@@ -534,7 +534,7 @@ let F = class extends q {
534
534
  this._terminate();
535
535
  const t = this._univerInstanceService.getAllUnitsForType(ee.UNIVER_SHEET), i = this._preprocessQuery(e);
536
536
  return t.map((r) => {
537
- const s = this._renderManagerService.getRenderById(r.getUnitId()).with(Ne), o = this._injector.createInstance(W, r, s);
537
+ const s = this._renderManagerService.getRenderById(r.getUnitId()).with(Ne), o = this._injector.createInstance(F, r, s);
538
538
  return this._findModelsByUnitId.set(r.getUnitId(), o), o.start(i), o;
539
539
  });
540
540
  }
@@ -557,14 +557,14 @@ let F = class extends q {
557
557
  };
558
558
  }
559
559
  };
560
- F = E([
561
- m(0, Z),
562
- m(1, ie),
563
- m(2, C(T))
564
- ], F);
560
+ W = E([
561
+ S(0, Z),
562
+ S(1, ie),
563
+ S(2, C(T))
564
+ ], W);
565
565
  const g = { hit: !1, replaceable: !1, isFormula: !1, rawData: null };
566
566
  function tt(h, e, t, i, n) {
567
- const { findBy: r } = i, s = r === k.FORMULA, o = h.getCellRaw(e, t);
567
+ const { findBy: r } = i, s = r === b.FORMULA, o = h.getCellRaw(e, t);
568
568
  return g.rawData = o, !(o != null && o.f) ? (g.isFormula = !1, P(n, i) ? o ? (g.hit = !0, g.replaceable = !0) : (g.hit = !0, g.replaceable = !1) : (g.hit = !1, g.replaceable = !1), g) : (g.isFormula = !0, s ? P({ v: o.f }, i) ? (g.hit = !0, g.replaceable = !0, g) : (g.hit = !1, g.replaceable = !1, g) : (g.replaceable = !1, P(n, i) ? g.hit = !0 : g.hit = !1, g));
569
569
  }
570
570
  function P(h, e) {
@@ -585,7 +585,7 @@ var st = Object.defineProperty, rt = Object.getOwnPropertyDescriptor, ot = (h, e
585
585
  return n;
586
586
  }, z = (h, e) => (t, i) => e(t, i, h), se = (h, e, t) => ot(h, typeof e != "symbol" ? e + "" : e, t);
587
587
  const ct = "SHEET_FIND_REPLACE_PLUGIN";
588
- let x = class extends we {
588
+ let x = class extends ke {
589
589
  constructor(h = G, e, t) {
590
590
  super(), this._config = h, this._injector = e, this._configService = t;
591
591
  const { ...i } = Me(
@@ -605,9 +605,9 @@ let x = class extends we {
605
605
  se(x, "pluginName", ct);
606
606
  se(x, "type", ee.UNIVER_SHEET);
607
607
  x = ht([
608
- be(L, L, Pe),
608
+ we(L, L, Pe),
609
609
  z(1, C(T)),
610
- z(2, ke)
610
+ z(2, be)
611
611
  ], x);
612
612
  export {
613
613
  ne as SheetReplaceCommand,
package/lib/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  var ue = Object.defineProperty;
2
2
  var ge = (h, e, t) => e in h ? ue(h, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : h[e] = t;
3
3
  var _ = (h, e, t) => ge(h, typeof e != "symbol" ? e + "" : e, t);
4
- import { CommandType as B, IUndoRedoService as _e, ICommandService as H, Rectangle as fe, Inject as C, Injector as T, IContextService as J, IUniverInstanceService as Z, ThemeService as Se, Disposable as q, EDITOR_ACTIVATED as me, UniverInstanceType as ee, fromCallback as U, ColorKit as pe, rotate as $, groupBy as ve, ObjectMatrix as Ie, Tools as Ce, replaceInDocumentBody as Re, DependentOn as be, IConfigService as ke, Plugin as we, merge as Me } from "@univerjs/core";
5
- import { FindReplaceController as xe, IFindReplaceService as ye, FindModel as Ue, FindBy as k, FindScope as I, FindDirection as b, UniverFindReplacePlugin as Pe } from "@univerjs/find-replace";
6
- import { SetRangeValuesCommand as te, SheetsSelectionsService as Be, SelectRangeCommand as We, SetWorksheetActiveOperation as Fe, SetSelectionsOperation as He, SetWorksheetActivateCommand as Te, UniverSheetsPlugin as L } from "@univerjs/sheets";
4
+ import { CommandType as B, IUndoRedoService as _e, ICommandService as H, Rectangle as fe, Inject as C, Injector as T, IContextService as J, IUniverInstanceService as Z, ThemeService as me, Disposable as q, EDITOR_ACTIVATED as Se, UniverInstanceType as ee, fromCallback as U, ColorKit as pe, rotate as $, groupBy as ve, ObjectMatrix as Ie, Tools as Ce, replaceInDocumentBody as Re, DependentOn as we, IConfigService as be, Plugin as ke, merge as Me } from "@univerjs/core";
5
+ import { FindReplaceController as xe, IFindReplaceService as ye, FindModel as Ue, FindBy as b, FindScope as I, FindDirection as w, UniverFindReplacePlugin as Pe } from "@univerjs/find-replace";
6
+ import { SetRangeValuesCommand as te, SheetsSelectionsService as Be, SelectRangeCommand as Fe, SetWorksheetActiveOperation as We, SetSelectionsOperation as He, SetWorksheetActivateCommand as Te, UniverSheetsPlugin as L } from "@univerjs/sheets";
7
7
  import { Shape as Ee, Rect as Oe, IRenderManagerService as ie, RENDER_RAW_FORMULA_KEY as Ae } from "@univerjs/engine-render";
8
8
  import { SheetSkeletonManagerService as Ne, getCoordByCell as j, getSheetObject as De, ScrollToCellCommand as $e } from "@univerjs/sheets-ui";
9
- import { filter as w, Subject as V, throttleTime as Le, merge as je, skip as Ve, debounceTime as Ge } from "rxjs";
9
+ import { filter as k, Subject as V, throttleTime as Le, merge as je, skip as Ve, debounceTime as Ge } from "rxjs";
10
10
  const Ye = "sheets-find-replace.config", G = {}, ne = {
11
11
  id: "sheet.command.replace",
12
12
  type: B.COMMAND,
@@ -75,7 +75,7 @@ var Ze = Object.getOwnPropertyDescriptor, E = (h, e, t, i) => {
75
75
  for (var n = i > 1 ? void 0 : i ? Ze(e, t) : e, r = h.length - 1, s; r >= 0; r--)
76
76
  (s = h[r]) && (n = s(n) || n);
77
77
  return n;
78
- }, m = (h, e) => (t, i) => e(t, i, h);
78
+ }, S = (h, e) => (t, i) => e(t, i, h);
79
79
  let M = class extends q {
80
80
  constructor(e, t, i, n, r) {
81
81
  super();
@@ -86,22 +86,22 @@ let M = class extends q {
86
86
  super.dispose(), this._findReplaceController.closePanel(), this._provider.dispose();
87
87
  }
88
88
  _init() {
89
- const e = this._injector.createInstance(F);
90
- this._provider = e, this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(e)), this.disposeWithMe(this._contextService.subscribeContextValue$(me).pipe(w((t) => !!t)).subscribe(() => this._findReplaceController.closePanel()));
89
+ const e = this._injector.createInstance(W);
90
+ this._provider = e, this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(e)), this.disposeWithMe(this._contextService.subscribeContextValue$(Se).pipe(k((t) => !!t)).subscribe(() => this._findReplaceController.closePanel()));
91
91
  }
92
92
  _initCommands() {
93
93
  [ne].forEach((e) => this.disposeWithMe(this._commandService.registerCommand(e)));
94
94
  }
95
95
  };
96
96
  M = E([
97
- m(0, C(T)),
98
- m(1, C(xe)),
99
- m(2, J),
100
- m(3, ye),
101
- m(4, H)
97
+ S(0, C(T)),
98
+ S(1, C(xe)),
99
+ S(2, J),
100
+ S(3, ye),
101
+ S(4, H)
102
102
  ], M);
103
103
  const qe = "sheets-find-replace-provider", et = 1e4;
104
- let W = class extends Ue {
104
+ let F = class extends Ue {
105
105
  constructor(e, t, i, n, r, s, o, c) {
106
106
  super();
107
107
  // We can directly inject the `FindReplaceService` here, and call its methods instead of using the observables.
@@ -145,7 +145,7 @@ let W = class extends Ue {
145
145
  return this._matches;
146
146
  }
147
147
  start(e) {
148
- switch (this._query = e, e.findBy === k.FORMULA ? this._toggleDisplayRawFormula(!0) : this._toggleDisplayRawFormula(!1), e.findScope) {
148
+ switch (this._query = e, e.findBy === b.FORMULA ? this._toggleDisplayRawFormula(!0) : this._toggleDisplayRawFormula(!1), e.findScope) {
149
149
  case I.UNIT:
150
150
  this.findInWorkbook(e);
151
151
  break;
@@ -157,7 +157,7 @@ let W = class extends Ue {
157
157
  }
158
158
  focusSelection() {
159
159
  const e = this.currentMatch;
160
- e && this._commandService.executeCommand(We.id, {
160
+ e && this._commandService.executeCommand(Fe.id, {
161
161
  unitId: e.unitId,
162
162
  subUnit: e.range.subUnitId,
163
163
  range: e.range.range
@@ -184,7 +184,7 @@ let W = class extends Ue {
184
184
  return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(() => {
185
185
  this._updateFindHighlight(), this._updateCurrentHighlightShape(this._activeHighlightIndex);
186
186
  })), this.disposeWithMe(
187
- U(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(w(([s, o]) => s.id === Fe.id && !(o != null && o.fromFindReplace))).subscribe(() => {
187
+ U(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(k(([s, o]) => s.id === We.id && !(o != null && o.fromFindReplace))).subscribe(() => {
188
188
  const s = this._workbook.getActiveSheet();
189
189
  if (!s)
190
190
  return;
@@ -193,7 +193,7 @@ let W = class extends Ue {
193
193
  })
194
194
  ), this.disposeWithMe(
195
195
  U(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(
196
- w(
196
+ k(
197
197
  ([s]) => s.type === B.MUTATION && s.params.unitId === this._workbook.getUnitId()
198
198
  ),
199
199
  Le(600, void 0, { leading: !1, trailing: !0 })
@@ -234,7 +234,7 @@ let W = class extends Ue {
234
234
  return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(() => this._updateFindHighlight())), this.disposeWithMe(
235
235
  je(
236
236
  U(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(
237
- w(([c]) => {
237
+ k(([c]) => {
238
238
  if (c.type === B.MUTATION && c.params.unitId === this._workbook.getUnitId())
239
239
  return !0;
240
240
  if (c.id === He.id && c.params.unitId === t) {
@@ -250,12 +250,12 @@ let W = class extends Ue {
250
250
  ), o(), n;
251
251
  }
252
252
  _findInRange(e, t, i, n, r) {
253
- const s = [], o = e.getSheetId(), c = (t.findDirection === b.COLUMN ? e.iterateByColumn : e.iterateByRow).bind(e)(i);
253
+ const s = [], o = e.getSheetId(), c = (t.findDirection === w.COLUMN ? e.iterateByColumn : e.iterateByRow).bind(e)(i);
254
254
  for (const l of c) {
255
- const { row: a, col: d, colSpan: u, rowSpan: f, value: S } = l;
256
- if (r != null && r(a, d) || !S || e.getRowFiltered(a))
255
+ const { row: a, col: d, colSpan: u, rowSpan: f, value: m } = l;
256
+ if (r != null && r(a, d) || !m || e.getRowFiltered(a))
257
257
  continue;
258
- const { hit: p, replaceable: R, isFormula: v } = tt(e, a, d, t, S);
258
+ const { hit: p, replaceable: R, isFormula: v } = tt(e, a, d, t, m);
259
259
  if (p) {
260
260
  const y = {
261
261
  provider: qe,
@@ -278,7 +278,7 @@ let W = class extends Ue {
278
278
  return { results: s };
279
279
  }
280
280
  _findInSelections(e, t, i, n) {
281
- const { findDirection: r } = i, s = r === b.ROW ? K : Q, o = /* @__PURE__ */ new Set();
281
+ const { findDirection: r } = i, s = r === w.ROW ? K : Q, o = /* @__PURE__ */ new Set();
282
282
  return { results: t.map((l) => this._findInRange(e, i, l.range, n, (a, d) => {
283
283
  const u = `${a}-${d}`;
284
284
  return o.has(u) ? !0 : (o.add(u), !1);
@@ -305,11 +305,11 @@ let W = class extends Ue {
305
305
  const t = this._workbook.getUnitId(), i = this._renderManagerService.getRenderById(t);
306
306
  if (i == null)
307
307
  return;
308
- const { scene: n } = i, r = this._matches, s = this._themeService.getCurrentTheme().gold400, o = new pe(s).toRgb(), c = this._workbook.getActiveSheet();
308
+ const { scene: n } = i, r = this._matches, s = this._themeService.getColorFromTheme("yellow.400"), o = new pe(s).toRgb(), c = this._workbook.getActiveSheet();
309
309
  if (!c)
310
310
  return;
311
311
  const l = c.getSheetId(), a = r.filter((u) => u.range.subUnitId === l).map((u, f) => {
312
- const { startColumn: S, startRow: p, endColumn: R, endRow: v } = u.range.range, y = j(p, S, n, e), re = j(v, R, n, e), { startX: O, startY: A } = y, { endX: oe, endY: he } = re, N = !c.getRowRawVisible(p), D = !c.getColVisible(S), ce = N || D, ae = D ? 2 : oe - O, le = N ? 2 : he - A, de = {
312
+ const { startColumn: m, startRow: p, endColumn: R, endRow: v } = u.range.range, y = j(p, m, n, e), re = j(v, R, n, e), { startX: O, startY: A } = y, { endX: oe, endY: he } = re, N = !c.getRowRawVisible(p), D = !c.getColVisible(m), ce = N || D, ae = D ? 2 : oe - O, le = N ? 2 : he - A, de = {
313
313
  left: O,
314
314
  top: A,
315
315
  color: o,
@@ -361,7 +361,7 @@ let W = class extends Ue {
361
361
  const t = (o = e == null ? void 0 : e.loop) != null ? o : !1, i = (c = e == null ? void 0 : e.stayIfOnMatch) != null ? c : !1, n = (l = e == null ? void 0 : e.noFocus) != null ? l : !1, r = (a = e == null ? void 0 : e.ignoreSelection) != null ? a : !1, s = this._findNextMatch(t, i, r);
362
362
  if (s) {
363
363
  const [u, f] = s;
364
- return this._matchesPosition = f + 1, this._query.findScope === I.UNIT ? this._activeHighlightIndex = this._matchesByWorksheet.get(u.range.subUnitId).findIndex((S) => S === u) : this._activeHighlightIndex = f, n || this._focusMatch(u), ((d = this._workbook.getActiveSheet()) == null ? void 0 : d.getSheetId()) === u.range.subUnitId && this._updateCurrentHighlightShape(this._activeHighlightIndex), u;
364
+ return this._matchesPosition = f + 1, this._query.findScope === I.UNIT ? this._activeHighlightIndex = this._matchesByWorksheet.get(u.range.subUnitId).findIndex((m) => m === u) : this._activeHighlightIndex = f, n || this._focusMatch(u), ((d = this._workbook.getActiveSheet()) == null ? void 0 : d.getSheetId()) === u.range.subUnitId && this._updateCurrentHighlightShape(this._activeHighlightIndex), u;
365
365
  }
366
366
  return this._matchesPosition = 0, this._updateCurrentHighlightShape(), null;
367
367
  }
@@ -372,7 +372,7 @@ let W = class extends Ue {
372
372
  const t = (o = e == null ? void 0 : e.loop) != null ? o : !1, i = (c = e == null ? void 0 : e.stayIfOnMatch) != null ? c : !1, n = (l = e == null ? void 0 : e.noFocus) != null ? l : !1, r = (a = e == null ? void 0 : e.ignoreSelection) != null ? a : !1, s = this._findPreviousMatch(t, i, r);
373
373
  if (s) {
374
374
  const [u, f] = s;
375
- return this._matchesPosition = f + 1, this._query.findScope === I.UNIT ? this._activeHighlightIndex = this._matchesByWorksheet.get(u.range.subUnitId).findIndex((S) => S === u) : this._activeHighlightIndex = f, n || this._focusMatch(u), ((d = this._workbook.getActiveSheet()) == null ? void 0 : d.getSheetId()) === u.range.subUnitId && this._updateCurrentHighlightShape(this._activeHighlightIndex), u;
375
+ return this._matchesPosition = f + 1, this._query.findScope === I.UNIT ? this._activeHighlightIndex = this._matchesByWorksheet.get(u.range.subUnitId).findIndex((m) => m === u) : this._activeHighlightIndex = f, n || this._focusMatch(u), ((d = this._workbook.getActiveSheet()) == null ? void 0 : d.getSheetId()) === u.range.subUnitId && this._updateCurrentHighlightShape(this._activeHighlightIndex), u;
376
376
  }
377
377
  return this._matchesPosition = 0, this._updateCurrentHighlightShape(), null;
378
378
  }
@@ -433,7 +433,7 @@ let W = class extends Ue {
433
433
  return s != null ? s : null;
434
434
  }
435
435
  _findNextMatchByRange(e, t, i = !1) {
436
- const n = this._query.findDirection === b.ROW;
436
+ const n = this._query.findDirection === w.ROW;
437
437
  let r = e.findIndex((o) => {
438
438
  const c = o.range.range;
439
439
  if (!(n ? K(t, c) : Q(t, c)))
@@ -446,7 +446,7 @@ let W = class extends Ue {
446
446
  return [s, this._matches.findIndex((o) => o === s)];
447
447
  }
448
448
  _findPreviousMatchByRange(e, t, i = !1) {
449
- const n = this._query.findDirection === b.ROW;
449
+ const n = this._query.findDirection === w.ROW;
450
450
  let r = this._matches.findLastIndex((o) => {
451
451
  const c = o.range.range;
452
452
  if (!(n ? Xe(t, c) : ze(t, c)))
@@ -464,7 +464,7 @@ let W = class extends Ue {
464
464
  const t = this.currentMatch.range, i = this._workbook.getSheetBySheetId(this.currentMatch.range.subUnitId), n = this._getReplacedCellData(
465
465
  this.currentMatch,
466
466
  i,
467
- this._query.findBy === k.FORMULA,
467
+ this._query.findBy === b.FORMULA,
468
468
  this._query.findString,
469
469
  e,
470
470
  this._query.caseSensitive ? "g" : "ig"
@@ -482,11 +482,11 @@ let W = class extends Ue {
482
482
  async replaceAll(e) {
483
483
  if (this._matchesCount === 0 || !this._query)
484
484
  return { success: 0, failure: 0 };
485
- const t = this._workbook.getUnitId(), { findString: i, caseSensitive: n, findBy: r } = this._query, s = r === k.FORMULA, o = n ? "g" : "ig", c = [];
485
+ const t = this._workbook.getUnitId(), { findString: i, caseSensitive: n, findBy: r } = this._query, s = r === b.FORMULA, o = n ? "g" : "ig", c = [];
486
486
  return ve(this._matches.filter((a) => a.replaceable), (a) => a.range.subUnitId).forEach((a, d) => {
487
487
  const u = new Ie(), f = this._workbook.getSheetBySheetId(d);
488
- a.forEach((S) => {
489
- const { startColumn: p, startRow: R } = S.range.range, v = this._getReplacedCellData(S, f, s, i, e, o);
488
+ a.forEach((m) => {
489
+ const { startColumn: p, startRow: R } = m.range.range, v = this._getReplacedCellData(m, f, s, i, e, o);
490
490
  v && u.setValue(R, p, v);
491
491
  }), c.push({
492
492
  count: a.length,
@@ -504,24 +504,24 @@ let W = class extends Ue {
504
504
  if (e.isFormula)
505
505
  return i ? { f: a.f.replace(new RegExp(X(n), s), r), v: null } : null;
506
506
  if (!!((f = a.p) != null && f.body)) {
507
- const S = Ce.deepClone(a.p);
508
- return Re(S.body, n, r, this._query.caseSensitive), { p: S };
507
+ const m = Ce.deepClone(a.p);
508
+ return Re(m.body, n, r, this._query.caseSensitive), { p: m };
509
509
  }
510
510
  return { v: a.v.toString().replace(new RegExp(X(n), s), r) };
511
511
  }
512
512
  };
513
- W = E([
514
- m(2, Z),
515
- m(3, ie),
516
- m(4, H),
517
- m(5, J),
518
- m(6, C(Se)),
519
- m(7, C(Be))
520
- ], W);
513
+ F = E([
514
+ S(2, Z),
515
+ S(3, ie),
516
+ S(4, H),
517
+ S(5, J),
518
+ S(6, C(me)),
519
+ S(7, C(Be))
520
+ ], F);
521
521
  function X(h) {
522
522
  return h.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
523
523
  }
524
- let F = class extends q {
524
+ let W = class extends q {
525
525
  constructor(e, t, i) {
526
526
  super();
527
527
  /**
@@ -534,7 +534,7 @@ let F = class extends q {
534
534
  this._terminate();
535
535
  const t = this._univerInstanceService.getAllUnitsForType(ee.UNIVER_SHEET), i = this._preprocessQuery(e);
536
536
  return t.map((r) => {
537
- const s = this._renderManagerService.getRenderById(r.getUnitId()).with(Ne), o = this._injector.createInstance(W, r, s);
537
+ const s = this._renderManagerService.getRenderById(r.getUnitId()).with(Ne), o = this._injector.createInstance(F, r, s);
538
538
  return this._findModelsByUnitId.set(r.getUnitId(), o), o.start(i), o;
539
539
  });
540
540
  }
@@ -557,14 +557,14 @@ let F = class extends q {
557
557
  };
558
558
  }
559
559
  };
560
- F = E([
561
- m(0, Z),
562
- m(1, ie),
563
- m(2, C(T))
564
- ], F);
560
+ W = E([
561
+ S(0, Z),
562
+ S(1, ie),
563
+ S(2, C(T))
564
+ ], W);
565
565
  const g = { hit: !1, replaceable: !1, isFormula: !1, rawData: null };
566
566
  function tt(h, e, t, i, n) {
567
- const { findBy: r } = i, s = r === k.FORMULA, o = h.getCellRaw(e, t);
567
+ const { findBy: r } = i, s = r === b.FORMULA, o = h.getCellRaw(e, t);
568
568
  return g.rawData = o, !(o != null && o.f) ? (g.isFormula = !1, P(n, i) ? o ? (g.hit = !0, g.replaceable = !0) : (g.hit = !0, g.replaceable = !1) : (g.hit = !1, g.replaceable = !1), g) : (g.isFormula = !0, s ? P({ v: o.f }, i) ? (g.hit = !0, g.replaceable = !0, g) : (g.hit = !1, g.replaceable = !1, g) : (g.replaceable = !1, P(n, i) ? g.hit = !0 : g.hit = !1, g));
569
569
  }
570
570
  function P(h, e) {
@@ -585,7 +585,7 @@ var st = Object.defineProperty, rt = Object.getOwnPropertyDescriptor, ot = (h, e
585
585
  return n;
586
586
  }, z = (h, e) => (t, i) => e(t, i, h), se = (h, e, t) => ot(h, typeof e != "symbol" ? e + "" : e, t);
587
587
  const ct = "SHEET_FIND_REPLACE_PLUGIN";
588
- let x = class extends we {
588
+ let x = class extends ke {
589
589
  constructor(h = G, e, t) {
590
590
  super(), this._config = h, this._injector = e, this._configService = t;
591
591
  const { ...i } = Me(
@@ -605,9 +605,9 @@ let x = class extends we {
605
605
  se(x, "pluginName", ct);
606
606
  se(x, "type", ee.UNIVER_SHEET);
607
607
  x = ht([
608
- be(L, L, Pe),
608
+ we(L, L, Pe),
609
609
  z(1, C(T)),
610
- z(2, ke)
610
+ z(2, be)
611
611
  ], x);
612
612
  export {
613
613
  ne as SheetReplaceCommand,
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(_,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/find-replace"),require("@univerjs/sheets"),require("@univerjs/engine-render"),require("@univerjs/sheets-ui"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/find-replace","@univerjs/sheets","@univerjs/engine-render","@univerjs/sheets-ui","rxjs"],a):(_=typeof globalThis<"u"?globalThis:_||self,a(_.UniverSheetsFindReplace={},_.UniverCore,_.UniverFindReplace,_.UniverSheets,_.UniverEngineRender,_.UniverSheetsUi,_.rxjs))})(this,function(_,a,f,R,w,M,C){"use strict";var fe=Object.defineProperty;var Se=(_,a,f)=>a in _?fe(_,a,{enumerable:!0,configurable:!0,writable:!0,value:f}):_[a]=f;var m=(_,a,f)=>Se(_,typeof a!="symbol"?a+"":a,f);const G="sheets-find-replace.config",T={},F={id:"sheet.command.replace",type:a.CommandType.COMMAND,handler:async(h,e)=>{const t=h.get(a.IUndoRedoService),n=h.get(a.ICommandService),{unitId:i,replacements:r}=e,s=t.__tempBatchingUndoRedo(i),o=await Promise.all(r.map(c=>n.executeCommand(R.SetRangeValuesCommand.id,{unitId:i,subUnitId:c.subUnitId,value:c.value})));return s.dispose(),Y(o,r)}};function Y(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}}class q extends w.Shape{constructor(t,n){super(t,n);m(this,"_activated",!1);m(this,"_inHiddenRange",!1);m(this,"_color");n&&this.setShapeProps(n)}setShapeProps(t){this._activated=!!t.activated,typeof t.inHiddenRange<"u"&&(this._inHiddenRange=t.inHiddenRange),typeof t.color<"u"&&(this._color=t.color),this.transformByState({width:t.width,height:t.height})}_draw(t){const n=this._activated,i=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 0.35)`,r=`rgb(${this._color.r}, ${this._color.g}, ${this._color.b})`;w.Rect.drawWith(t,{width:this.width,height:this.height,fill:i,stroke:n?r:void 0,strokeWidth:n?2:0,evented:!1})}}function H(h,e){return h.startRow===e.startRow&&h.startColumn===e.startColumn}function E(h,e){return h.startRow<e.startRow||h.startRow===e.startRow&&h.startColumn<=e.startColumn}function O(h,e){return h.startColumn<e.startColumn||h.startColumn===e.startColumn&&h.startRow<=e.startRow}function K(h,e){return h.startRow>e.startRow||h.startRow===e.startRow&&h.startColumn>=e.startColumn}function Q(h,e){return h.startColumn>e.startColumn||h.startColumn===e.startColumn&&h.startRow>=e.startRow}function X(h,e){const{range:t}=h,{startRow:n,startColumn:i}=t,r=e.getMergedCell(n,i);return r?a.Rectangle.equals(t,r):t.endRow===t.startRow&&t.endColumn===t.startColumn}var z=Object.getOwnPropertyDescriptor,U=(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=s(i)||i);return i},p=(h,e)=>(t,n)=>e(t,n,h);_.SheetsFindReplaceController=class extends a.Disposable{constructor(t,n,i,r,s){super();m(this,"_provider");this._injector=t,this._findReplaceController=n,this._contextService=i,this._findReplaceService=r,this._commandService=s,this._init(),this._initCommands()}dispose(){super.dispose(),this._findReplaceController.closePanel(),this._provider.dispose()}_init(){const t=this._injector.createInstance(P);this._provider=t,this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(t)),this.disposeWithMe(this._contextService.subscribeContextValue$(a.EDITOR_ACTIVATED).pipe(C.filter(n=>!!n)).subscribe(()=>this._findReplaceController.closePanel()))}_initCommands(){[F].forEach(t=>this.disposeWithMe(this._commandService.registerCommand(t)))}},_.SheetsFindReplaceController=U([p(0,a.Inject(a.Injector)),p(1,a.Inject(f.FindReplaceController)),p(2,a.IContextService),p(3,f.IFindReplaceService),p(4,a.ICommandService)],_.SheetsFindReplaceController);const J="sheets-find-replace-provider",Z=1e4;let x=class extends f.FindModel{constructor(e,t,n,i,r,s,o,c){super();m(this,"_matchesUpdate$",new C.Subject);m(this,"matchesUpdate$",this._matchesUpdate$.asObservable());m(this,"_activelyChangingMatch$",new C.Subject);m(this,"activelyChangingMatch$",this._activelyChangingMatch$.asObservable());m(this,"_matchesByWorksheet",new Map);m(this,"_matches",[]);m(this,"_matchesPosition",0);m(this,"_activeHighlightIndex",-1);m(this,"_highlightShapes",[]);m(this,"_currentHighlightShape",null);m(this,"_query",null);m(this,"_workbookSelections");this._workbook=e,this._sheetSkeletonManagerService=t,this._univerInstanceService=n,this._renderManagerService=i,this._commandService=r,this._contextService=s,this._themeService=o,this._workbookSelections=c.getWorkbookSelections(this.unitId)}get _matchesCount(){return this._matches.length}get unitId(){return this._workbook.getUnitId()}get matchesCount(){return this._matchesCount}get matchesPosition(){return this._matchesPosition}get currentMatch(){return this._matchesPosition>0?this._matches[this._matchesPosition-1]:null}dispose(){super.dispose(),this._disposeHighlights(),this._toggleDisplayRawFormula(!1)}getMatches(){return this._matches}start(e){switch(this._query=e,e.findBy===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}}focusSelection(){const e=this.currentMatch;e&&this._commandService.executeCommand(R.SelectRangeCommand.id,{unitId:e.unitId,subUnit:e.range.subUnitId,range:e.range.range})}_toggleDisplayRawFormula(e){this._contextService.setContextValue(w.RENDER_RAW_FORMULA_KEY,e)}findInWorkbook(e){const t=this._workbook.getUnitId();let n,i=!0;const r=()=>{const s=this._workbook.getSheets().filter(o=>!o.isSheetHidden()).map(o=>{const c=this._findInWorksheet(o,e,t),d=o.getSheetId(),{results:l}=c;return l.length?this._matchesByWorksheet.set(d,c.results):this._matchesByWorksheet.delete(d),c});this._matches=s.map(o=>o.results).flat(),this._updateFindHighlight(),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(a.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(C.filter(([s,o])=>s.id===R.SetWorksheetActiveOperation.id&&!(o!=null&&o.fromFindReplace))).subscribe(()=>{const s=this._workbook.getActiveSheet();if(!s)return;const o=s.getSheetId();this._matchesByWorksheet.has(o)&&this._findNextMatchOnActiveSheetChange(s)})),this.disposeWithMe(a.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(C.filter(([s])=>s.type===a.CommandType.MUTATION&&s.params.unitId===this._workbook.getUnitId()),C.throttleTime(600,void 0,{leading:!1,trailing:!0})).subscribe(()=>r())),r(),n}_findNextMatchOnActiveSheetChange(e){let t,n,i=0;const r=this._matchesByWorksheet.get(e.getSheetId()),s=this._workbookSelections.getCurrentSelections();s!=null&&s.length?([t,i]=this._findNextMatchByRange(r,s[0].range),n=r.findIndex(o=>o===t)):(t=r[0],n=0,i=this._matches.findIndex(o=>o===t)),this._matchesPosition=i+1,this._activelyChangingMatch$.next(t),this._activeHighlightIndex=n,this._updateFindHighlight(),this._updateCurrentHighlightShape(n)}findInActiveWorksheet(e){const t=this._workbook.getUnitId(),n=()=>{var u;const c=this._workbook.getActiveSheet();if(!c)return!1;const d=this._workbookSelections.getCurrentSelections();return(u=d==null?void 0:d.some(g=>!X(g,c)))!=null?u:!1};let i,r=!0,s=!1;const o=()=>{const c=this._workbook.getActiveSheet();if(!c)return{results:[]};const d=this.currentMatch;s=n();const l=this._workbookSelections.getCurrentSelections(),u=s?this._findInSelections(c,l,e,t):this._findInWorksheet(c,e,t);return this._matches=u.results,this._matchesPosition=this._tryRestoreLastMatchesPosition(d,this._matches),r?(i=u,r=!1):this._matchesUpdate$.next(this._matches),this._updateFindHighlight(),u};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>this._updateFindHighlight())),this.disposeWithMe(C.merge(a.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(C.filter(([c])=>{if(c.type===a.CommandType.MUTATION&&c.params.unitId===this._workbook.getUnitId())return!0;if(c.id===R.SetSelectionsOperation.id&&c.params.unitId===t){const d=n();return d===!1&&s===!1?!1:(s=d,!0)}return!1})),this._workbook.activeSheet$.pipe(C.skip(1))).pipe(C.debounceTime(200)).subscribe(()=>o())),o(),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 d of c){const{row:l,col:u,colSpan:g,rowSpan:v,value:I}=d;if(r!=null&&r(l,u)||!I||e.getRowFiltered(l))continue;const{hit:k,replaceable:y,isFormula:b}=ee(e,l,u,t,I);if(k){const W={provider:J,unitId:i,replaceable:y,isFormula:b,range:{subUnitId:o,range:{startRow:l,startColumn:u,endColumn:u+(g!=null?g:1)-1,endRow:l+(v!=null?v:1)-1}}};s.push(W)}}return{results:s}}_findInSelections(e,t,n,i){const{findDirection:r}=n,s=r===f.FindDirection.ROW?E:O,o=new Set;return{results:t.map(d=>this._findInRange(e,n,d.range,i,(l,u)=>{const g=`${l}-${u}`;return o.has(g)?!0:(o.add(g),!1)}).results).flat().sort((d,l)=>s(d.range.range,l.range.range)?-1:1)}}_findInWorksheet(e,t,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 a.ColorKit(s).toRgb(),c=this._workbook.getActiveSheet();if(!c)return;const d=c.getSheetId(),l=r.filter(g=>g.range.subUnitId===d).map((g,v)=>{const{startColumn:I,startRow:k,endColumn:y,endRow:b}=g.range.range,W=M.getCoordByCell(k,I,i,e),ce=M.getCoordByCell(b,y,i,e),{startX:j,startY:$}=W,{endX:ae,endY:le}=ce,L=!c.getRowRawVisible(k),V=!c.getColVisible(I),de=L||V,ue=V?2:ae-j,ge=L?2:le-$,_e={left:j,top:$,color:o,width:ue,height:ge,evented:!1,inHiddenRange:de,zIndex:Z};return new q(`find-highlight-${v}`,_e)});i.addObjects(l),this._highlightShapes=l,i.makeDirty()}_updateCurrentHighlightShape(e){var t;if((t=this._currentHighlightShape)==null||t.setShapeProps({activated:!1}),this._currentHighlightShape=null,e!==void 0){const n=this._highlightShapes[e];if(!n)return;this._currentHighlightShape=n,n.setShapeProps({activated:!0})}}_getSheetObject(){return M.getSheetObject(this._univerInstanceService,this._renderManagerService)}_focusMatch(e){var n;const t=e.range.subUnitId;t!==((n=this._workbook.getActiveSheet())==null?void 0:n.getSheetId())&&this._commandService.executeCommand(R.SetWorksheetActivateCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:t},{fromFindReplace:!0}),this._commandService.executeCommand(M.ScrollToCellCommand.id,{range:e.range.range},{fromFindReplace:!0})}_tryRestoreLastMatchesPosition(e,t){if(!e)return 0;const{subUnitId:n}=e.range,{startColumn:i,startRow:r}=e.range.range,s=t.findIndex(o=>{if(n!==o.range.subUnitId)return!1;const{startColumn:c,startRow:d}=o.range.range;return c===i&&d===r});return s>-1?s+1:0}moveToNextMatch(e){var o,c,d,l,u;if(!this._matches.length)return null;const t=(o=e==null?void 0:e.loop)!=null?o:!1,n=(c=e==null?void 0:e.stayIfOnMatch)!=null?c:!1,i=(d=e==null?void 0:e.noFocus)!=null?d:!1,r=(l=e==null?void 0:e.ignoreSelection)!=null?l:!1,s=this._findNextMatch(t,n,r);if(s){const[g,v]=s;return this._matchesPosition=v+1,this._query.findScope===f.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(g.range.subUnitId).findIndex(I=>I===g):this._activeHighlightIndex=v,i||this._focusMatch(g),((u=this._workbook.getActiveSheet())==null?void 0:u.getSheetId())===g.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),g}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}moveToPreviousMatch(e){var o,c,d,l,u;if(!this._matches.length)return null;const t=(o=e==null?void 0:e.loop)!=null?o:!1,n=(c=e==null?void 0:e.stayIfOnMatch)!=null?c:!1,i=(d=e==null?void 0:e.noFocus)!=null?d:!1,r=(l=e==null?void 0:e.ignoreSelection)!=null?l:!1,s=this._findPreviousMatch(t,n,r);if(s){const[g,v]=s;return this._matchesPosition=v+1,this._query.findScope===f.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(g.range.subUnitId).findIndex(I=>I===g):this._activeHighlightIndex=v,i||this._focusMatch(g),((u=this._workbook.getActiveSheet())==null?void 0:u.getSheetId())===g.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),g}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}_findPreviousMatch(e=!1,t=!1,n=!1){var o;if(this.currentMatch){const c=this._matches.findIndex(g=>g===this.currentMatch);if(t)return[this.currentMatch,c];const d=c-1;if(!e&&d<0)return null;const l=this._matches.length,u=(d+l)%l;return[this._matches[u],u]}const i=this._workbookSelections.getCurrentLastSelection();if(n||!i){const c=this._matches.length-1;return[this._matches[c],c]}if(this._query.findScope!==f.FindScope.UNIT)return this._findPreviousMatchByRange(this._matches,i.range);const r=(o=this._workbook.getActiveSheet())==null?void 0:o.getSheetId();if(!r)return null;const s=this._findPreviousWorksheetThatHasAMatch(r,e);return s?this._findPreviousMatchByRange(this._matchesByWorksheet.get(s),i.range):null}_findNextMatch(e=!1,t=!1,n=!1){var o;if(this.currentMatch){const c=this._matches.findIndex(g=>g===this.currentMatch);if(t)return[this.currentMatch,c];const d=c+1,l=this._matches.length;if(!e&&d>=l)return null;const u=d%l;return[this._matches[u],u]}const i=this._workbookSelections.getCurrentLastSelection();if(n||!i)return[this._matches[0],0];if(this._query.findScope!==f.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?a.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?a.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?E(t,c):O(t,c)))return!1;const l=H(t,c);return n?l:!l});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?K(t,c):Q(t,c)))return!1;const l=H(t,c);return n?l:!l});r===-1&&(r=0);const s=e[r];return[s,this._matches.findIndex(o=>o===s)]}async replace(e){if(this._matchesCount===0||!this.currentMatch||!this._query||!this.currentMatch.replaceable)return!1;const t=this.currentMatch.range,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(R.SetRangeValuesCommand.id,r)}async replaceAll(e){if(this._matchesCount===0||!this._query)return{success:0,failure:0};const t=this._workbook.getUnitId(),{findString:n,caseSensitive:i,findBy:r}=this._query,s=r===f.FindBy.FORMULA,o=i?"g":"ig",c=[];return a.groupBy(this._matches.filter(l=>l.replaceable),l=>l.range.subUnitId).forEach((l,u)=>{const g=new a.ObjectMatrix,v=this._workbook.getSheetBySheetId(u);l.forEach(I=>{const{startColumn:k,startRow:y}=I.range.range,b=this._getReplacedCellData(I,v,s,n,e,o);b&&g.setValue(y,k,b)}),c.push({count:l.length,subUnitId:u,value:g.getMatrix()})}),c?this._commandService.executeCommand(F.id,{unitId:t,replacements:c}):{success:0,failure:0}}_getReplacedCellData(e,t,n,i,r,s){var v;const o=e.range.range,{startRow:c,startColumn:d}=o,l=t.getCellRaw(c,d);if(e.isFormula)return n?{f:l.f.replace(new RegExp(A(i),s),r),v:null}:null;if(!!((v=l.p)!=null&&v.body)){const I=a.Tools.deepClone(l.p);return a.replaceInDocumentBody(I.body,i,r,this._query.caseSensitive),{p:I}}return{v:l.v.toString().replace(new RegExp(A(i),s),r)}}};x=U([p(2,a.IUniverInstanceService),p(3,w.IRenderManagerService),p(4,a.ICommandService),p(5,a.IContextService),p(6,a.Inject(a.ThemeService)),p(7,a.Inject(R.SheetsSelectionsService))],x);function A(h){return h.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}let P=class extends a.Disposable{constructor(e,t,n){super();m(this,"_findModelsByUnitId",new Map);this._univerInstanceService=e,this._renderManagerService=t,this._injector=n}async find(e){this._terminate();const t=this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET),n=this._preprocessQuery(e);return t.map(r=>{const s=this._renderManagerService.getRenderById(r.getUnitId()).with(M.SheetSkeletonManagerService),o=this._injector.createInstance(x,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=U([p(0,a.IUniverInstanceService),p(1,w.IRenderManagerService),p(2,a.Inject(a.Injector))],P);const S={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 S.rawData=o,!(o!=null&&o.f)?(S.isFormula=!1,B(i,n)?o?(S.hit=!0,S.replaceable=!0):(S.hit=!0,S.replaceable=!1):(S.hit=!1,S.replaceable=!1),S):(S.isFormula=!0,s?B({v:o.f},n)?(S.hit=!0,S.replaceable=!0,S):(S.hit=!1,S.replaceable=!1,S):(S.replaceable=!1,B(i,n)?S.hit=!0:S.hit=!1,S))}function B(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 ie=Object.defineProperty,se=Object.getOwnPropertyDescriptor,re=(h,e,t)=>e in h?ie(h,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):h[e]=t,oe=(h,e,t,n)=>{for(var i=n>1?void 0:n?se(e,t):e,r=h.length-1,s;r>=0;r--)(s=h[r])&&(i=s(i)||i);return i},D=(h,e)=>(t,n)=>e(t,n,h),N=(h,e,t)=>re(h,typeof e!="symbol"?e+"":e,t);const he="SHEET_FIND_REPLACE_PLUGIN";_.UniverSheetsFindReplacePlugin=class extends a.Plugin{constructor(e=T,t,n){super(),this._config=e,this._injector=t,this._configService=n;const{...i}=a.merge({},T,this._config);this._configService.setConfig(G,i)}onStarting(){[[_.SheetsFindReplaceController]].forEach(e=>this._injector.add(e))}onSteady(){this._injector.get(_.SheetsFindReplaceController)}},N(_.UniverSheetsFindReplacePlugin,"pluginName",he),N(_.UniverSheetsFindReplacePlugin,"type",a.UniverInstanceType.UNIVER_SHEET),_.UniverSheetsFindReplacePlugin=oe([a.DependentOn(R.UniverSheetsPlugin,R.UniverSheetsPlugin,f.UniverFindReplacePlugin),D(1,a.Inject(a.Injector)),D(2,a.IConfigService)],_.UniverSheetsFindReplacePlugin),_.SheetReplaceCommand=F,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"})});
1
+ (function(_,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/find-replace"),require("@univerjs/sheets"),require("@univerjs/engine-render"),require("@univerjs/sheets-ui"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/find-replace","@univerjs/sheets","@univerjs/engine-render","@univerjs/sheets-ui","rxjs"],a):(_=typeof globalThis<"u"?globalThis:_||self,a(_.UniverSheetsFindReplace={},_.UniverCore,_.UniverFindReplace,_.UniverSheets,_.UniverEngineRender,_.UniverSheetsUi,_.rxjs))})(this,function(_,a,f,R,w,M,C){"use strict";var fe=Object.defineProperty;var Se=(_,a,f)=>a in _?fe(_,a,{enumerable:!0,configurable:!0,writable:!0,value:f}):_[a]=f;var m=(_,a,f)=>Se(_,typeof a!="symbol"?a+"":a,f);const G="sheets-find-replace.config",T={},F={id:"sheet.command.replace",type:a.CommandType.COMMAND,handler:async(h,e)=>{const t=h.get(a.IUndoRedoService),i=h.get(a.ICommandService),{unitId:n,replacements:r}=e,s=t.__tempBatchingUndoRedo(n),o=await Promise.all(r.map(c=>i.executeCommand(R.SetRangeValuesCommand.id,{unitId:n,subUnitId:c.subUnitId,value:c.value})));return s.dispose(),Y(o,r)}};function Y(h,e){let t=0,i=0;return h.forEach((n,r)=>{const s=e[r].count;n?t+=s:i+=s}),{success:t,failure:i}}class q extends w.Shape{constructor(t,i){super(t,i);m(this,"_activated",!1);m(this,"_inHiddenRange",!1);m(this,"_color");i&&this.setShapeProps(i)}setShapeProps(t){this._activated=!!t.activated,typeof t.inHiddenRange<"u"&&(this._inHiddenRange=t.inHiddenRange),typeof t.color<"u"&&(this._color=t.color),this.transformByState({width:t.width,height:t.height})}_draw(t){const i=this._activated,n=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 0.35)`,r=`rgb(${this._color.r}, ${this._color.g}, ${this._color.b})`;w.Rect.drawWith(t,{width:this.width,height:this.height,fill:n,stroke:i?r:void 0,strokeWidth:i?2:0,evented:!1})}}function H(h,e){return h.startRow===e.startRow&&h.startColumn===e.startColumn}function E(h,e){return h.startRow<e.startRow||h.startRow===e.startRow&&h.startColumn<=e.startColumn}function O(h,e){return h.startColumn<e.startColumn||h.startColumn===e.startColumn&&h.startRow<=e.startRow}function K(h,e){return h.startRow>e.startRow||h.startRow===e.startRow&&h.startColumn>=e.startColumn}function Q(h,e){return h.startColumn>e.startColumn||h.startColumn===e.startColumn&&h.startRow>=e.startRow}function X(h,e){const{range:t}=h,{startRow:i,startColumn:n}=t,r=e.getMergedCell(i,n);return r?a.Rectangle.equals(t,r):t.endRow===t.startRow&&t.endColumn===t.startColumn}var z=Object.getOwnPropertyDescriptor,U=(h,e,t,i)=>{for(var n=i>1?void 0:i?z(e,t):e,r=h.length-1,s;r>=0;r--)(s=h[r])&&(n=s(n)||n);return n},p=(h,e)=>(t,i)=>e(t,i,h);_.SheetsFindReplaceController=class extends a.Disposable{constructor(t,i,n,r,s){super();m(this,"_provider");this._injector=t,this._findReplaceController=i,this._contextService=n,this._findReplaceService=r,this._commandService=s,this._init(),this._initCommands()}dispose(){super.dispose(),this._findReplaceController.closePanel(),this._provider.dispose()}_init(){const t=this._injector.createInstance(P);this._provider=t,this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(t)),this.disposeWithMe(this._contextService.subscribeContextValue$(a.EDITOR_ACTIVATED).pipe(C.filter(i=>!!i)).subscribe(()=>this._findReplaceController.closePanel()))}_initCommands(){[F].forEach(t=>this.disposeWithMe(this._commandService.registerCommand(t)))}},_.SheetsFindReplaceController=U([p(0,a.Inject(a.Injector)),p(1,a.Inject(f.FindReplaceController)),p(2,a.IContextService),p(3,f.IFindReplaceService),p(4,a.ICommandService)],_.SheetsFindReplaceController);const J="sheets-find-replace-provider",Z=1e4;let x=class extends f.FindModel{constructor(e,t,i,n,r,s,o,c){super();m(this,"_matchesUpdate$",new C.Subject);m(this,"matchesUpdate$",this._matchesUpdate$.asObservable());m(this,"_activelyChangingMatch$",new C.Subject);m(this,"activelyChangingMatch$",this._activelyChangingMatch$.asObservable());m(this,"_matchesByWorksheet",new Map);m(this,"_matches",[]);m(this,"_matchesPosition",0);m(this,"_activeHighlightIndex",-1);m(this,"_highlightShapes",[]);m(this,"_currentHighlightShape",null);m(this,"_query",null);m(this,"_workbookSelections");this._workbook=e,this._sheetSkeletonManagerService=t,this._univerInstanceService=i,this._renderManagerService=n,this._commandService=r,this._contextService=s,this._themeService=o,this._workbookSelections=c.getWorkbookSelections(this.unitId)}get _matchesCount(){return this._matches.length}get unitId(){return this._workbook.getUnitId()}get matchesCount(){return this._matchesCount}get matchesPosition(){return this._matchesPosition}get currentMatch(){return this._matchesPosition>0?this._matches[this._matchesPosition-1]:null}dispose(){super.dispose(),this._disposeHighlights(),this._toggleDisplayRawFormula(!1)}getMatches(){return this._matches}start(e){switch(this._query=e,e.findBy===f.FindBy.FORMULA?this._toggleDisplayRawFormula(!0):this._toggleDisplayRawFormula(!1),e.findScope){case f.FindScope.UNIT:this.findInWorkbook(e);break;case f.FindScope.SUBUNIT:default:this.findInActiveWorksheet(e);break}}focusSelection(){const e=this.currentMatch;e&&this._commandService.executeCommand(R.SelectRangeCommand.id,{unitId:e.unitId,subUnit:e.range.subUnitId,range:e.range.range})}_toggleDisplayRawFormula(e){this._contextService.setContextValue(w.RENDER_RAW_FORMULA_KEY,e)}findInWorkbook(e){const t=this._workbook.getUnitId();let i,n=!0;const r=()=>{const s=this._workbook.getSheets().filter(o=>!o.isSheetHidden()).map(o=>{const c=this._findInWorksheet(o,e,t),d=o.getSheetId(),{results:l}=c;return l.length?this._matchesByWorksheet.set(d,c.results):this._matchesByWorksheet.delete(d),c});this._matches=s.map(o=>o.results).flat(),this._updateFindHighlight(),n?(i={results:this._matches},n=!1):this._matchesUpdate$.next(this._matches)};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>{this._updateFindHighlight(),this._updateCurrentHighlightShape(this._activeHighlightIndex)})),this.disposeWithMe(a.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(C.filter(([s,o])=>s.id===R.SetWorksheetActiveOperation.id&&!(o!=null&&o.fromFindReplace))).subscribe(()=>{const s=this._workbook.getActiveSheet();if(!s)return;const o=s.getSheetId();this._matchesByWorksheet.has(o)&&this._findNextMatchOnActiveSheetChange(s)})),this.disposeWithMe(a.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(C.filter(([s])=>s.type===a.CommandType.MUTATION&&s.params.unitId===this._workbook.getUnitId()),C.throttleTime(600,void 0,{leading:!1,trailing:!0})).subscribe(()=>r())),r(),i}_findNextMatchOnActiveSheetChange(e){let t,i,n=0;const r=this._matchesByWorksheet.get(e.getSheetId()),s=this._workbookSelections.getCurrentSelections();s!=null&&s.length?([t,n]=this._findNextMatchByRange(r,s[0].range),i=r.findIndex(o=>o===t)):(t=r[0],i=0,n=this._matches.findIndex(o=>o===t)),this._matchesPosition=n+1,this._activelyChangingMatch$.next(t),this._activeHighlightIndex=i,this._updateFindHighlight(),this._updateCurrentHighlightShape(i)}findInActiveWorksheet(e){const t=this._workbook.getUnitId(),i=()=>{var u;const c=this._workbook.getActiveSheet();if(!c)return!1;const d=this._workbookSelections.getCurrentSelections();return(u=d==null?void 0:d.some(g=>!X(g,c)))!=null?u:!1};let n,r=!0,s=!1;const o=()=>{const c=this._workbook.getActiveSheet();if(!c)return{results:[]};const d=this.currentMatch;s=i();const l=this._workbookSelections.getCurrentSelections(),u=s?this._findInSelections(c,l,e,t):this._findInWorksheet(c,e,t);return this._matches=u.results,this._matchesPosition=this._tryRestoreLastMatchesPosition(d,this._matches),r?(n=u,r=!1):this._matchesUpdate$.next(this._matches),this._updateFindHighlight(),u};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>this._updateFindHighlight())),this.disposeWithMe(C.merge(a.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(C.filter(([c])=>{if(c.type===a.CommandType.MUTATION&&c.params.unitId===this._workbook.getUnitId())return!0;if(c.id===R.SetSelectionsOperation.id&&c.params.unitId===t){const d=i();return d===!1&&s===!1?!1:(s=d,!0)}return!1})),this._workbook.activeSheet$.pipe(C.skip(1))).pipe(C.debounceTime(200)).subscribe(()=>o())),o(),n}_findInRange(e,t,i,n,r){const s=[],o=e.getSheetId(),c=(t.findDirection===f.FindDirection.COLUMN?e.iterateByColumn:e.iterateByRow).bind(e)(i);for(const d of c){const{row:l,col:u,colSpan:g,rowSpan:v,value:I}=d;if(r!=null&&r(l,u)||!I||e.getRowFiltered(l))continue;const{hit:k,replaceable:y,isFormula:b}=ee(e,l,u,t,I);if(k){const W={provider:J,unitId:n,replaceable:y,isFormula:b,range:{subUnitId:o,range:{startRow:l,startColumn:u,endColumn:u+(g!=null?g:1)-1,endRow:l+(v!=null?v:1)-1}}};s.push(W)}}return{results:s}}_findInSelections(e,t,i,n){const{findDirection:r}=i,s=r===f.FindDirection.ROW?E:O,o=new Set;return{results:t.map(d=>this._findInRange(e,i,d.range,n,(l,u)=>{const g=`${l}-${u}`;return o.has(g)?!0:(o.add(g),!1)}).results).flat().sort((d,l)=>s(d.range.range,l.range.range)?-1:1)}}_findInWorksheet(e,t,i){const n=e.getRowCount(),r=e.getColumnCount(),s={startRow:0,startColumn:0,endRow:n-1,endColumn:r-1};return this._findInRange(e,t,s,i)}_disposeHighlights(){var e;this._highlightShapes.forEach(t=>{var i;(i=t.getScene())==null||i.makeDirty(),t.dispose()}),this._highlightShapes=[],(e=this._currentHighlightShape)==null||e.dispose(),this._currentHighlightShape=null}_updateFindHighlight(){var u;this._disposeHighlights();const e=(u=this._sheetSkeletonManagerService.getCurrent())==null?void 0:u.skeleton;if(!e)return;const t=this._workbook.getUnitId(),i=this._renderManagerService.getRenderById(t);if(i==null)return;const{scene:n}=i,r=this._matches,s=this._themeService.getColorFromTheme("yellow.400"),o=new a.ColorKit(s).toRgb(),c=this._workbook.getActiveSheet();if(!c)return;const d=c.getSheetId(),l=r.filter(g=>g.range.subUnitId===d).map((g,v)=>{const{startColumn:I,startRow:k,endColumn:y,endRow:b}=g.range.range,W=M.getCoordByCell(k,I,n,e),ce=M.getCoordByCell(b,y,n,e),{startX:j,startY:$}=W,{endX:ae,endY:le}=ce,L=!c.getRowRawVisible(k),V=!c.getColVisible(I),de=L||V,ue=V?2:ae-j,ge=L?2:le-$,_e={left:j,top:$,color:o,width:ue,height:ge,evented:!1,inHiddenRange:de,zIndex:Z};return new q(`find-highlight-${v}`,_e)});n.addObjects(l),this._highlightShapes=l,n.makeDirty()}_updateCurrentHighlightShape(e){var t;if((t=this._currentHighlightShape)==null||t.setShapeProps({activated:!1}),this._currentHighlightShape=null,e!==void 0){const i=this._highlightShapes[e];if(!i)return;this._currentHighlightShape=i,i.setShapeProps({activated:!0})}}_getSheetObject(){return M.getSheetObject(this._univerInstanceService,this._renderManagerService)}_focusMatch(e){var i;const t=e.range.subUnitId;t!==((i=this._workbook.getActiveSheet())==null?void 0:i.getSheetId())&&this._commandService.executeCommand(R.SetWorksheetActivateCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:t},{fromFindReplace:!0}),this._commandService.executeCommand(M.ScrollToCellCommand.id,{range:e.range.range},{fromFindReplace:!0})}_tryRestoreLastMatchesPosition(e,t){if(!e)return 0;const{subUnitId:i}=e.range,{startColumn:n,startRow:r}=e.range.range,s=t.findIndex(o=>{if(i!==o.range.subUnitId)return!1;const{startColumn:c,startRow:d}=o.range.range;return c===n&&d===r});return s>-1?s+1:0}moveToNextMatch(e){var o,c,d,l,u;if(!this._matches.length)return null;const t=(o=e==null?void 0:e.loop)!=null?o:!1,i=(c=e==null?void 0:e.stayIfOnMatch)!=null?c:!1,n=(d=e==null?void 0:e.noFocus)!=null?d:!1,r=(l=e==null?void 0:e.ignoreSelection)!=null?l:!1,s=this._findNextMatch(t,i,r);if(s){const[g,v]=s;return this._matchesPosition=v+1,this._query.findScope===f.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(g.range.subUnitId).findIndex(I=>I===g):this._activeHighlightIndex=v,n||this._focusMatch(g),((u=this._workbook.getActiveSheet())==null?void 0:u.getSheetId())===g.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),g}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}moveToPreviousMatch(e){var o,c,d,l,u;if(!this._matches.length)return null;const t=(o=e==null?void 0:e.loop)!=null?o:!1,i=(c=e==null?void 0:e.stayIfOnMatch)!=null?c:!1,n=(d=e==null?void 0:e.noFocus)!=null?d:!1,r=(l=e==null?void 0:e.ignoreSelection)!=null?l:!1,s=this._findPreviousMatch(t,i,r);if(s){const[g,v]=s;return this._matchesPosition=v+1,this._query.findScope===f.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(g.range.subUnitId).findIndex(I=>I===g):this._activeHighlightIndex=v,n||this._focusMatch(g),((u=this._workbook.getActiveSheet())==null?void 0:u.getSheetId())===g.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),g}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}_findPreviousMatch(e=!1,t=!1,i=!1){var o;if(this.currentMatch){const c=this._matches.findIndex(g=>g===this.currentMatch);if(t)return[this.currentMatch,c];const d=c-1;if(!e&&d<0)return null;const l=this._matches.length,u=(d+l)%l;return[this._matches[u],u]}const n=this._workbookSelections.getCurrentLastSelection();if(i||!n){const c=this._matches.length-1;return[this._matches[c],c]}if(this._query.findScope!==f.FindScope.UNIT)return this._findPreviousMatchByRange(this._matches,n.range);const r=(o=this._workbook.getActiveSheet())==null?void 0:o.getSheetId();if(!r)return null;const s=this._findPreviousWorksheetThatHasAMatch(r,e);return s?this._findPreviousMatchByRange(this._matchesByWorksheet.get(s),n.range):null}_findNextMatch(e=!1,t=!1,i=!1){var o;if(this.currentMatch){const c=this._matches.findIndex(g=>g===this.currentMatch);if(t)return[this.currentMatch,c];const d=c+1,l=this._matches.length;if(!e&&d>=l)return null;const u=d%l;return[this._matches[u],u]}const n=this._workbookSelections.getCurrentLastSelection();if(i||!n)return[this._matches[0],0];if(this._query.findScope!==f.FindScope.UNIT)return this._findNextMatchByRange(this._matches,n.range,t);const r=(o=this._workbook.getActiveSheet())==null?void 0:o.getSheetId();if(!r)return null;const s=this._findNextWorksheetThatHasAMatch(r,e);return s?this._findNextMatchByRange(this._matchesByWorksheet.get(s),n.range):null}_findPreviousWorksheetThatHasAMatch(e,t=!1){const i=this._workbook.getSheetOrders(),n=i.findIndex(o=>o===e),s=(t?a.rotate(i,n+1):i.slice(0,n+1)).findLast(o=>this._matchesByWorksheet.has(o));return s!=null?s:null}_findNextWorksheetThatHasAMatch(e,t=!1){const i=this._workbook.getSheetOrders(),n=i.findIndex(o=>o===e),s=(t?a.rotate(i,n):i.slice(n)).find(o=>this._matchesByWorksheet.has(o));return s!=null?s:null}_findNextMatchByRange(e,t,i=!1){const n=this._query.findDirection===f.FindDirection.ROW;let r=e.findIndex(o=>{const c=o.range.range;if(!(n?E(t,c):O(t,c)))return!1;const l=H(t,c);return i?l:!l});r===-1&&(r=e.length-1);const s=e[r];return[s,this._matches.findIndex(o=>o===s)]}_findPreviousMatchByRange(e,t,i=!1){const n=this._query.findDirection===f.FindDirection.ROW;let r=this._matches.findLastIndex(o=>{const c=o.range.range;if(!(n?K(t,c):Q(t,c)))return!1;const l=H(t,c);return i?l:!l});r===-1&&(r=0);const s=e[r];return[s,this._matches.findIndex(o=>o===s)]}async replace(e){if(this._matchesCount===0||!this.currentMatch||!this._query||!this.currentMatch.replaceable)return!1;const t=this.currentMatch.range,i=this._workbook.getSheetBySheetId(this.currentMatch.range.subUnitId),n=this._getReplacedCellData(this.currentMatch,i,this._query.findBy===f.FindBy.FORMULA,this._query.findString,e,this._query.caseSensitive?"g":"ig"),r={unitId:this.currentMatch.unitId,subUnitId:t.subUnitId,value:{[t.range.startRow]:{[t.range.startColumn]:n}}};return this._commandService.executeCommand(R.SetRangeValuesCommand.id,r)}async replaceAll(e){if(this._matchesCount===0||!this._query)return{success:0,failure:0};const t=this._workbook.getUnitId(),{findString:i,caseSensitive:n,findBy:r}=this._query,s=r===f.FindBy.FORMULA,o=n?"g":"ig",c=[];return a.groupBy(this._matches.filter(l=>l.replaceable),l=>l.range.subUnitId).forEach((l,u)=>{const g=new a.ObjectMatrix,v=this._workbook.getSheetBySheetId(u);l.forEach(I=>{const{startColumn:k,startRow:y}=I.range.range,b=this._getReplacedCellData(I,v,s,i,e,o);b&&g.setValue(y,k,b)}),c.push({count:l.length,subUnitId:u,value:g.getMatrix()})}),c?this._commandService.executeCommand(F.id,{unitId:t,replacements:c}):{success:0,failure:0}}_getReplacedCellData(e,t,i,n,r,s){var v;const o=e.range.range,{startRow:c,startColumn:d}=o,l=t.getCellRaw(c,d);if(e.isFormula)return i?{f:l.f.replace(new RegExp(A(n),s),r),v:null}:null;if(!!((v=l.p)!=null&&v.body)){const I=a.Tools.deepClone(l.p);return a.replaceInDocumentBody(I.body,n,r,this._query.caseSensitive),{p:I}}return{v:l.v.toString().replace(new RegExp(A(n),s),r)}}};x=U([p(2,a.IUniverInstanceService),p(3,w.IRenderManagerService),p(4,a.ICommandService),p(5,a.IContextService),p(6,a.Inject(a.ThemeService)),p(7,a.Inject(R.SheetsSelectionsService))],x);function A(h){return h.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}let P=class extends a.Disposable{constructor(e,t,i){super();m(this,"_findModelsByUnitId",new Map);this._univerInstanceService=e,this._renderManagerService=t,this._injector=i}async find(e){this._terminate();const t=this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET),i=this._preprocessQuery(e);return t.map(r=>{const s=this._renderManagerService.getRenderById(r.getUnitId()).with(M.SheetSkeletonManagerService),o=this._injector.createInstance(x,r,s);return this._findModelsByUnitId.set(r.getUnitId(),o),o.start(i),o})}terminate(){this._terminate()}_terminate(){this._findModelsByUnitId.forEach(e=>e.dispose()),this._findModelsByUnitId.clear()}_preprocessQuery(e){let t=e.caseSensitive?e.findString:e.findString.toLowerCase();return t=t.trim(),{...e,findString:t}}};P=U([p(0,a.IUniverInstanceService),p(1,w.IRenderManagerService),p(2,a.Inject(a.Injector))],P);const S={hit:!1,replaceable:!1,isFormula:!1,rawData:null};function ee(h,e,t,i,n){const{findBy:r}=i,s=r===f.FindBy.FORMULA,o=h.getCellRaw(e,t);return S.rawData=o,!(o!=null&&o.f)?(S.isFormula=!1,B(n,i)?o?(S.hit=!0,S.replaceable=!0):(S.hit=!0,S.replaceable=!1):(S.hit=!1,S.replaceable=!1),S):(S.isFormula=!0,s?B({v:o.f},i)?(S.hit=!0,S.replaceable=!0,S):(S.hit=!1,S.replaceable=!1,S):(S.replaceable=!1,B(n,i)?S.hit=!0:S.hit=!1,S))}function B(h,e){let t=te(h);return t?e.matchesTheWholeCell?(t=ie(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,i,n;const e=(n=(i=(t=h==null?void 0:h.p)==null?void 0:t.body)==null?void 0:i.dataStream)!=null?n:h==null?void 0:h.v;return typeof e=="number"?`${e}`:typeof e=="boolean"?e?"1":"0":e}function ie(h){return h.replace(/^ +/g,"").replace(/ +$/g,"")}var ne=Object.defineProperty,se=Object.getOwnPropertyDescriptor,re=(h,e,t)=>e in h?ne(h,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):h[e]=t,oe=(h,e,t,i)=>{for(var n=i>1?void 0:i?se(e,t):e,r=h.length-1,s;r>=0;r--)(s=h[r])&&(n=s(n)||n);return n},D=(h,e)=>(t,i)=>e(t,i,h),N=(h,e,t)=>re(h,typeof e!="symbol"?e+"":e,t);const he="SHEET_FIND_REPLACE_PLUGIN";_.UniverSheetsFindReplacePlugin=class extends a.Plugin{constructor(e=T,t,i){super(),this._config=e,this._injector=t,this._configService=i;const{...n}=a.merge({},T,this._config);this._configService.setConfig(G,n)}onStarting(){[[_.SheetsFindReplaceController]].forEach(e=>this._injector.add(e))}onSteady(){this._injector.get(_.SheetsFindReplaceController)}},N(_.UniverSheetsFindReplacePlugin,"pluginName",he),N(_.UniverSheetsFindReplacePlugin,"type",a.UniverInstanceType.UNIVER_SHEET),_.UniverSheetsFindReplacePlugin=oe([a.DependentOn(R.UniverSheetsPlugin,R.UniverSheetsPlugin,f.UniverFindReplacePlugin),D(1,a.Inject(a.Injector)),D(2,a.IConfigService)],_.UniverSheetsFindReplacePlugin),_.SheetReplaceCommand=F,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-find-replace",
3
- "version": "0.6.10",
3
+ "version": "0.7.0-beta.1",
4
4
  "private": false,
5
5
  "description": "UniverSheet find replace plugin",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -63,18 +63,18 @@
63
63
  "rxjs": ">=7.0.0"
64
64
  },
65
65
  "dependencies": {
66
- "@univerjs/core": "0.6.10",
67
- "@univerjs/engine-render": "0.6.10",
68
- "@univerjs/find-replace": "0.6.10",
69
- "@univerjs/sheets-ui": "0.6.10",
70
- "@univerjs/sheets": "0.6.10"
66
+ "@univerjs/core": "0.7.0-beta.1",
67
+ "@univerjs/find-replace": "0.7.0-beta.1",
68
+ "@univerjs/sheets": "0.7.0-beta.1",
69
+ "@univerjs/sheets-ui": "0.7.0-beta.1",
70
+ "@univerjs/engine-render": "0.7.0-beta.1"
71
71
  },
72
72
  "devDependencies": {
73
73
  "rxjs": "^7.8.1",
74
74
  "typescript": "^5.8.3",
75
- "vite": "^6.3.0",
76
- "vitest": "^3.1.1",
77
- "@univerjs-infra/shared": "0.6.10"
75
+ "vite": "^6.3.5",
76
+ "vitest": "^3.1.3",
77
+ "@univerjs-infra/shared": "0.7.0-beta.1"
78
78
  },
79
79
  "scripts": {
80
80
  "test": "vitest run",