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