@univerjs/sheets-find-replace 0.20.1 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/lib/cjs/facade.js +204 -1
  2. package/lib/cjs/index.js +936 -1
  3. package/lib/cjs/locale/ca-ES.js +9 -1
  4. package/lib/cjs/locale/en-US.js +24 -1
  5. package/lib/cjs/locale/es-ES.js +9 -1
  6. package/lib/cjs/locale/fa-IR.js +9 -1
  7. package/lib/cjs/locale/fr-FR.js +9 -1
  8. package/lib/cjs/locale/ja-JP.js +9 -1
  9. package/lib/cjs/locale/ko-KR.js +9 -1
  10. package/lib/cjs/locale/ru-RU.js +9 -1
  11. package/lib/cjs/locale/sk-SK.js +9 -1
  12. package/lib/cjs/locale/vi-VN.js +9 -1
  13. package/lib/cjs/locale/zh-CN.js +24 -1
  14. package/lib/cjs/locale/zh-TW.js +9 -1
  15. package/lib/es/facade.js +205 -1
  16. package/lib/es/index.js +923 -1
  17. package/lib/es/locale/ca-ES.js +8 -1
  18. package/lib/es/locale/en-US.js +23 -1
  19. package/lib/es/locale/es-ES.js +8 -1
  20. package/lib/es/locale/fa-IR.js +8 -1
  21. package/lib/es/locale/fr-FR.js +8 -1
  22. package/lib/es/locale/ja-JP.js +8 -1
  23. package/lib/es/locale/ko-KR.js +8 -1
  24. package/lib/es/locale/ru-RU.js +8 -1
  25. package/lib/es/locale/sk-SK.js +8 -1
  26. package/lib/es/locale/vi-VN.js +8 -1
  27. package/lib/es/locale/zh-CN.js +23 -1
  28. package/lib/es/locale/zh-TW.js +8 -1
  29. package/lib/facade.js +205 -1
  30. package/lib/index.js +923 -1
  31. package/lib/locale/ca-ES.js +8 -1
  32. package/lib/locale/en-US.js +23 -1
  33. package/lib/locale/es-ES.js +8 -1
  34. package/lib/locale/fa-IR.js +8 -1
  35. package/lib/locale/fr-FR.js +8 -1
  36. package/lib/locale/ja-JP.js +8 -1
  37. package/lib/locale/ko-KR.js +8 -1
  38. package/lib/locale/ru-RU.js +8 -1
  39. package/lib/locale/sk-SK.js +8 -1
  40. package/lib/locale/vi-VN.js +8 -1
  41. package/lib/locale/zh-CN.js +23 -1
  42. package/lib/locale/zh-TW.js +8 -1
  43. package/lib/umd/index.js +1 -1
  44. package/package.json +8 -8
package/lib/cjs/index.js CHANGED
@@ -1 +1,936 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/core`),t=require(`@univerjs/sheets`),n=require(`@univerjs/engine-render`),r=require(`@univerjs/find-replace`),i=require(`@univerjs/sheets-ui`),a=require(`rxjs`);const o={id:`sheet.command.replace`,type:e.CommandType.COMMAND,handler:async(n,r)=>{let i=n.get(e.IUndoRedoService),a=n.get(e.ICommandService),{unitId:o,replacements:c}=r,l=i.__tempBatchingUndoRedo(o),u=await Promise.all(c.map(e=>a.executeCommand(t.SetRangeValuesCommand.id,{unitId:o,subUnitId:e.subUnitId,value:e.value})));return l.dispose(),s(u,c)}};function s(e,t){let n=0,r=0;return e.forEach((e,i)=>{let a=t[i].count;e?n+=a:r+=a}),{success:n,failure:r}}function c(e){"@babel/helpers - typeof";return c=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},c(e)}function l(e,t){if(c(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(c(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function u(e){var t=l(e,`string`);return c(t)==`symbol`?t:t+``}function d(e,t,n){return(t=u(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var f=class extends n.Shape{constructor(e,t){super(e,t),d(this,`_activated`,!1),d(this,`_inHiddenRange`,!1),d(this,`_color`,void 0),t&&this.setShapeProps(t)}setShapeProps(e){this._activated=!!e.activated,e.inHiddenRange!==void 0&&(this._inHiddenRange=e.inHiddenRange),e.color!==void 0&&(this._color=e.color),this.transformByState({width:e.width,height:e.height})}_draw(e){let t=this._activated,r=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 0.35)`,i=`rgb(${this._color.r}, ${this._color.g}, ${this._color.b})`;n.Rect.drawWith(e,{width:this.width,height:this.height,fill:r,stroke:t?i:void 0,strokeWidth:t?2:0,evented:!1})}};function p(e,t){return e.startRow===t.startRow&&e.startColumn===t.startColumn}function m(e,t){return e.startRow<t.startRow||e.startRow===t.startRow&&e.startColumn<=t.startColumn}function h(e,t){return e.startColumn<t.startColumn||e.startColumn===t.startColumn&&e.startRow<=t.startRow}function g(e,t){return e.startRow>t.startRow||e.startRow===t.startRow&&e.startColumn>=t.startColumn}function _(e,t){return e.startColumn>t.startColumn||e.startColumn===t.startColumn&&e.startRow>=t.startRow}function v(t,n){let{range:r}=t,{startRow:i,startColumn:a}=r,o=n.getMergedCell(i,a);return o?e.Rectangle.equals(r,o):r.endRow===r.startRow&&r.endColumn===r.startColumn}function y(e,t){return function(n,r){t(n,r,e)}}function b(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let x=class extends e.Disposable{constructor(e,t,n,r,i){super(),this._injector=e,this._findReplaceController=t,this._contextService=n,this._findReplaceService=r,this._commandService=i,d(this,`_provider`,void 0),this._init(),this._initCommands()}dispose(){super.dispose(),this._findReplaceController.closePanel(),this._provider.dispose()}_init(){let t=this._injector.createInstance(w);this._provider=t,this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(t)),this.disposeWithMe(this._contextService.subscribeContextValue$(e.EDITOR_ACTIVATED).pipe((0,a.filter)(e=>!!e)).subscribe(()=>this._findReplaceController.closePanel()))}_initCommands(){[o].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}};x=b([y(0,(0,e.Inject)(e.Injector)),y(1,(0,e.Inject)(r.FindReplaceController)),y(2,e.IContextService),y(3,r.IFindReplaceService),y(4,e.ICommandService)],x);let S=class extends r.FindModel{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}constructor(e,t,n,r,i,o,s,c){super(),this._workbook=e,this._sheetSkeletonManagerService=t,this._univerInstanceService=n,this._renderManagerService=r,this._commandService=i,this._contextService=o,this._themeService=s,d(this,`_matchesUpdate$`,new a.Subject),d(this,`matchesUpdate$`,this._matchesUpdate$.asObservable()),d(this,`_activelyChangingMatch$`,new a.Subject),d(this,`activelyChangingMatch$`,this._activelyChangingMatch$.asObservable()),d(this,`_matchesByWorksheet`,new Map),d(this,`_matches`,[]),d(this,`_matchesPosition`,0),d(this,`_activeHighlightIndex`,-1),d(this,`_highlightShapes`,[]),d(this,`_currentHighlightShape`,null),d(this,`_query`,null),d(this,`_workbookSelections`,void 0),this._workbookSelections=c.getWorkbookSelections(this.unitId)}dispose(){super.dispose(),this._disposeHighlights(),this._toggleDisplayRawFormula(!1)}getMatches(){return this._matches}start(e){switch(this._query=e,e.findBy===r.FindBy.FORMULA?this._toggleDisplayRawFormula(!0):this._toggleDisplayRawFormula(!1),e.findScope){case r.FindScope.UNIT:this.findInWorkbook(e);break;case r.FindScope.SUBUNIT:default:this.findInActiveWorksheet(e);break}}focusSelection(){let e=this.currentMatch;e&&this._commandService.executeCommand(t.SelectRangeCommand.id,{unitId:e.unitId,subUnit:e.range.subUnitId,range:e.range.range})}_toggleDisplayRawFormula(e){this._contextService.setContextValue(n.RENDER_RAW_FORMULA_KEY,e)}findInWorkbook(n){let r=this._workbook.getUnitId(),i,o=!0,s=()=>{this._matches=this._workbook.getSheets().filter(e=>!e.isSheetHidden()).map(e=>{let t=this._findInWorksheet(e,n,r),i=e.getSheetId(),{results:a}=t;return a.length?this._matchesByWorksheet.set(i,t.results):this._matchesByWorksheet.delete(i),t}).map(e=>e.results).flat(),this._updateFindHighlight(),o?(i={results:this._matches},o=!1):this._matchesUpdate$.next(this._matches)};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>{this._updateFindHighlight(),this._updateCurrentHighlightShape(this._activeHighlightIndex)})),this.disposeWithMe((0,e.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0,a.filter)(([e,n])=>e.id===t.SetWorksheetActiveOperation.id&&!(n!=null&&n.fromFindReplace))).subscribe(()=>{let e=this._workbook.getActiveSheet();if(!e)return;let t=e.getSheetId();this._matchesByWorksheet.has(t)&&this._findNextMatchOnActiveSheetChange(e)})),this.disposeWithMe((0,e.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0,a.filter)(([t])=>t.type===e.CommandType.MUTATION&&t.params.unitId===this._workbook.getUnitId()),(0,a.throttleTime)(600,void 0,{leading:!1,trailing:!0})).subscribe(()=>s())),s(),i}_findNextMatchOnActiveSheetChange(e){let t,n,r=0,i=this._matchesByWorksheet.get(e.getSheetId()),a=this._workbookSelections.getCurrentSelections();a!=null&&a.length?([t,r]=this._findNextMatchByRange(i,a[0].range),n=i.findIndex(e=>e===t)):(t=i[0],n=0,r=this._matches.findIndex(e=>e===t)),this._matchesPosition=r+1,this._activelyChangingMatch$.next(t),this._activeHighlightIndex=n,this._updateFindHighlight(),this._updateCurrentHighlightShape(n)}findInActiveWorksheet(n){let r=this._workbook.getUnitId(),i=()=>{var e;let t=this._workbook.getActiveSheet();if(!t)return!1;let n=this._workbookSelections.getCurrentSelections();return(e=n==null?void 0:n.some(e=>!v(e,t)))==null?!1:e},o,s=!0,c=!1,l=()=>{let e=this._workbook.getActiveSheet();if(!e)return{results:[]};let t=this.currentMatch;c=i();let a=this._workbookSelections.getCurrentSelections(),l=c?this._findInSelections(e,a,n,r):this._findInWorksheet(e,n,r);return this._matches=l.results,this._matchesPosition=this._tryRestoreLastMatchesPosition(t,this._matches),s?(o=l,s=!1):this._matchesUpdate$.next(this._matches),this._updateFindHighlight(),l};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>this._updateFindHighlight())),this.disposeWithMe((0,a.merge)((0,e.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0,a.filter)(([n])=>{if(n.type===e.CommandType.MUTATION&&n.params.unitId===this._workbook.getUnitId())return!0;if(n.id===t.SetSelectionsOperation.id&&n.params.unitId===r){let e=i();return e===!1&&c===!1?!1:(c=e,!0)}return!1})),this._workbook.activeSheet$.pipe((0,a.skip)(1))).pipe((0,a.debounceTime)(200)).subscribe(()=>l())),l(),o}_findInRange(e,t,n,i,a){let o=[],s=e.getSheetId(),c=(t.findDirection===r.FindDirection.COLUMN?e.iterateByColumn:e.iterateByRow).bind(e)(n);for(let n of c){let{row:r,col:c,colSpan:l,rowSpan:u,value:d}=n;if(a!=null&&a(r,c)||!d||e.getRowFiltered(r))continue;let{hit:f,replaceable:p,isFormula:m}=E(e,r,c,t,d);if(f){let e={provider:`sheets-find-replace-provider`,unitId:i,replaceable:p,isFormula:m,range:{subUnitId:s,range:{startRow:r,startColumn:c,endColumn:c+(l==null?1:l)-1,endRow:r+(u==null?1:u)-1}}};o.push(e)}}return{results:o}}_findInSelections(e,t,n,i){let{findDirection:a}=n,o=a===r.FindDirection.ROW?m:h,s=new Set;return{results:t.map(t=>this._findInRange(e,n,t.range,i,(e,t)=>{let n=`${e}-${t}`;return s.has(n)?!0:(s.add(n),!1)}).results).flat().sort((e,t)=>o(e.range.range,t.range.range)?-1:1)}}_findInWorksheet(e,t,n){let r=e.getRowCount(),i=e.getColumnCount(),a={startRow:0,startColumn:0,endRow:r-1,endColumn:i-1};return this._findInRange(e,t,a,n)}_disposeHighlights(){var e;this._highlightShapes.forEach(e=>{var t;(t=e.getScene())==null||t.makeDirty(),e.dispose()}),this._highlightShapes=[],(e=this._currentHighlightShape)==null||e.dispose(),this._currentHighlightShape=null}_updateFindHighlight(){this._disposeHighlights();let t=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!t)return;let n=this._workbook.getUnitId(),r=this._renderManagerService.getRenderById(n);if(r==null)return;let{scene:a}=r,o=this._matches,s=new e.ColorKit(this._themeService.getColorFromTheme(`yellow.400`)).toRgb(),c=this._workbook.getActiveSheet();if(!c)return;let l=c.getSheetId(),u=o.filter(e=>e.range.subUnitId===l).map((e,n)=>{let{startColumn:r,startRow:o,endColumn:l,endRow:u}=e.range.range,d=(0,i.getCoordByCell)(o,r,a,t),p=(0,i.getCoordByCell)(u,l,a,t),{startX:m,startY:h}=d,{endX:g,endY:_}=p,v=!0;for(let e=o;e<=u;e++)if(c.getRowRawVisible(e)){v=!1;break}let y=!0;for(let e=r;e<=l;e++)if(c.getColVisible(e)){y=!1;break}let b=v||y,x={left:m,top:h,color:s,width:y?2:g-m,height:v?2:_-h,evented:!1,inHiddenRange:b,zIndex:1e4};return new f(`find-highlight-${n}`,x)});a.addObjects(u),this._highlightShapes=u,a.makeDirty()}_updateCurrentHighlightShape(e){var t;if((t=this._currentHighlightShape)==null||t.setShapeProps({activated:!1}),this._currentHighlightShape=null,e!==void 0){let t=this._highlightShapes[e];if(!t)return;this._currentHighlightShape=t,t.setShapeProps({activated:!0})}}_getSheetObject(){return(0,i.getSheetObject)(this._univerInstanceService,this._renderManagerService)}_focusMatch(e){var n;let r=e.range.subUnitId;r!==((n=this._workbook.getActiveSheet())==null?void 0:n.getSheetId())&&this._commandService.executeCommand(t.SetWorksheetActivateCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:r},{fromFindReplace:!0}),this._commandService.executeCommand(i.ScrollToCellCommand.id,{range:e.range.range},{fromFindReplace:!0})}_tryRestoreLastMatchesPosition(e,t){if(!e)return 0;let{subUnitId:n}=e.range,{startColumn:r,startRow:i}=e.range.range,a=t.findIndex(e=>{if(n!==e.range.subUnitId)return!1;let{startColumn:t,startRow:a}=e.range.range;return t===r&&a===i});return a>-1?a+1:0}moveToNextMatch(e){var t,n,i,a;if(!this._matches.length)return null;let o=(t=e==null?void 0:e.loop)==null?!1:t,s=(n=e==null?void 0:e.stayIfOnMatch)==null?!1:n,c=(i=e==null?void 0:e.noFocus)==null?!1:i,l=(a=e==null?void 0:e.ignoreSelection)==null?!1:a,u=this._findNextMatch(o,s,l);if(u){var d;let[e,t]=u;return this._matchesPosition=t+1,this._query.findScope===r.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(e.range.subUnitId).findIndex(t=>t===e):this._activeHighlightIndex=t,c||this._focusMatch(e),((d=this._workbook.getActiveSheet())==null?void 0:d.getSheetId())===e.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),e}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}moveToPreviousMatch(e){var t,n,i,a;if(!this._matches.length)return null;let o=(t=e==null?void 0:e.loop)==null?!1:t,s=(n=e==null?void 0:e.stayIfOnMatch)==null?!1:n,c=(i=e==null?void 0:e.noFocus)==null?!1:i,l=(a=e==null?void 0:e.ignoreSelection)==null?!1:a,u=this._findPreviousMatch(o,s,l);if(u){var d;let[e,t]=u;return this._matchesPosition=t+1,this._query.findScope===r.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(e.range.subUnitId).findIndex(t=>t===e):this._activeHighlightIndex=t,c||this._focusMatch(e),((d=this._workbook.getActiveSheet())==null?void 0:d.getSheetId())===e.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),e}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}_findPreviousMatch(e=!1,t=!1,n=!1){var i;if(this.currentMatch){let n=this._matches.findIndex(e=>e===this.currentMatch);if(t)return[this.currentMatch,n];let r=n-1;if(!e&&r<0)return null;let i=this._matches.length,a=(r+i)%i;return[this._matches[a],a]}let a=this._workbookSelections.getCurrentLastSelection();if(n||!a){let e=this._matches.length-1;return[this._matches[e],e]}if(this._query.findScope!==r.FindScope.UNIT)return this._findPreviousMatchByRange(this._matches,a.range);let o=(i=this._workbook.getActiveSheet())==null?void 0:i.getSheetId();if(!o)return null;let s=this._findPreviousWorksheetThatHasAMatch(o,e);return s?this._findPreviousMatchByRange(this._matchesByWorksheet.get(s),a.range):null}_findNextMatch(e=!1,t=!1,n=!1){var i;if(this.currentMatch){let n=this._matches.findIndex(e=>e===this.currentMatch);if(t)return[this.currentMatch,n];let r=n+1,i=this._matches.length;if(!e&&r>=i)return null;let a=r%i;return[this._matches[a],a]}let a=this._workbookSelections.getCurrentLastSelection();if(n||!a)return[this._matches[0],0];if(this._query.findScope!==r.FindScope.UNIT)return this._findNextMatchByRange(this._matches,a.range,t);let o=(i=this._workbook.getActiveSheet())==null?void 0:i.getSheetId();if(!o)return null;let s=this._findNextWorksheetThatHasAMatch(o,e);return s?this._findNextMatchByRange(this._matchesByWorksheet.get(s),a.range):null}_findPreviousWorksheetThatHasAMatch(t,n=!1){let r=this._workbook.getSheetOrders(),i=r.findIndex(e=>e===t),a=(n?(0,e.rotate)(r,i+1):r.slice(0,i+1)).findLast(e=>this._matchesByWorksheet.has(e));return a==null?null:a}_findNextWorksheetThatHasAMatch(t,n=!1){let r=this._workbook.getSheetOrders(),i=r.findIndex(e=>e===t),a=(n?(0,e.rotate)(r,i):r.slice(i)).find(e=>this._matchesByWorksheet.has(e));return a==null?null:a}_findNextMatchByRange(e,t,n=!1){let i=this._query.findDirection===r.FindDirection.ROW,a=e.findIndex(e=>{let r=e.range.range;if(!(i?m(t,r):h(t,r)))return!1;let a=p(t,r);return n?a:!a});a===-1&&(a=e.length-1);let o=e[a];return[o,this._matches.findIndex(e=>e===o)]}_findPreviousMatchByRange(e,t,n=!1){let i=this._query.findDirection===r.FindDirection.ROW,a=this._matches.findLastIndex(e=>{let r=e.range.range;if(!(i?g(t,r):_(t,r)))return!1;let a=p(t,r);return n?a:!a});a===-1&&(a=0);let o=e[a];return[o,this._matches.findIndex(e=>e===o)]}async replace(e){if(this._matchesCount===0||!this.currentMatch||!this._query||!this.currentMatch.replaceable)return!1;let n=this.currentMatch.range,i=this._workbook.getSheetBySheetId(this.currentMatch.range.subUnitId),a=this._getReplacedCellData(this.currentMatch,i,this._query.findBy===r.FindBy.FORMULA,this._query.findString,e,this._query.caseSensitive?`g`:`ig`),o={unitId:this.currentMatch.unitId,subUnitId:n.subUnitId,value:{[n.range.startRow]:{[n.range.startColumn]:a}}};return this._commandService.executeCommand(t.SetRangeValuesCommand.id,o)}async replaceAll(t){if(this._matchesCount===0||!this._query)return{success:0,failure:0};let n=this._workbook.getUnitId(),{findString:i,caseSensitive:a,findBy:s}=this._query,c=s===r.FindBy.FORMULA,l=a?`g`:`ig`,u=[];return(0,e.groupBy)(this._matches.filter(e=>e.replaceable),e=>e.range.subUnitId).forEach((n,r)=>{let a=new e.ObjectMatrix,o=this._workbook.getSheetBySheetId(r);n.forEach(e=>{let{startColumn:n,startRow:r}=e.range.range,s=this._getReplacedCellData(e,o,c,i,t,l);s&&a.setValue(r,n,s)}),u.push({count:n.length,subUnitId:r,value:a.getMatrix()})}),u?this._commandService.executeCommand(o.id,{unitId:n,replacements:u}):{success:0,failure:0}}_getReplacedCellData(t,n,r,i,a,o){var s;let{startRow:c,startColumn:l}=t.range.range,u=n.getCellRaw(c,l);if(t.isFormula)return r?{f:u.f.replace(new RegExp(C(i),o),a),v:null}:null;if((s=u.p)!=null&&s.body){let t=e.Tools.deepClone(u.p);return(0,e.replaceInDocumentBody)(t.body,i,a,this._query.caseSensitive),{p:t}}return{v:u.v.toString().replace(new RegExp(C(i),o),a)}}};S=b([y(2,e.IUniverInstanceService),y(3,n.IRenderManagerService),y(4,e.ICommandService),y(5,e.IContextService),y(6,(0,e.Inject)(e.ThemeService)),y(7,(0,e.Inject)(t.SheetsSelectionsService))],S);function C(e){return e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,`\\$&`)}let w=class extends e.Disposable{constructor(e,t,n){super(),this._univerInstanceService=e,this._renderManagerService=t,this._injector=n,d(this,`_findModelsByUnitId`,new Map)}async find(t){this._terminate();let n=this._univerInstanceService.getCurrentUnitOfType(e.UniverInstanceType.UNIVER_SHEET);if(!n)return[];let r=this._preprocessQuery(t),a=this._renderManagerService.getRenderById(n.getUnitId()).with(i.SheetSkeletonManagerService),o=this._injector.createInstance(S,n,a);return this._findModelsByUnitId.set(n.getUnitId(),o),o.start(r),[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}}};w=b([y(0,e.IUniverInstanceService),y(1,n.IRenderManagerService),y(2,(0,e.Inject)(e.Injector))],w);const T={hit:!1,replaceable:!1,isFormula:!1,rawData:null};function E(e,t,n,i,a){let{findBy:o}=i,s=o===r.FindBy.FORMULA,c=e.getCellRaw(t,n);return T.rawData=c,c!=null&&c.f?(T.isFormula=!0,s?D({v:c.f},i)?(T.hit=!0,T.replaceable=!0,T):(T.hit=!1,T.replaceable=!1,T):(T.replaceable=!1,D(a,i)?T.hit=!0:T.hit=!1,T)):(T.isFormula=!1,D(a,i)?c?(T.hit=!0,T.replaceable=!0):(T.hit=!0,T.replaceable=!1):(T.hit=!1,T.replaceable=!1),T)}function D(e,t){let n=O(e);return n?t.matchesTheWholeCell?(n=k(n),t.caseSensitive?n===t.findString:n.toLowerCase()===t.findString):t.caseSensitive?n.indexOf(t.findString)>-1:n.toLowerCase().indexOf(t.findString)>-1:!1}function O(e){var t,n;let r=(t=e==null||(n=e.p)==null||(n=n.body)==null?void 0:n.dataStream)==null?e==null?void 0:e.v:t;return typeof r==`number`?`${r}`:typeof r==`boolean`?r?`1`:`0`:r}function k(e){return e.replace(/^ +/g,``).replace(/ +$/g,``)}var A=`@univerjs/sheets-find-replace`,j=`0.20.1`;const M=`sheets-find-replace.config`;Symbol(M);const N={};let P=class extends e.Plugin{constructor(t=N,n,r){super(),this._config=t,this._injector=n,this._configService=r;let{...i}=(0,e.merge)({},N,this._config);this._configService.setConfig(M,i)}onStarting(){[[x]].forEach(e=>this._injector.add(e))}onSteady(){this._injector.get(x)}};d(P,`pluginName`,`SHEET_FIND_REPLACE_PLUGIN`),d(P,`packageName`,A),d(P,`version`,j),d(P,`type`,e.UniverInstanceType.UNIVER_SHEET),P=b([(0,e.DependentOn)(t.UniverSheetsPlugin,t.UniverSheetsPlugin,r.UniverFindReplacePlugin),y(1,(0,e.Inject)(e.Injector)),y(2,e.IConfigService)],P),exports.SheetReplaceCommand=o,Object.defineProperty(exports,`SheetsFindReplaceController`,{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,`UniverSheetsFindReplacePlugin`,{enumerable:!0,get:function(){return P}});
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ let _univerjs_core = require("@univerjs/core");
3
+ let _univerjs_sheets = require("@univerjs/sheets");
4
+ let _univerjs_engine_render = require("@univerjs/engine-render");
5
+ let _univerjs_find_replace = require("@univerjs/find-replace");
6
+ let _univerjs_sheets_ui = require("@univerjs/sheets-ui");
7
+ let rxjs = require("rxjs");
8
+
9
+ //#region src/commands/commands/sheet-replace.command.ts
10
+ /**
11
+ * This command is used for the SheetFindReplaceController to deal with replacing, including undo redo.
12
+ *
13
+ */
14
+ const SheetReplaceCommand = {
15
+ id: "sheet.command.replace",
16
+ type: _univerjs_core.CommandType.COMMAND,
17
+ handler: async (accessor, params) => {
18
+ const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
19
+ const commandService = accessor.get(_univerjs_core.ICommandService);
20
+ const { unitId, replacements } = params;
21
+ const disposeBatchingHandler = undoRedoService.__tempBatchingUndoRedo(unitId);
22
+ const results = await Promise.all(replacements.map((replacement) => commandService.executeCommand(_univerjs_sheets.SetRangeValuesCommand.id, {
23
+ unitId,
24
+ subUnitId: replacement.subUnitId,
25
+ value: replacement.value
26
+ })));
27
+ disposeBatchingHandler.dispose();
28
+ return getReplaceAllResult(results, replacements);
29
+ }
30
+ };
31
+ function getReplaceAllResult(results, replacements) {
32
+ let success = 0;
33
+ let failure = 0;
34
+ results.forEach((r, index) => {
35
+ const count = replacements[index].count;
36
+ if (r) success += count;
37
+ else failure += count;
38
+ });
39
+ return {
40
+ success,
41
+ failure
42
+ };
43
+ }
44
+
45
+ //#endregion
46
+ //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
47
+ function _typeof(o) {
48
+ "@babel/helpers - typeof";
49
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
50
+ return typeof o;
51
+ } : function(o) {
52
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
53
+ }, _typeof(o);
54
+ }
55
+
56
+ //#endregion
57
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
58
+ function toPrimitive(t, r) {
59
+ if ("object" != _typeof(t) || !t) return t;
60
+ var e = t[Symbol.toPrimitive];
61
+ if (void 0 !== e) {
62
+ var i = e.call(t, r || "default");
63
+ if ("object" != _typeof(i)) return i;
64
+ throw new TypeError("@@toPrimitive must return a primitive value.");
65
+ }
66
+ return ("string" === r ? String : Number)(t);
67
+ }
68
+
69
+ //#endregion
70
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
71
+ function toPropertyKey(t) {
72
+ var i = toPrimitive(t, "string");
73
+ return "symbol" == _typeof(i) ? i : i + "";
74
+ }
75
+
76
+ //#endregion
77
+ //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
78
+ function _defineProperty(e, r, t) {
79
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
80
+ value: t,
81
+ enumerable: !0,
82
+ configurable: !0,
83
+ writable: !0
84
+ }) : e[r] = t, e;
85
+ }
86
+
87
+ //#endregion
88
+ //#region src/views/shapes/find-replace-highlight.shape.ts
89
+ var SheetFindReplaceHighlightShape = class extends _univerjs_engine_render.Shape {
90
+ constructor(key, props) {
91
+ super(key, props);
92
+ _defineProperty(this, "_activated", false);
93
+ _defineProperty(this, "_inHiddenRange", false);
94
+ _defineProperty(this, "_color", void 0);
95
+ if (props) this.setShapeProps(props);
96
+ }
97
+ setShapeProps(props) {
98
+ this._activated = !!props.activated;
99
+ if (typeof props.inHiddenRange !== "undefined") this._inHiddenRange = props.inHiddenRange;
100
+ if (typeof props.color !== "undefined") this._color = props.color;
101
+ this.transformByState({
102
+ width: props.width,
103
+ height: props.height
104
+ });
105
+ }
106
+ _draw(ctx) {
107
+ const activated = this._activated;
108
+ const color = `rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 0.35)`;
109
+ const borderColor = `rgb(${this._color.r}, ${this._color.g}, ${this._color.b})`;
110
+ _univerjs_engine_render.Rect.drawWith(ctx, {
111
+ width: this.width,
112
+ height: this.height,
113
+ fill: color,
114
+ stroke: activated ? borderColor : void 0,
115
+ strokeWidth: activated ? 2 : 0,
116
+ evented: false
117
+ });
118
+ }
119
+ };
120
+
121
+ //#endregion
122
+ //#region src/controllers/utils.ts
123
+ function isSamePosition(range1, range2) {
124
+ return range1.startRow === range2.startRow && range1.startColumn === range2.startColumn;
125
+ }
126
+ /**
127
+ * Tell if `range2` is after (or the same as) `range1` with row direction is at priority.
128
+ * @param range1
129
+ * @param range2
130
+ * @returns
131
+ */
132
+ function isBehindPositionWithRowPriority(range1, range2) {
133
+ return range1.startRow < range2.startRow || range1.startRow === range2.startRow && range1.startColumn <= range2.startColumn;
134
+ }
135
+ /**
136
+ * Tell if `range2` is after (or the same as) `range1` with column direction is at priority.
137
+ * @param range1
138
+ * @param range2
139
+ * @returns
140
+ */
141
+ function isBehindPositionWithColumnPriority(range1, range2) {
142
+ return range1.startColumn < range2.startColumn || range1.startColumn === range2.startColumn && range1.startRow <= range2.startRow;
143
+ }
144
+ /**
145
+ * Tell if `range2` is before (or the same as) `range1` with column direction is at priority.
146
+ * @param range1
147
+ * @param range2
148
+ * @returns
149
+ */
150
+ function isBeforePositionWithRowPriority(range1, range2) {
151
+ return range1.startRow > range2.startRow || range1.startRow === range2.startRow && range1.startColumn >= range2.startColumn;
152
+ }
153
+ function isBeforePositionWithColumnPriority(range1, range2) {
154
+ return range1.startColumn > range2.startColumn || range1.startColumn === range2.startColumn && range1.startRow >= range2.startRow;
155
+ }
156
+ function isSelectionSingleCell(selection, worksheet) {
157
+ const { range } = selection;
158
+ const { startRow, startColumn } = range;
159
+ const hasMergedCell = worksheet.getMergedCell(startRow, startColumn);
160
+ if (hasMergedCell) return _univerjs_core.Rectangle.equals(range, hasMergedCell);
161
+ else return range.endRow === range.startRow && range.endColumn === range.startColumn;
162
+ }
163
+
164
+ //#endregion
165
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
166
+ function __decorateParam(paramIndex, decorator) {
167
+ return function(target, key) {
168
+ decorator(target, key, paramIndex);
169
+ };
170
+ }
171
+
172
+ //#endregion
173
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
174
+ function __decorate(decorators, target, key, desc) {
175
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
176
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
177
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
178
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
179
+ }
180
+
181
+ //#endregion
182
+ //#region src/controllers/sheet-find-replace.controller.ts
183
+ let SheetsFindReplaceController = class SheetsFindReplaceController extends _univerjs_core.Disposable {
184
+ constructor(_injector, _findReplaceController, _contextService, _findReplaceService, _commandService) {
185
+ super();
186
+ this._injector = _injector;
187
+ this._findReplaceController = _findReplaceController;
188
+ this._contextService = _contextService;
189
+ this._findReplaceService = _findReplaceService;
190
+ this._commandService = _commandService;
191
+ _defineProperty(this, "_provider", void 0);
192
+ this._init();
193
+ this._initCommands();
194
+ }
195
+ dispose() {
196
+ super.dispose();
197
+ this._findReplaceController.closePanel();
198
+ this._provider.dispose();
199
+ }
200
+ _init() {
201
+ const provider = this._injector.createInstance(SheetsFindReplaceProvider);
202
+ this._provider = provider;
203
+ this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(provider));
204
+ this.disposeWithMe(this._contextService.subscribeContextValue$(_univerjs_core.EDITOR_ACTIVATED).pipe((0, rxjs.filter)((v) => !!v)).subscribe(() => this._findReplaceController.closePanel()));
205
+ }
206
+ _initCommands() {
207
+ [SheetReplaceCommand].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
208
+ }
209
+ };
210
+ SheetsFindReplaceController = __decorate([
211
+ __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
212
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_find_replace.FindReplaceController)),
213
+ __decorateParam(2, _univerjs_core.IContextService),
214
+ __decorateParam(3, _univerjs_find_replace.IFindReplaceService),
215
+ __decorateParam(4, _univerjs_core.ICommandService)
216
+ ], SheetsFindReplaceController);
217
+ const SHEETS_FIND_REPLACE_PROVIDER_NAME = "sheets-find-replace-provider";
218
+ const FIND_REPLACE_Z_INDEX = 1e4;
219
+ let SheetFindModel = class SheetFindModel extends _univerjs_find_replace.FindModel {
220
+ get _matchesCount() {
221
+ return this._matches.length;
222
+ }
223
+ get unitId() {
224
+ return this._workbook.getUnitId();
225
+ }
226
+ get matchesCount() {
227
+ return this._matchesCount;
228
+ }
229
+ get matchesPosition() {
230
+ return this._matchesPosition;
231
+ }
232
+ get currentMatch() {
233
+ return this._matchesPosition > 0 ? this._matches[this._matchesPosition - 1] : null;
234
+ }
235
+ constructor(_workbook, _sheetSkeletonManagerService, _univerInstanceService, _renderManagerService, _commandService, _contextService, _themeService, _selectionManagerService) {
236
+ super();
237
+ this._workbook = _workbook;
238
+ this._sheetSkeletonManagerService = _sheetSkeletonManagerService;
239
+ this._univerInstanceService = _univerInstanceService;
240
+ this._renderManagerService = _renderManagerService;
241
+ this._commandService = _commandService;
242
+ this._contextService = _contextService;
243
+ this._themeService = _themeService;
244
+ _defineProperty(this, "_matchesUpdate$", new rxjs.Subject());
245
+ _defineProperty(this, "matchesUpdate$", this._matchesUpdate$.asObservable());
246
+ _defineProperty(this, "_activelyChangingMatch$", new rxjs.Subject());
247
+ _defineProperty(this, "activelyChangingMatch$", this._activelyChangingMatch$.asObservable());
248
+ _defineProperty(this, "_matchesByWorksheet", /* @__PURE__ */ new Map());
249
+ _defineProperty(this, "_matches", []);
250
+ _defineProperty(this, "_matchesPosition", 0);
251
+ _defineProperty(this, "_activeHighlightIndex", -1);
252
+ _defineProperty(this, "_highlightShapes", []);
253
+ _defineProperty(this, "_currentHighlightShape", null);
254
+ _defineProperty(this, "_query", null);
255
+ _defineProperty(this, "_workbookSelections", void 0);
256
+ this._workbookSelections = _selectionManagerService.getWorkbookSelections(this.unitId);
257
+ }
258
+ dispose() {
259
+ super.dispose();
260
+ this._disposeHighlights();
261
+ this._toggleDisplayRawFormula(false);
262
+ }
263
+ getMatches() {
264
+ return this._matches;
265
+ }
266
+ start(query) {
267
+ this._query = query;
268
+ if (query.findBy === _univerjs_find_replace.FindBy.FORMULA) this._toggleDisplayRawFormula(true);
269
+ else this._toggleDisplayRawFormula(false);
270
+ switch (query.findScope) {
271
+ case _univerjs_find_replace.FindScope.UNIT:
272
+ this.findInWorkbook(query);
273
+ break;
274
+ case _univerjs_find_replace.FindScope.SUBUNIT:
275
+ default:
276
+ this.findInActiveWorksheet(query);
277
+ break;
278
+ }
279
+ }
280
+ focusSelection() {
281
+ const currentMatch = this.currentMatch;
282
+ if (!currentMatch) return;
283
+ this._commandService.executeCommand(_univerjs_sheets.SelectRangeCommand.id, {
284
+ unitId: currentMatch.unitId,
285
+ subUnit: currentMatch.range.subUnitId,
286
+ range: currentMatch.range.range
287
+ });
288
+ }
289
+ _toggleDisplayRawFormula(force) {
290
+ this._contextService.setContextValue(_univerjs_engine_render.RENDER_RAW_FORMULA_KEY, force);
291
+ }
292
+ /**
293
+ * Find all matches in the current workbook no matter which worksheet is activated.
294
+ * @param query the query object
295
+ * @returns the query complete event
296
+ */
297
+ findInWorkbook(query) {
298
+ const unitId = this._workbook.getUnitId();
299
+ let complete;
300
+ let firstSearch = true;
301
+ const findInWorkbook = () => {
302
+ this._matches = this._workbook.getSheets().filter((worksheet) => !worksheet.isSheetHidden()).map((worksheet) => {
303
+ const complete = this._findInWorksheet(worksheet, query, unitId);
304
+ const sheetId = worksheet.getSheetId();
305
+ const { results } = complete;
306
+ if (results.length) this._matchesByWorksheet.set(sheetId, complete.results);
307
+ else this._matchesByWorksheet.delete(sheetId);
308
+ return complete;
309
+ }).map((c) => c.results).flat();
310
+ this._updateFindHighlight();
311
+ if (firstSearch) {
312
+ complete = { results: this._matches };
313
+ firstSearch = false;
314
+ } else this._matchesUpdate$.next(this._matches);
315
+ };
316
+ this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(() => {
317
+ this._updateFindHighlight();
318
+ this._updateCurrentHighlightShape(this._activeHighlightIndex);
319
+ }));
320
+ this.disposeWithMe((0, _univerjs_core.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0, rxjs.filter)(([command, options]) => command.id === _univerjs_sheets.SetWorksheetActiveOperation.id && !(options === null || options === void 0 ? void 0 : options.fromFindReplace))).subscribe(() => {
321
+ const activeSheet = this._workbook.getActiveSheet();
322
+ if (!activeSheet) return;
323
+ const activeSheetId = activeSheet.getSheetId();
324
+ if (!this._matchesByWorksheet.has(activeSheetId)) return;
325
+ this._findNextMatchOnActiveSheetChange(activeSheet);
326
+ }));
327
+ this.disposeWithMe((0, _univerjs_core.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0, rxjs.filter)(([command]) => command.type === _univerjs_core.CommandType.MUTATION && command.params.unitId === this._workbook.getUnitId()), (0, rxjs.throttleTime)(600, void 0, {
328
+ leading: false,
329
+ trailing: true
330
+ })).subscribe(() => findInWorkbook()));
331
+ findInWorkbook();
332
+ return complete;
333
+ }
334
+ /**
335
+ * This method is used in `findInWorkbook`. When the active sheet changes, this method helps to find the next match
336
+ * in the new worksheet.
337
+ */
338
+ _findNextMatchOnActiveSheetChange(activeSheet) {
339
+ let match;
340
+ let index;
341
+ let globalIndex = 0;
342
+ const matchesByWorksheet = this._matchesByWorksheet.get(activeSheet.getSheetId());
343
+ const selections = this._workbookSelections.getCurrentSelections();
344
+ if (!(selections === null || selections === void 0 ? void 0 : selections.length)) {
345
+ match = matchesByWorksheet[0];
346
+ index = 0;
347
+ globalIndex = this._matches.findIndex((m) => m === match);
348
+ } else {
349
+ [match, globalIndex] = this._findNextMatchByRange(matchesByWorksheet, selections[0].range);
350
+ index = matchesByWorksheet.findIndex((m) => m === match);
351
+ }
352
+ this._matchesPosition = globalIndex + 1;
353
+ this._activelyChangingMatch$.next(match);
354
+ this._activeHighlightIndex = index;
355
+ this._updateFindHighlight();
356
+ this._updateCurrentHighlightShape(index);
357
+ }
358
+ /**
359
+ * Find all matches (only) in the currently activated worksheet.
360
+ * @param query the query object
361
+ * @returns the query complete event
362
+ */
363
+ findInActiveWorksheet(query) {
364
+ const unitId = this._workbook.getUnitId();
365
+ const checkShouldFindInSelections = () => {
366
+ var _currentSelections$so;
367
+ const currentWorksheet = this._workbook.getActiveSheet();
368
+ if (!currentWorksheet) return false;
369
+ const currentSelections = this._workbookSelections.getCurrentSelections();
370
+ return (_currentSelections$so = currentSelections === null || currentSelections === void 0 ? void 0 : currentSelections.some((selection) => !isSelectionSingleCell(selection, currentWorksheet))) !== null && _currentSelections$so !== void 0 ? _currentSelections$so : false;
371
+ };
372
+ let complete;
373
+ let firstSearch = true;
374
+ let findBySelections = false;
375
+ const performFindInWorksheet = () => {
376
+ const currentWorksheet = this._workbook.getActiveSheet();
377
+ if (!currentWorksheet) return { results: [] };
378
+ const lastMatch = this.currentMatch;
379
+ findBySelections = checkShouldFindInSelections();
380
+ const currentSelections = this._workbookSelections.getCurrentSelections();
381
+ const newComplete = findBySelections ? this._findInSelections(currentWorksheet, currentSelections, query, unitId) : this._findInWorksheet(currentWorksheet, query, unitId);
382
+ this._matches = newComplete.results;
383
+ this._matchesPosition = this._tryRestoreLastMatchesPosition(lastMatch, this._matches);
384
+ if (firstSearch) {
385
+ complete = newComplete;
386
+ firstSearch = false;
387
+ } else this._matchesUpdate$.next(this._matches);
388
+ this._updateFindHighlight();
389
+ return newComplete;
390
+ };
391
+ this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(() => this._updateFindHighlight()));
392
+ this.disposeWithMe((0, rxjs.merge)((0, _univerjs_core.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0, rxjs.filter)(([command]) => {
393
+ if (command.type === _univerjs_core.CommandType.MUTATION && command.params.unitId === this._workbook.getUnitId()) return true;
394
+ if (command.id === _univerjs_sheets.SetSelectionsOperation.id && command.params.unitId === unitId) {
395
+ const shouldFindBySelections = checkShouldFindInSelections();
396
+ if (shouldFindBySelections === false && findBySelections === false) return false;
397
+ findBySelections = shouldFindBySelections;
398
+ return true;
399
+ }
400
+ return false;
401
+ })), this._workbook.activeSheet$.pipe((0, rxjs.skip)(1))).pipe((0, rxjs.debounceTime)(200)).subscribe(() => performFindInWorksheet()));
402
+ performFindInWorksheet();
403
+ return complete;
404
+ }
405
+ _findInRange(worksheet, query, range, unitId, dedupeFn) {
406
+ const results = [];
407
+ const subUnitId = worksheet.getSheetId();
408
+ const iter = (query.findDirection === _univerjs_find_replace.FindDirection.COLUMN ? worksheet.iterateByColumn : worksheet.iterateByRow).bind(worksheet)(range);
409
+ for (const value of iter) {
410
+ const { row, col, colSpan, rowSpan, value: cellData } = value;
411
+ if ((dedupeFn === null || dedupeFn === void 0 ? void 0 : dedupeFn(row, col)) || !cellData) continue;
412
+ if (worksheet.getRowFiltered(row)) continue;
413
+ const { hit, replaceable, isFormula } = hitCell(worksheet, row, col, query, cellData);
414
+ if (hit) {
415
+ const result = {
416
+ provider: SHEETS_FIND_REPLACE_PROVIDER_NAME,
417
+ unitId,
418
+ replaceable,
419
+ isFormula,
420
+ range: {
421
+ subUnitId,
422
+ range: {
423
+ startRow: row,
424
+ startColumn: col,
425
+ endColumn: col + (colSpan !== null && colSpan !== void 0 ? colSpan : 1) - 1,
426
+ endRow: row + (rowSpan !== null && rowSpan !== void 0 ? rowSpan : 1) - 1
427
+ }
428
+ }
429
+ };
430
+ results.push(result);
431
+ }
432
+ }
433
+ return { results };
434
+ }
435
+ _findInSelections(worksheet, selections, query, unitId) {
436
+ const { findDirection } = query;
437
+ const sortFn = findDirection === _univerjs_find_replace.FindDirection.ROW ? isBehindPositionWithRowPriority : isBehindPositionWithColumnPriority;
438
+ const dedupeSet = /* @__PURE__ */ new Set();
439
+ return { results: selections.map((selection) => this._findInRange(worksheet, query, selection.range, unitId, (row, col) => {
440
+ const key = `${row}-${col}`;
441
+ if (dedupeSet.has(key)) return true;
442
+ dedupeSet.add(key);
443
+ return false;
444
+ }).results).flat().sort((a, b) => sortFn(a.range.range, b.range.range) ? -1 : 1) };
445
+ }
446
+ /** Find matches in a given worksheet. */
447
+ _findInWorksheet(worksheet, query, unitId) {
448
+ const rowCount = worksheet.getRowCount();
449
+ const colCount = worksheet.getColumnCount();
450
+ const range = {
451
+ startRow: 0,
452
+ startColumn: 0,
453
+ endRow: rowCount - 1,
454
+ endColumn: colCount - 1
455
+ };
456
+ return this._findInRange(worksheet, query, range, unitId);
457
+ }
458
+ _disposeHighlights() {
459
+ var _this$_currentHighlig;
460
+ this._highlightShapes.forEach((shape) => {
461
+ var _shape$getScene;
462
+ (_shape$getScene = shape.getScene()) === null || _shape$getScene === void 0 || _shape$getScene.makeDirty();
463
+ shape.dispose();
464
+ });
465
+ this._highlightShapes = [];
466
+ (_this$_currentHighlig = this._currentHighlightShape) === null || _this$_currentHighlig === void 0 || _this$_currentHighlig.dispose();
467
+ this._currentHighlightShape = null;
468
+ }
469
+ _updateFindHighlight() {
470
+ this._disposeHighlights();
471
+ const skeleton = this._sheetSkeletonManagerService.getCurrentSkeleton();
472
+ if (!skeleton) return;
473
+ const unitId = this._workbook.getUnitId();
474
+ const currentRender = this._renderManagerService.getRenderById(unitId);
475
+ if (currentRender == null) return;
476
+ const { scene } = currentRender;
477
+ const matches = this._matches;
478
+ const color = new _univerjs_core.ColorKit(this._themeService.getColorFromTheme("yellow.400")).toRgb();
479
+ const worksheet = this._workbook.getActiveSheet();
480
+ if (!worksheet) return;
481
+ const activeSheetId = worksheet.getSheetId();
482
+ const highlightShapes = matches.filter((match) => match.range.subUnitId === activeSheetId).map((find, index) => {
483
+ const { startColumn, startRow, endColumn, endRow } = find.range.range;
484
+ const startPosition = (0, _univerjs_sheets_ui.getCoordByCell)(startRow, startColumn, scene, skeleton);
485
+ const endPosition = (0, _univerjs_sheets_ui.getCoordByCell)(endRow, endColumn, scene, skeleton);
486
+ const { startX, startY } = startPosition;
487
+ const { endX, endY } = endPosition;
488
+ let isAllRowHidden = true;
489
+ for (let row = startRow; row <= endRow; row++) if (worksheet.getRowRawVisible(row)) {
490
+ isAllRowHidden = false;
491
+ break;
492
+ }
493
+ let isAllColHidden = true;
494
+ for (let col = startColumn; col <= endColumn; col++) if (worksheet.getColVisible(col)) {
495
+ isAllColHidden = false;
496
+ break;
497
+ }
498
+ const inHiddenRange = isAllRowHidden || isAllColHidden;
499
+ const props = {
500
+ left: startX,
501
+ top: startY,
502
+ color,
503
+ width: isAllColHidden ? 2 : endX - startX,
504
+ height: isAllRowHidden ? 2 : endY - startY,
505
+ evented: false,
506
+ inHiddenRange,
507
+ zIndex: FIND_REPLACE_Z_INDEX
508
+ };
509
+ return new SheetFindReplaceHighlightShape(`find-highlight-${index}`, props);
510
+ });
511
+ scene.addObjects(highlightShapes);
512
+ this._highlightShapes = highlightShapes;
513
+ scene.makeDirty();
514
+ }
515
+ _updateCurrentHighlightShape(matchIndex) {
516
+ var _this$_currentHighlig2;
517
+ (_this$_currentHighlig2 = this._currentHighlightShape) === null || _this$_currentHighlig2 === void 0 || _this$_currentHighlig2.setShapeProps({ activated: false });
518
+ this._currentHighlightShape = null;
519
+ if (matchIndex !== void 0) {
520
+ const shape = this._highlightShapes[matchIndex];
521
+ if (!shape) return;
522
+ this._currentHighlightShape = shape;
523
+ shape.setShapeProps({ activated: true });
524
+ }
525
+ }
526
+ _getSheetObject() {
527
+ return (0, _univerjs_sheets_ui.getSheetObject)(this._univerInstanceService, this._renderManagerService);
528
+ }
529
+ _focusMatch(match) {
530
+ var _this$_workbook$getAc;
531
+ const subUnitId = match.range.subUnitId;
532
+ if (subUnitId !== ((_this$_workbook$getAc = this._workbook.getActiveSheet()) === null || _this$_workbook$getAc === void 0 ? void 0 : _this$_workbook$getAc.getSheetId())) this._commandService.executeCommand(_univerjs_sheets.SetWorksheetActivateCommand.id, {
533
+ unitId: this._workbook.getUnitId(),
534
+ subUnitId
535
+ }, { fromFindReplace: true });
536
+ this._commandService.executeCommand(_univerjs_sheets_ui.ScrollToCellCommand.id, { range: match.range.range }, { fromFindReplace: true });
537
+ }
538
+ _tryRestoreLastMatchesPosition(lastMatch, newMatches) {
539
+ if (!lastMatch) return 0;
540
+ const { subUnitId: lastSubUnitId } = lastMatch.range;
541
+ const { startColumn: lastStartColumn, startRow: lastStartRow } = lastMatch.range.range;
542
+ const index = newMatches.findIndex((match) => {
543
+ if (lastSubUnitId !== match.range.subUnitId) return false;
544
+ const { startColumn, startRow } = match.range.range;
545
+ return startColumn === lastStartColumn && startRow === lastStartRow;
546
+ });
547
+ return index > -1 ? index + 1 : 0;
548
+ }
549
+ moveToNextMatch(params) {
550
+ var _params$loop, _params$stayIfOnMatch, _params$noFocus, _params$ignoreSelecti;
551
+ if (!this._matches.length) return null;
552
+ const loop = (_params$loop = params === null || params === void 0 ? void 0 : params.loop) !== null && _params$loop !== void 0 ? _params$loop : false;
553
+ const stayIfOnMatch = (_params$stayIfOnMatch = params === null || params === void 0 ? void 0 : params.stayIfOnMatch) !== null && _params$stayIfOnMatch !== void 0 ? _params$stayIfOnMatch : false;
554
+ const noFocus = (_params$noFocus = params === null || params === void 0 ? void 0 : params.noFocus) !== null && _params$noFocus !== void 0 ? _params$noFocus : false;
555
+ const ignoreSelection = (_params$ignoreSelecti = params === null || params === void 0 ? void 0 : params.ignoreSelection) !== null && _params$ignoreSelecti !== void 0 ? _params$ignoreSelecti : false;
556
+ const matchToMove = this._findNextMatch(loop, stayIfOnMatch, ignoreSelection);
557
+ if (matchToMove) {
558
+ var _this$_workbook$getAc2;
559
+ const [match, index] = matchToMove;
560
+ this._matchesPosition = index + 1;
561
+ if (this._query.findScope === _univerjs_find_replace.FindScope.UNIT) this._activeHighlightIndex = this._matchesByWorksheet.get(match.range.subUnitId).findIndex((m) => m === match);
562
+ else this._activeHighlightIndex = index;
563
+ if (!noFocus) this._focusMatch(match);
564
+ if (((_this$_workbook$getAc2 = this._workbook.getActiveSheet()) === null || _this$_workbook$getAc2 === void 0 ? void 0 : _this$_workbook$getAc2.getSheetId()) === match.range.subUnitId) this._updateCurrentHighlightShape(this._activeHighlightIndex);
565
+ return match;
566
+ }
567
+ this._matchesPosition = 0;
568
+ this._updateCurrentHighlightShape();
569
+ return null;
570
+ }
571
+ moveToPreviousMatch(params) {
572
+ var _params$loop2, _params$stayIfOnMatch2, _params$noFocus2, _params$ignoreSelecti2;
573
+ if (!this._matches.length) return null;
574
+ const loop = (_params$loop2 = params === null || params === void 0 ? void 0 : params.loop) !== null && _params$loop2 !== void 0 ? _params$loop2 : false;
575
+ const stayIfOnMatch = (_params$stayIfOnMatch2 = params === null || params === void 0 ? void 0 : params.stayIfOnMatch) !== null && _params$stayIfOnMatch2 !== void 0 ? _params$stayIfOnMatch2 : false;
576
+ const noFocus = (_params$noFocus2 = params === null || params === void 0 ? void 0 : params.noFocus) !== null && _params$noFocus2 !== void 0 ? _params$noFocus2 : false;
577
+ const ignoreSelection = (_params$ignoreSelecti2 = params === null || params === void 0 ? void 0 : params.ignoreSelection) !== null && _params$ignoreSelecti2 !== void 0 ? _params$ignoreSelecti2 : false;
578
+ const matchToMove = this._findPreviousMatch(loop, stayIfOnMatch, ignoreSelection);
579
+ if (matchToMove) {
580
+ var _this$_workbook$getAc3;
581
+ const [match, index] = matchToMove;
582
+ this._matchesPosition = index + 1;
583
+ if (this._query.findScope === _univerjs_find_replace.FindScope.UNIT) this._activeHighlightIndex = this._matchesByWorksheet.get(match.range.subUnitId).findIndex((m) => m === match);
584
+ else this._activeHighlightIndex = index;
585
+ if (!noFocus) this._focusMatch(match);
586
+ if (((_this$_workbook$getAc3 = this._workbook.getActiveSheet()) === null || _this$_workbook$getAc3 === void 0 ? void 0 : _this$_workbook$getAc3.getSheetId()) === match.range.subUnitId) this._updateCurrentHighlightShape(this._activeHighlightIndex);
587
+ return match;
588
+ }
589
+ this._matchesPosition = 0;
590
+ this._updateCurrentHighlightShape();
591
+ return null;
592
+ }
593
+ _findPreviousMatch(loop = false, stayIfOnMatch = false, ignoreSelection = false) {
594
+ var _this$_workbook$getAc4;
595
+ if (this.currentMatch) {
596
+ const currentMatchIndex = this._matches.findIndex((match) => match === this.currentMatch);
597
+ if (stayIfOnMatch) return [this.currentMatch, currentMatchIndex];
598
+ const nextMatchIndex = currentMatchIndex - 1;
599
+ if (!loop && nextMatchIndex < 0) return null;
600
+ const length = this._matches.length;
601
+ const modded = (nextMatchIndex + length) % length;
602
+ return [this._matches[modded], modded];
603
+ }
604
+ const lastSelection = this._workbookSelections.getCurrentLastSelection();
605
+ if (ignoreSelection || !lastSelection) {
606
+ const lastIndex = this._matches.length - 1;
607
+ return [this._matches[lastIndex], lastIndex];
608
+ }
609
+ if (this._query.findScope !== _univerjs_find_replace.FindScope.UNIT) return this._findPreviousMatchByRange(this._matches, lastSelection.range);
610
+ const currentSheetId = (_this$_workbook$getAc4 = this._workbook.getActiveSheet()) === null || _this$_workbook$getAc4 === void 0 ? void 0 : _this$_workbook$getAc4.getSheetId();
611
+ if (!currentSheetId) return null;
612
+ const worksheetThatHasMatch = this._findPreviousWorksheetThatHasAMatch(currentSheetId, loop);
613
+ if (!worksheetThatHasMatch) return null;
614
+ return this._findPreviousMatchByRange(this._matchesByWorksheet.get(worksheetThatHasMatch), lastSelection.range);
615
+ }
616
+ _findNextMatch(loop = false, stayIfOnMatch = false, ignoreSelection = false) {
617
+ var _this$_workbook$getAc5;
618
+ if (this.currentMatch) {
619
+ const currentMatchIndex = this._matches.findIndex((match) => match === this.currentMatch);
620
+ if (stayIfOnMatch) return [this.currentMatch, currentMatchIndex];
621
+ const nextMatchIndex = currentMatchIndex + 1;
622
+ const length = this._matches.length;
623
+ if (!loop && nextMatchIndex >= length) return null;
624
+ const modded = nextMatchIndex % length;
625
+ return [this._matches[modded], modded];
626
+ }
627
+ const last = this._workbookSelections.getCurrentLastSelection();
628
+ if (ignoreSelection || !last) return [this._matches[0], 0];
629
+ if (this._query.findScope !== _univerjs_find_replace.FindScope.UNIT) return this._findNextMatchByRange(this._matches, last.range, stayIfOnMatch);
630
+ const currentSheetId = (_this$_workbook$getAc5 = this._workbook.getActiveSheet()) === null || _this$_workbook$getAc5 === void 0 ? void 0 : _this$_workbook$getAc5.getSheetId();
631
+ if (!currentSheetId) return null;
632
+ const worksheetThatHasMatch = this._findNextWorksheetThatHasAMatch(currentSheetId, loop);
633
+ if (!worksheetThatHasMatch) return null;
634
+ return this._findNextMatchByRange(this._matchesByWorksheet.get(worksheetThatHasMatch), last.range);
635
+ }
636
+ _findPreviousWorksheetThatHasAMatch(currentWorksheet, loop = false) {
637
+ const rawWorksheetsInOrder = this._workbook.getSheetOrders();
638
+ const currentSheetIndex = rawWorksheetsInOrder.findIndex((sheet) => sheet === currentWorksheet);
639
+ const first = (loop ? (0, _univerjs_core.rotate)(rawWorksheetsInOrder, currentSheetIndex + 1) : rawWorksheetsInOrder.slice(0, currentSheetIndex + 1)).findLast((worksheet) => this._matchesByWorksheet.has(worksheet));
640
+ return first !== null && first !== void 0 ? first : null;
641
+ }
642
+ _findNextWorksheetThatHasAMatch(currentWorksheet, loop = false) {
643
+ const rawWorksheetsInOrder = this._workbook.getSheetOrders();
644
+ const currentSheetIndex = rawWorksheetsInOrder.findIndex((sheet) => sheet === currentWorksheet);
645
+ const first = (loop ? (0, _univerjs_core.rotate)(rawWorksheetsInOrder, currentSheetIndex) : rawWorksheetsInOrder.slice(currentSheetIndex)).find((worksheet) => this._matchesByWorksheet.has(worksheet));
646
+ return first !== null && first !== void 0 ? first : null;
647
+ }
648
+ _findNextMatchByRange(matches, range, stayIfOnMatch = false) {
649
+ const findByRow = this._query.findDirection === _univerjs_find_replace.FindDirection.ROW;
650
+ let index = matches.findIndex((match) => {
651
+ const matchRange = match.range.range;
652
+ if (!(findByRow ? isBehindPositionWithRowPriority(range, matchRange) : isBehindPositionWithColumnPriority(range, matchRange))) return false;
653
+ const isSame = isSamePosition(range, matchRange);
654
+ return stayIfOnMatch ? isSame : !isSame;
655
+ });
656
+ if (index === -1) index = matches.length - 1;
657
+ const match = matches[index];
658
+ return [match, this._matches.findIndex((m) => m === match)];
659
+ }
660
+ _findPreviousMatchByRange(matches, range, stayIfOnMatch = false) {
661
+ const findByRow = this._query.findDirection === _univerjs_find_replace.FindDirection.ROW;
662
+ let index = this._matches.findLastIndex((match) => {
663
+ const matchRange = match.range.range;
664
+ if (!(findByRow ? isBeforePositionWithRowPriority(range, matchRange) : isBeforePositionWithColumnPriority(range, matchRange))) return false;
665
+ const isSame = isSamePosition(range, matchRange);
666
+ return stayIfOnMatch ? isSame : !isSame;
667
+ });
668
+ if (index === -1) index = 0;
669
+ const match = matches[index];
670
+ return [match, this._matches.findIndex((m) => m === match)];
671
+ }
672
+ async replace(replaceString) {
673
+ if (this._matchesCount === 0 || !this.currentMatch || !this._query || !this.currentMatch.replaceable) return false;
674
+ const range = this.currentMatch.range;
675
+ const targetWorksheet = this._workbook.getSheetBySheetId(this.currentMatch.range.subUnitId);
676
+ const newContent = this._getReplacedCellData(this.currentMatch, targetWorksheet, this._query.findBy === _univerjs_find_replace.FindBy.FORMULA, this._query.findString, replaceString, this._query.caseSensitive ? "g" : "ig");
677
+ const params = {
678
+ unitId: this.currentMatch.unitId,
679
+ subUnitId: range.subUnitId,
680
+ value: { [range.range.startRow]: { [range.range.startColumn]: newContent } }
681
+ };
682
+ return this._commandService.executeCommand(_univerjs_sheets.SetRangeValuesCommand.id, params);
683
+ }
684
+ async replaceAll(replaceString) {
685
+ if (this._matchesCount === 0 || !this._query) return {
686
+ success: 0,
687
+ failure: 0
688
+ };
689
+ const unitId = this._workbook.getUnitId();
690
+ const { findString, caseSensitive, findBy } = this._query;
691
+ const shouldReplaceFormula = findBy === _univerjs_find_replace.FindBy.FORMULA;
692
+ const replaceFlag = caseSensitive ? "g" : "ig";
693
+ const replacements = [];
694
+ (0, _univerjs_core.groupBy)(this._matches.filter((m) => m.replaceable), (match) => match.range.subUnitId).forEach((matches, subUnitId) => {
695
+ const matrix = new _univerjs_core.ObjectMatrix();
696
+ const worksheet = this._workbook.getSheetBySheetId(subUnitId);
697
+ matches.forEach((match) => {
698
+ const { startColumn, startRow } = match.range.range;
699
+ const newCellData = this._getReplacedCellData(match, worksheet, shouldReplaceFormula, findString, replaceString, replaceFlag);
700
+ if (newCellData) matrix.setValue(startRow, startColumn, newCellData);
701
+ });
702
+ replacements.push({
703
+ count: matches.length,
704
+ subUnitId,
705
+ value: matrix.getMatrix()
706
+ });
707
+ });
708
+ if (!replacements) return {
709
+ success: 0,
710
+ failure: 0
711
+ };
712
+ return this._commandService.executeCommand(SheetReplaceCommand.id, {
713
+ unitId,
714
+ replacements
715
+ });
716
+ }
717
+ _getReplacedCellData(match, worksheet, shouldReplaceFormula, findString, replaceString, replaceFlag) {
718
+ var _currentContent$p;
719
+ const { startRow, startColumn } = match.range.range;
720
+ const currentContent = worksheet.getCellRaw(startRow, startColumn);
721
+ if (match.isFormula) {
722
+ if (!shouldReplaceFormula) return null;
723
+ return {
724
+ f: currentContent.f.replace(new RegExp(escapeRegExp(findString), replaceFlag), replaceString),
725
+ v: null
726
+ };
727
+ }
728
+ if (!!((_currentContent$p = currentContent.p) === null || _currentContent$p === void 0 ? void 0 : _currentContent$p.body)) {
729
+ const clonedRichText = _univerjs_core.Tools.deepClone(currentContent.p);
730
+ (0, _univerjs_core.replaceInDocumentBody)(clonedRichText.body, findString, replaceString, this._query.caseSensitive);
731
+ return { p: clonedRichText };
732
+ }
733
+ return { v: currentContent.v.toString().replace(new RegExp(escapeRegExp(findString), replaceFlag), replaceString) };
734
+ }
735
+ };
736
+ SheetFindModel = __decorate([
737
+ __decorateParam(2, _univerjs_core.IUniverInstanceService),
738
+ __decorateParam(3, _univerjs_engine_render.IRenderManagerService),
739
+ __decorateParam(4, _univerjs_core.ICommandService),
740
+ __decorateParam(5, _univerjs_core.IContextService),
741
+ __decorateParam(6, (0, _univerjs_core.Inject)(_univerjs_core.ThemeService)),
742
+ __decorateParam(7, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetsSelectionsService))
743
+ ], SheetFindModel);
744
+ function escapeRegExp(text) {
745
+ return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
746
+ }
747
+ /**
748
+ * This module is responsible for searching and replacing in the sheets.
749
+ * It also adds the search results to the search view by highlighting them.
750
+ */
751
+ let SheetsFindReplaceProvider = class SheetsFindReplaceProvider extends _univerjs_core.Disposable {
752
+ constructor(_univerInstanceService, _renderManagerService, _injector) {
753
+ super();
754
+ this._univerInstanceService = _univerInstanceService;
755
+ this._renderManagerService = _renderManagerService;
756
+ this._injector = _injector;
757
+ _defineProperty(this, "_findModelsByUnitId", /* @__PURE__ */ new Map());
758
+ }
759
+ async find(query) {
760
+ this._terminate();
761
+ const workbook = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
762
+ if (!workbook) return [];
763
+ const parsedQuery = this._preprocessQuery(query);
764
+ const skeletonManagerService = this._renderManagerService.getRenderById(workbook.getUnitId()).with(_univerjs_sheets_ui.SheetSkeletonManagerService);
765
+ const sheetFind = this._injector.createInstance(SheetFindModel, workbook, skeletonManagerService);
766
+ this._findModelsByUnitId.set(workbook.getUnitId(), sheetFind);
767
+ sheetFind.start(parsedQuery);
768
+ return [sheetFind];
769
+ }
770
+ terminate() {
771
+ this._terminate();
772
+ }
773
+ _terminate() {
774
+ this._findModelsByUnitId.forEach((model) => model.dispose());
775
+ this._findModelsByUnitId.clear();
776
+ }
777
+ /**
778
+ * Parsed the query object before do actual searching in favor of performance.
779
+ * @param query the raw query object
780
+ * @returns the parsed query object
781
+ */
782
+ _preprocessQuery(query) {
783
+ let findString = query.caseSensitive ? query.findString : query.findString.toLowerCase();
784
+ findString = findString.trim();
785
+ return {
786
+ ...query,
787
+ findString
788
+ };
789
+ }
790
+ };
791
+ SheetsFindReplaceProvider = __decorate([
792
+ __decorateParam(0, _univerjs_core.IUniverInstanceService),
793
+ __decorateParam(1, _univerjs_engine_render.IRenderManagerService),
794
+ __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_core.Injector))
795
+ ], SheetsFindReplaceProvider);
796
+ const VALUE_PASSING_OBJECT = {
797
+ hit: false,
798
+ replaceable: false,
799
+ isFormula: false,
800
+ rawData: null
801
+ };
802
+ /**
803
+ * This function determines if a cell's content matches what is searched for.
804
+ * @param worksheet worksheet the Worksheet to search
805
+ * @param row the row index
806
+ * @param col the column index
807
+ * @param query the parsed query object
808
+ * @returns if the cell is hit, replaceable and is a formula
809
+ */
810
+ function hitCell(worksheet, row, col, query, cellData) {
811
+ const { findBy } = query;
812
+ const findByFormula = findBy === _univerjs_find_replace.FindBy.FORMULA;
813
+ const rawData = worksheet.getCellRaw(row, col);
814
+ VALUE_PASSING_OBJECT.rawData = rawData;
815
+ if (!!(rawData === null || rawData === void 0 ? void 0 : rawData.f)) {
816
+ VALUE_PASSING_OBJECT.isFormula = true;
817
+ if (findByFormula) {
818
+ if (matchCellData({ v: rawData.f }, query)) {
819
+ VALUE_PASSING_OBJECT.hit = true;
820
+ VALUE_PASSING_OBJECT.replaceable = true;
821
+ return VALUE_PASSING_OBJECT;
822
+ }
823
+ VALUE_PASSING_OBJECT.hit = false;
824
+ VALUE_PASSING_OBJECT.replaceable = false;
825
+ return VALUE_PASSING_OBJECT;
826
+ }
827
+ VALUE_PASSING_OBJECT.replaceable = false;
828
+ if (matchCellData(cellData, query)) VALUE_PASSING_OBJECT.hit = true;
829
+ else VALUE_PASSING_OBJECT.hit = false;
830
+ return VALUE_PASSING_OBJECT;
831
+ }
832
+ VALUE_PASSING_OBJECT.isFormula = false;
833
+ if (!matchCellData(cellData, query)) {
834
+ VALUE_PASSING_OBJECT.hit = false;
835
+ VALUE_PASSING_OBJECT.replaceable = false;
836
+ } else if (!rawData) {
837
+ VALUE_PASSING_OBJECT.hit = true;
838
+ VALUE_PASSING_OBJECT.replaceable = false;
839
+ } else {
840
+ VALUE_PASSING_OBJECT.hit = true;
841
+ VALUE_PASSING_OBJECT.replaceable = true;
842
+ }
843
+ return VALUE_PASSING_OBJECT;
844
+ }
845
+ function matchCellData(cellData, query) {
846
+ let value = extractPureValue(cellData);
847
+ if (!value) return false;
848
+ if (query.matchesTheWholeCell) {
849
+ value = trimLeadingTrailingWhitespace(value);
850
+ return query.caseSensitive ? value === query.findString : value.toLowerCase() === query.findString;
851
+ }
852
+ return query.caseSensitive ? value.indexOf(query.findString) > -1 : value.toLowerCase().indexOf(query.findString) > -1;
853
+ }
854
+ function extractPureValue(cell) {
855
+ var _cell$p$body$dataStre, _cell$p;
856
+ const rawValue = (_cell$p$body$dataStre = cell === null || cell === void 0 || (_cell$p = cell.p) === null || _cell$p === void 0 || (_cell$p = _cell$p.body) === null || _cell$p === void 0 ? void 0 : _cell$p.dataStream) !== null && _cell$p$body$dataStre !== void 0 ? _cell$p$body$dataStre : cell === null || cell === void 0 ? void 0 : cell.v;
857
+ if (typeof rawValue === "number") return `${rawValue}`;
858
+ if (typeof rawValue === "boolean") return rawValue ? "1" : "0";
859
+ return rawValue;
860
+ }
861
+ /**
862
+ * Trim only white spaces but not line breaks from the start and end of a string.
863
+ * @param value the string to be trimmed
864
+ */
865
+ function trimLeadingTrailingWhitespace(value) {
866
+ return value.replace(/^ +/g, "").replace(/ +$/g, "");
867
+ }
868
+
869
+ //#endregion
870
+ //#region package.json
871
+ var name = "@univerjs/sheets-find-replace";
872
+ var version = "0.21.0";
873
+
874
+ //#endregion
875
+ //#region src/config/config.ts
876
+ /**
877
+ * Copyright 2023-present DreamNum Co., Ltd.
878
+ *
879
+ * Licensed under the Apache License, Version 2.0 (the "License");
880
+ * you may not use this file except in compliance with the License.
881
+ * You may obtain a copy of the License at
882
+ *
883
+ * http://www.apache.org/licenses/LICENSE-2.0
884
+ *
885
+ * Unless required by applicable law or agreed to in writing, software
886
+ * distributed under the License is distributed on an "AS IS" BASIS,
887
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
888
+ * See the License for the specific language governing permissions and
889
+ * limitations under the License.
890
+ */
891
+ const SHEETS_FIND_REPLACE_PLUGIN_CONFIG_KEY = "sheets-find-replace.config";
892
+ const configSymbol = Symbol(SHEETS_FIND_REPLACE_PLUGIN_CONFIG_KEY);
893
+ const defaultPluginConfig = {};
894
+
895
+ //#endregion
896
+ //#region src/plugin.ts
897
+ let UniverSheetsFindReplacePlugin = class UniverSheetsFindReplacePlugin extends _univerjs_core.Plugin {
898
+ constructor(_config = defaultPluginConfig, _injector, _configService) {
899
+ super();
900
+ this._config = _config;
901
+ this._injector = _injector;
902
+ this._configService = _configService;
903
+ const { ...rest } = (0, _univerjs_core.merge)({}, defaultPluginConfig, this._config);
904
+ this._configService.setConfig(SHEETS_FIND_REPLACE_PLUGIN_CONFIG_KEY, rest);
905
+ }
906
+ onStarting() {
907
+ [[SheetsFindReplaceController]].forEach((d) => this._injector.add(d));
908
+ }
909
+ onSteady() {
910
+ this._injector.get(SheetsFindReplaceController);
911
+ }
912
+ };
913
+ _defineProperty(UniverSheetsFindReplacePlugin, "pluginName", "SHEET_FIND_REPLACE_PLUGIN");
914
+ _defineProperty(UniverSheetsFindReplacePlugin, "packageName", name);
915
+ _defineProperty(UniverSheetsFindReplacePlugin, "version", version);
916
+ _defineProperty(UniverSheetsFindReplacePlugin, "type", _univerjs_core.UniverInstanceType.UNIVER_SHEET);
917
+ UniverSheetsFindReplacePlugin = __decorate([
918
+ (0, _univerjs_core.DependentOn)(_univerjs_sheets.UniverSheetsPlugin, _univerjs_sheets.UniverSheetsPlugin, _univerjs_find_replace.UniverFindReplacePlugin),
919
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
920
+ __decorateParam(2, _univerjs_core.IConfigService)
921
+ ], UniverSheetsFindReplacePlugin);
922
+
923
+ //#endregion
924
+ exports.SheetReplaceCommand = SheetReplaceCommand;
925
+ Object.defineProperty(exports, 'SheetsFindReplaceController', {
926
+ enumerable: true,
927
+ get: function () {
928
+ return SheetsFindReplaceController;
929
+ }
930
+ });
931
+ Object.defineProperty(exports, 'UniverSheetsFindReplacePlugin', {
932
+ enumerable: true,
933
+ get: function () {
934
+ return UniverSheetsFindReplacePlugin;
935
+ }
936
+ });