@univerjs/sheets-find-replace 0.17.0 → 0.18.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/lib/cjs/facade.js +1 -1
- package/lib/cjs/index.js +1 -1
- package/lib/cjs/locale/ca-ES.js +1 -1
- package/lib/cjs/locale/en-US.js +1 -1
- package/lib/cjs/locale/es-ES.js +1 -1
- package/lib/cjs/locale/fa-IR.js +1 -1
- package/lib/cjs/locale/fr-FR.js +1 -1
- package/lib/cjs/locale/ja-JP.js +1 -1
- package/lib/cjs/locale/ko-KR.js +1 -1
- package/lib/cjs/locale/ru-RU.js +1 -1
- package/lib/cjs/locale/sk-SK.js +1 -1
- package/lib/cjs/locale/vi-VN.js +1 -1
- package/lib/cjs/locale/zh-CN.js +1 -1
- package/lib/cjs/locale/zh-TW.js +1 -1
- package/lib/es/facade.js +1 -101
- package/lib/es/index.js +1 -633
- package/lib/es/locale/ca-ES.js +1 -11
- package/lib/es/locale/en-US.js +1 -11
- package/lib/es/locale/es-ES.js +1 -11
- package/lib/es/locale/fa-IR.js +1 -11
- package/lib/es/locale/fr-FR.js +1 -11
- package/lib/es/locale/ja-JP.js +1 -11
- package/lib/es/locale/ko-KR.js +1 -11
- package/lib/es/locale/ru-RU.js +1 -11
- package/lib/es/locale/sk-SK.js +1 -11
- package/lib/es/locale/vi-VN.js +1 -11
- package/lib/es/locale/zh-CN.js +1 -11
- package/lib/es/locale/zh-TW.js +1 -11
- package/lib/facade.js +1 -101
- package/lib/index.js +1 -633
- package/lib/locale/ca-ES.js +1 -11
- package/lib/locale/en-US.js +1 -11
- package/lib/locale/es-ES.js +1 -11
- package/lib/locale/fa-IR.js +1 -11
- package/lib/locale/fr-FR.js +1 -11
- package/lib/locale/ja-JP.js +1 -11
- package/lib/locale/ko-KR.js +1 -11
- package/lib/locale/ru-RU.js +1 -11
- package/lib/locale/sk-SK.js +1 -11
- package/lib/locale/vi-VN.js +1 -11
- package/lib/locale/zh-CN.js +1 -11
- package/lib/locale/zh-TW.js +1 -11
- package/lib/types/commands/commands/sheet-replace.command.d.ts +17 -2
- package/lib/types/controllers/sheet-find-replace.controller.d.ts +21 -4
- package/lib/types/controllers/utils.d.ts +17 -2
- package/lib/types/facade/f-text-finder.d.ts +19 -2
- package/lib/types/facade/f-univer.d.ts +15 -0
- package/lib/types/locale/ca-ES.d.ts +16 -1
- package/lib/types/locale/es-ES.d.ts +16 -1
- package/lib/types/locale/fa-IR.d.ts +16 -1
- package/lib/types/locale/fr-FR.d.ts +16 -1
- package/lib/types/locale/ja-JP.d.ts +16 -1
- package/lib/types/locale/ko-KR.d.ts +16 -1
- package/lib/types/locale/ru-RU.d.ts +16 -1
- package/lib/types/locale/sk-SK.d.ts +16 -1
- package/lib/types/locale/vi-VN.d.ts +16 -1
- package/lib/types/locale/zh-TW.d.ts +16 -1
- package/lib/types/plugin.d.ts +16 -1
- package/lib/types/views/shapes/find-replace-highlight.shape.d.ts +18 -2
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/lib/umd/locale/ca-ES.js +1 -1
- package/lib/umd/locale/en-US.js +1 -1
- package/lib/umd/locale/es-ES.js +1 -1
- package/lib/umd/locale/fa-IR.js +1 -1
- package/lib/umd/locale/fr-FR.js +1 -1
- package/lib/umd/locale/ja-JP.js +1 -1
- package/lib/umd/locale/ko-KR.js +1 -1
- package/lib/umd/locale/ru-RU.js +1 -1
- package/lib/umd/locale/sk-SK.js +1 -1
- package/lib/umd/locale/vi-VN.js +1 -1
- package/lib/umd/locale/zh-CN.js +1 -1
- package/lib/umd/locale/zh-TW.js +1 -1
- package/package.json +11 -10
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(f,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("@univerjs/engine-render"),require("@univerjs/find-replace"),require("@univerjs/sheets-ui"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","@univerjs/engine-render","@univerjs/find-replace","@univerjs/sheets-ui","rxjs"],a):(f=typeof globalThis<"u"?globalThis:f||self,a(f.UniverSheetsFindReplace={},f.UniverCore,f.UniverSheets,f.UniverEngineRender,f.UniverFindReplace,f.UniverSheetsUi,f.rxjs))})(this,(function(f,a,p,y,S,F,k){"use strict";var Se=Object.defineProperty;var me=(f,a,p)=>a in f?Se(f,a,{enumerable:!0,configurable:!0,writable:!0,value:p}):f[a]=p;var m=(f,a,p)=>me(f,typeof a!="symbol"?a+"":a,p);const P={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(p.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}}class K extends y.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})`;y.Rect.drawWith(t,{width:this.width,height:this.height,fill:n,stroke:i?r:void 0,strokeWidth:i?2:0,evented:!1})}}function A(h,e){return h.startRow===e.startRow&&h.startColumn===e.startColumn}function D(h,e){return h.startRow<e.startRow||h.startRow===e.startRow&&h.startColumn<=e.startColumn}function N(h,e){return h.startColumn<e.startColumn||h.startColumn===e.startColumn&&h.startRow<=e.startRow}function Q(h,e){return h.startRow>e.startRow||h.startRow===e.startRow&&h.startColumn>=e.startColumn}function X(h,e){return h.startColumn>e.startColumn||h.startColumn===e.startColumn&&h.startRow>=e.startRow}function z(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 J=Object.getOwnPropertyDescriptor,x=(h,e,t,i)=>{for(var n=i>1?void 0:i?J(e,t):e,r=h.length-1,s;r>=0;r--)(s=h[r])&&(n=s(n)||n);return n},C=(h,e)=>(t,i)=>e(t,i,h);f.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(W);this._provider=t,this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(t)),this.disposeWithMe(this._contextService.subscribeContextValue$(a.EDITOR_ACTIVATED).pipe(k.filter(i=>!!i)).subscribe(()=>this._findReplaceController.closePanel()))}_initCommands(){[P].forEach(t=>this.disposeWithMe(this._commandService.registerCommand(t)))}},f.SheetsFindReplaceController=x([C(0,a.Inject(a.Injector)),C(1,a.Inject(S.FindReplaceController)),C(2,a.IContextService),C(3,S.IFindReplaceService),C(4,a.ICommandService)],f.SheetsFindReplaceController);const Z="sheets-find-replace-provider",ee=1e4;let B=class extends S.FindModel{constructor(e,t,i,n,r,s,o,c){super();m(this,"_matchesUpdate$",new k.Subject);m(this,"matchesUpdate$",this._matchesUpdate$.asObservable());m(this,"_activelyChangingMatch$",new k.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===S.FindBy.FORMULA?this._toggleDisplayRawFormula(!0):this._toggleDisplayRawFormula(!1),e.findScope){case S.FindScope.UNIT:this.findInWorkbook(e);break;case S.FindScope.SUBUNIT:default:this.findInActiveWorksheet(e);break}}focusSelection(){const e=this.currentMatch;e&&this._commandService.executeCommand(p.SelectRangeCommand.id,{unitId:e.unitId,subUnit:e.range.subUnitId,range:e.range.range})}_toggleDisplayRawFormula(e){this._contextService.setContextValue(y.RENDER_RAW_FORMULA_KEY,e)}findInWorkbook(e){const t=this._workbook.getUnitId();let i,n=!0;const r=()=>{const s=this._workbook.getSheets().filter(o=>!o.isSheetHidden()).map(o=>{const c=this._findInWorksheet(o,e,t),d=o.getSheetId(),{results:l}=c;return l.length?this._matchesByWorksheet.set(d,c.results):this._matchesByWorksheet.delete(d),c});this._matches=s.map(o=>o.results).flat(),this._updateFindHighlight(),n?(i={results:this._matches},n=!1):this._matchesUpdate$.next(this._matches)};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>{this._updateFindHighlight(),this._updateCurrentHighlightShape(this._activeHighlightIndex)})),this.disposeWithMe(a.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(k.filter(([s,o])=>s.id===p.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(k.filter(([s])=>s.type===a.CommandType.MUTATION&&s.params.unitId===this._workbook.getUnitId()),k.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=>!z(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(k.merge(a.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(k.filter(([c])=>{if(c.type===a.CommandType.MUTATION&&c.params.unitId===this._workbook.getUnitId())return!0;if(c.id===p.SetSelectionsOperation.id&&c.params.unitId===t){const d=i();return d===!1&&s===!1?!1:(s=d,!0)}return!1})),this._workbook.activeSheet$.pipe(k.skip(1))).pipe(k.debounceTime(200)).subscribe(()=>o())),o(),n}_findInRange(e,t,i,n,r){const s=[],o=e.getSheetId(),c=(t.findDirection===S.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:w,replaceable:M,isFormula:R}=te(e,l,u,t,I);if(w){const H={provider:Z,unitId:n,replaceable:M,isFormula:R,range:{subUnitId:o,range:{startRow:l,startColumn:u,endColumn:u+(g!=null?g:1)-1,endRow:l+(v!=null?v:1)-1}}};s.push(H)}}return{results:s}}_findInSelections(e,t,i,n){const{findDirection:r}=i,s=r===S.FindDirection.ROW?D:N,o=new Set;return{results:t.map(d=>this._findInRange(e,i,d.range,n,(l,u)=>{const g=`${l}-${u}`;return o.has(g)?!0:(o.add(g),!1)}).results).flat().sort((d,l)=>s(d.range.range,l.range.range)?-1:1)}}_findInWorksheet(e,t,i){const n=e.getRowCount(),r=e.getColumnCount(),s={startRow:0,startColumn:0,endRow:n-1,endColumn:r-1};return this._findInRange(e,t,s,i)}_disposeHighlights(){var e;this._highlightShapes.forEach(t=>{var i;(i=t.getScene())==null||i.makeDirty(),t.dispose()}),this._highlightShapes=[],(e=this._currentHighlightShape)==null||e.dispose(),this._currentHighlightShape=null}_updateFindHighlight(){var u;this._disposeHighlights();const e=(u=this._sheetSkeletonManagerService.getCurrent())==null?void 0:u.skeleton;if(!e)return;const t=this._workbook.getUnitId(),i=this._renderManagerService.getRenderById(t);if(i==null)return;const{scene:n}=i,r=this._matches,s=this._themeService.getColorFromTheme("yellow.400"),o=new a.ColorKit(s).toRgb(),c=this._workbook.getActiveSheet();if(!c)return;const d=c.getSheetId(),l=r.filter(g=>g.range.subUnitId===d).map((g,v)=>{const{startColumn:I,startRow:w,endColumn:M,endRow:R}=g.range.range,H=F.getCoordByCell(w,I,n,e),ae=F.getCoordByCell(R,M,n,e),{startX:G,startY:Y}=H,{endX:le,endY:de}=ae;let E=!0;for(let b=w;b<=R;b++)if(c.getRowRawVisible(b)){E=!1;break}let O=!0;for(let b=I;b<=M;b++)if(c.getColVisible(b)){O=!1;break}const ue=E||O,ge=O?2:le-G,fe=E?2:de-Y,_e={left:G,top:Y,color:o,width:ge,height:fe,evented:!1,inHiddenRange:ue,zIndex:ee};return new K(`find-highlight-${v}`,_e)});n.addObjects(l),this._highlightShapes=l,n.makeDirty()}_updateCurrentHighlightShape(e){var t;if((t=this._currentHighlightShape)==null||t.setShapeProps({activated:!1}),this._currentHighlightShape=null,e!==void 0){const i=this._highlightShapes[e];if(!i)return;this._currentHighlightShape=i,i.setShapeProps({activated:!0})}}_getSheetObject(){return F.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(p.SetWorksheetActivateCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:t},{fromFindReplace:!0}),this._commandService.executeCommand(F.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===S.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===S.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!==S.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!==S.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===S.FindDirection.ROW;let r=e.findIndex(o=>{const c=o.range.range;if(!(n?D(t,c):N(t,c)))return!1;const l=A(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===S.FindDirection.ROW;let r=this._matches.findLastIndex(o=>{const c=o.range.range;if(!(n?Q(t,c):X(t,c)))return!1;const l=A(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===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]:n}}};return this._commandService.executeCommand(p.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===S.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:w,startRow:M}=I.range.range,R=this._getReplacedCellData(I,v,s,i,e,o);R&&g.setValue(M,w,R)}),c.push({count:l.length,subUnitId:u,value:g.getMatrix()})}),c?this._commandService.executeCommand(P.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(j(n),s),r),v:null}:null;if(!!((v=l.p)!=null&&v.body)){const I=a.Tools.deepClone(l.p);return a.replaceInDocumentBody(I.body,n,r,this._query.caseSensitive),{p:I}}return{v:l.v.toString().replace(new RegExp(j(n),s),r)}}};B=x([C(2,a.IUniverInstanceService),C(3,y.IRenderManagerService),C(4,a.ICommandService),C(5,a.IContextService),C(6,a.Inject(a.ThemeService)),C(7,a.Inject(p.SheetsSelectionsService))],B);function j(h){return h.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}let W=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.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET);if(!t)return[];const i=this._preprocessQuery(e),n=this._renderManagerService.getRenderById(t.getUnitId()).with(F.SheetSkeletonManagerService),r=this._injector.createInstance(B,t,n);return this._findModelsByUnitId.set(t.getUnitId(),r),r.start(i),[r]}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=x([C(0,a.IUniverInstanceService),C(1,y.IRenderManagerService),C(2,a.Inject(a.Injector))],W);const _={hit:!1,replaceable:!1,isFormula:!1,rawData:null};function te(h,e,t,i,n){const{findBy:r}=i,s=r===S.FindBy.FORMULA,o=h.getCellRaw(e,t);return _.rawData=o,!(o!=null&&o.f)?(_.isFormula=!1,T(n,i)?o?(_.hit=!0,_.replaceable=!0):(_.hit=!0,_.replaceable=!1):(_.hit=!1,_.replaceable=!1),_):(_.isFormula=!0,s?T({v:o.f},i)?(_.hit=!0,_.replaceable=!0,_):(_.hit=!1,_.replaceable=!1,_):(_.replaceable=!1,T(n,i)?_.hit=!0:_.hit=!1,_))}function T(h,e){let t=ie(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 ie(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 ne(h){return h.replace(/^ +/g,"").replace(/ +$/g,"")}const $={name:"@univerjs/sheets-find-replace",version:"0.17.0"},se="sheets-find-replace.config",L={};var re=Object.defineProperty,oe=Object.getOwnPropertyDescriptor,he=(h,e,t)=>e in h?re(h,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):h[e]=t,ce=(h,e,t,i)=>{for(var n=i>1?void 0:i?oe(e,t):e,r=h.length-1,s;r>=0;r--)(s=h[r])&&(n=s(n)||n);return n},V=(h,e)=>(t,i)=>e(t,i,h),U=(h,e,t)=>he(h,typeof e!="symbol"?e+"":e,t);f.UniverSheetsFindReplacePlugin=class extends a.Plugin{constructor(e=L,t,i){super(),this._config=e,this._injector=t,this._configService=i;const{...n}=a.merge({},L,this._config);this._configService.setConfig(se,n)}onStarting(){[[f.SheetsFindReplaceController]].forEach(e=>this._injector.add(e))}onSteady(){this._injector.get(f.SheetsFindReplaceController)}},U(f.UniverSheetsFindReplacePlugin,"pluginName","SHEET_FIND_REPLACE_PLUGIN"),U(f.UniverSheetsFindReplacePlugin,"packageName",$.name),U(f.UniverSheetsFindReplacePlugin,"version",$.version),U(f.UniverSheetsFindReplacePlugin,"type",a.UniverInstanceType.UNIVER_SHEET),f.UniverSheetsFindReplacePlugin=ce([a.DependentOn(p.UniverSheetsPlugin,p.UniverSheetsPlugin,S.UniverFindReplacePlugin),V(1,a.Inject(a.Injector)),V(2,a.IConfigService)],f.UniverSheetsFindReplacePlugin),f.SheetReplaceCommand=P,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/sheets`),require(`@univerjs/engine-render`),require(`@univerjs/find-replace`),require(`@univerjs/sheets-ui`),require(`rxjs`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets`,`@univerjs/engine-render`,`@univerjs/find-replace`,`@univerjs/sheets-ui`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsFindReplace={},e.UniverCore,e.UniverSheets,e.UniverEngineRender,e.UniverFindReplace,e.UniverSheetsUi,e.rxjs))})(this,function(e,t,n,r,i,a,o){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let s={id:`sheet.command.replace`,type:t.CommandType.COMMAND,handler:async(e,r)=>{let i=e.get(t.IUndoRedoService),a=e.get(t.ICommandService),{unitId:o,replacements:s}=r,l=i.__tempBatchingUndoRedo(o),u=await Promise.all(s.map(e=>a.executeCommand(n.SetRangeValuesCommand.id,{unitId:o,subUnitId:e.subUnitId,value:e.value})));return l.dispose(),c(u,s)}};function c(e,t){let n=0,r=0;return e.forEach((e,i)=>{let a=t[i].count;e?n+=a:r+=a}),{success:n,failure:r}}function l(e){"@babel/helpers - typeof";return l=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},l(e)}function u(e,t){if(l(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(l(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function d(e){var t=u(e,`string`);return l(t)==`symbol`?t:t+``}function f(e,t,n){return(t=d(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var p=class extends r.Shape{constructor(e,t){super(e,t),f(this,`_activated`,!1),f(this,`_inHiddenRange`,!1),f(this,`_color`,void 0),t&&this.setShapeProps(t)}setShapeProps(e){this._activated=!!e.activated,e.inHiddenRange!==void 0&&(this._inHiddenRange=e.inHiddenRange),e.color!==void 0&&(this._color=e.color),this.transformByState({width:e.width,height:e.height})}_draw(e){let t=this._activated,n=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 0.35)`,i=`rgb(${this._color.r}, ${this._color.g}, ${this._color.b})`;r.Rect.drawWith(e,{width:this.width,height:this.height,fill:n,stroke:t?i:void 0,strokeWidth:t?2:0,evented:!1})}};function m(e,t){return e.startRow===t.startRow&&e.startColumn===t.startColumn}function h(e,t){return e.startRow<t.startRow||e.startRow===t.startRow&&e.startColumn<=t.startColumn}function g(e,t){return e.startColumn<t.startColumn||e.startColumn===t.startColumn&&e.startRow<=t.startRow}function _(e,t){return e.startRow>t.startRow||e.startRow===t.startRow&&e.startColumn>=t.startColumn}function v(e,t){return e.startColumn>t.startColumn||e.startColumn===t.startColumn&&e.startRow>=t.startRow}function y(e,n){let{range:r}=e,{startRow:i,startColumn:a}=r,o=n.getMergedCell(i,a);return o?t.Rectangle.equals(r,o):r.endRow===r.startRow&&r.endColumn===r.startColumn}function b(e,t){return function(n,r){t(n,r,e)}}function x(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let S=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._injector=e,this._findReplaceController=t,this._contextService=n,this._findReplaceService=r,this._commandService=i,f(this,`_provider`,void 0),this._init(),this._initCommands()}dispose(){super.dispose(),this._findReplaceController.closePanel(),this._provider.dispose()}_init(){let e=this._injector.createInstance(T);this._provider=e,this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(e)),this.disposeWithMe(this._contextService.subscribeContextValue$(t.EDITOR_ACTIVATED).pipe((0,o.filter)(e=>!!e)).subscribe(()=>this._findReplaceController.closePanel()))}_initCommands(){[s].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}};S=x([b(0,(0,t.Inject)(t.Injector)),b(1,(0,t.Inject)(i.FindReplaceController)),b(2,t.IContextService),b(3,i.IFindReplaceService),b(4,t.ICommandService)],S);let C=class extends i.FindModel{get _matchesCount(){return this._matches.length}get unitId(){return this._workbook.getUnitId()}get matchesCount(){return this._matchesCount}get matchesPosition(){return this._matchesPosition}get currentMatch(){return this._matchesPosition>0?this._matches[this._matchesPosition-1]:null}constructor(e,t,n,r,i,a,s,c){super(),this._workbook=e,this._sheetSkeletonManagerService=t,this._univerInstanceService=n,this._renderManagerService=r,this._commandService=i,this._contextService=a,this._themeService=s,f(this,`_matchesUpdate$`,new o.Subject),f(this,`matchesUpdate$`,this._matchesUpdate$.asObservable()),f(this,`_activelyChangingMatch$`,new o.Subject),f(this,`activelyChangingMatch$`,this._activelyChangingMatch$.asObservable()),f(this,`_matchesByWorksheet`,new Map),f(this,`_matches`,[]),f(this,`_matchesPosition`,0),f(this,`_activeHighlightIndex`,-1),f(this,`_highlightShapes`,[]),f(this,`_currentHighlightShape`,null),f(this,`_query`,null),f(this,`_workbookSelections`,void 0),this._workbookSelections=c.getWorkbookSelections(this.unitId)}dispose(){super.dispose(),this._disposeHighlights(),this._toggleDisplayRawFormula(!1)}getMatches(){return this._matches}start(e){switch(this._query=e,e.findBy===i.FindBy.FORMULA?this._toggleDisplayRawFormula(!0):this._toggleDisplayRawFormula(!1),e.findScope){case i.FindScope.UNIT:this.findInWorkbook(e);break;case i.FindScope.SUBUNIT:default:this.findInActiveWorksheet(e);break}}focusSelection(){let e=this.currentMatch;e&&this._commandService.executeCommand(n.SelectRangeCommand.id,{unitId:e.unitId,subUnit:e.range.subUnitId,range:e.range.range})}_toggleDisplayRawFormula(e){this._contextService.setContextValue(r.RENDER_RAW_FORMULA_KEY,e)}findInWorkbook(e){let r=this._workbook.getUnitId(),i,a=!0,s=()=>{this._matches=this._workbook.getSheets().filter(e=>!e.isSheetHidden()).map(t=>{let n=this._findInWorksheet(t,e,r),i=t.getSheetId(),{results:a}=n;return a.length?this._matchesByWorksheet.set(i,n.results):this._matchesByWorksheet.delete(i),n}).map(e=>e.results).flat(),this._updateFindHighlight(),a?(i={results:this._matches},a=!1):this._matchesUpdate$.next(this._matches)};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>{this._updateFindHighlight(),this._updateCurrentHighlightShape(this._activeHighlightIndex)})),this.disposeWithMe((0,t.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0,o.filter)(([e,t])=>e.id===n.SetWorksheetActiveOperation.id&&!(t!=null&&t.fromFindReplace))).subscribe(()=>{let e=this._workbook.getActiveSheet();if(!e)return;let t=e.getSheetId();this._matchesByWorksheet.has(t)&&this._findNextMatchOnActiveSheetChange(e)})),this.disposeWithMe((0,t.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0,o.filter)(([e])=>e.type===t.CommandType.MUTATION&&e.params.unitId===this._workbook.getUnitId()),(0,o.throttleTime)(600,void 0,{leading:!1,trailing:!0})).subscribe(()=>s())),s(),i}_findNextMatchOnActiveSheetChange(e){let t,n,r=0,i=this._matchesByWorksheet.get(e.getSheetId()),a=this._workbookSelections.getCurrentSelections();a!=null&&a.length?([t,r]=this._findNextMatchByRange(i,a[0].range),n=i.findIndex(e=>e===t)):(t=i[0],n=0,r=this._matches.findIndex(e=>e===t)),this._matchesPosition=r+1,this._activelyChangingMatch$.next(t),this._activeHighlightIndex=n,this._updateFindHighlight(),this._updateCurrentHighlightShape(n)}findInActiveWorksheet(e){let r=this._workbook.getUnitId(),i=()=>{var e;let t=this._workbook.getActiveSheet();if(!t)return!1;let n=this._workbookSelections.getCurrentSelections();return(e=n==null?void 0:n.some(e=>!y(e,t)))==null?!1:e},a,s=!0,c=!1,l=()=>{let t=this._workbook.getActiveSheet();if(!t)return{results:[]};let n=this.currentMatch;c=i();let o=this._workbookSelections.getCurrentSelections(),l=c?this._findInSelections(t,o,e,r):this._findInWorksheet(t,e,r);return this._matches=l.results,this._matchesPosition=this._tryRestoreLastMatchesPosition(n,this._matches),s?(a=l,s=!1):this._matchesUpdate$.next(this._matches),this._updateFindHighlight(),l};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>this._updateFindHighlight())),this.disposeWithMe((0,o.merge)((0,t.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0,o.filter)(([e])=>{if(e.type===t.CommandType.MUTATION&&e.params.unitId===this._workbook.getUnitId())return!0;if(e.id===n.SetSelectionsOperation.id&&e.params.unitId===r){let e=i();return e===!1&&c===!1?!1:(c=e,!0)}return!1})),this._workbook.activeSheet$.pipe((0,o.skip)(1))).pipe((0,o.debounceTime)(200)).subscribe(()=>l())),l(),a}_findInRange(e,t,n,r,a){let o=[],s=e.getSheetId(),c=(t.findDirection===i.FindDirection.COLUMN?e.iterateByColumn:e.iterateByRow).bind(e)(n);for(let n of c){let{row:i,col:c,colSpan:l,rowSpan:u,value:d}=n;if(a!=null&&a(i,c)||!d||e.getRowFiltered(i))continue;let{hit:f,replaceable:p,isFormula:m}=D(e,i,c,t,d);if(f){let e={provider:`sheets-find-replace-provider`,unitId:r,replaceable:p,isFormula:m,range:{subUnitId:s,range:{startRow:i,startColumn:c,endColumn:c+(l==null?1:l)-1,endRow:i+(u==null?1:u)-1}}};o.push(e)}}return{results:o}}_findInSelections(e,t,n,r){let{findDirection:a}=n,o=a===i.FindDirection.ROW?h:g,s=new Set;return{results:t.map(t=>this._findInRange(e,n,t.range,r,(e,t)=>{let n=`${e}-${t}`;return s.has(n)?!0:(s.add(n),!1)}).results).flat().sort((e,t)=>o(e.range.range,t.range.range)?-1:1)}}_findInWorksheet(e,t,n){let r=e.getRowCount(),i=e.getColumnCount(),a={startRow:0,startColumn:0,endRow:r-1,endColumn:i-1};return this._findInRange(e,t,a,n)}_disposeHighlights(){var e;this._highlightShapes.forEach(e=>{var t;(t=e.getScene())==null||t.makeDirty(),e.dispose()}),this._highlightShapes=[],(e=this._currentHighlightShape)==null||e.dispose(),this._currentHighlightShape=null}_updateFindHighlight(){var e;this._disposeHighlights();let n=(e=this._sheetSkeletonManagerService.getCurrent())==null?void 0:e.skeleton;if(!n)return;let r=this._workbook.getUnitId(),i=this._renderManagerService.getRenderById(r);if(i==null)return;let{scene:o}=i,s=this._matches,c=new t.ColorKit(this._themeService.getColorFromTheme(`yellow.400`)).toRgb(),l=this._workbook.getActiveSheet();if(!l)return;let u=l.getSheetId(),d=s.filter(e=>e.range.subUnitId===u).map((e,t)=>{let{startColumn:r,startRow:i,endColumn:s,endRow:u}=e.range.range,d=(0,a.getCoordByCell)(i,r,o,n),f=(0,a.getCoordByCell)(u,s,o,n),{startX:m,startY:h}=d,{endX:g,endY:_}=f,v=!0;for(let e=i;e<=u;e++)if(l.getRowRawVisible(e)){v=!1;break}let y=!0;for(let e=r;e<=s;e++)if(l.getColVisible(e)){y=!1;break}let b=v||y,x={left:m,top:h,color:c,width:y?2:g-m,height:v?2:_-h,evented:!1,inHiddenRange:b,zIndex:1e4};return new p(`find-highlight-${t}`,x)});o.addObjects(d),this._highlightShapes=d,o.makeDirty()}_updateCurrentHighlightShape(e){var t;if((t=this._currentHighlightShape)==null||t.setShapeProps({activated:!1}),this._currentHighlightShape=null,e!==void 0){let t=this._highlightShapes[e];if(!t)return;this._currentHighlightShape=t,t.setShapeProps({activated:!0})}}_getSheetObject(){return(0,a.getSheetObject)(this._univerInstanceService,this._renderManagerService)}_focusMatch(e){var t;let r=e.range.subUnitId;r!==((t=this._workbook.getActiveSheet())==null?void 0:t.getSheetId())&&this._commandService.executeCommand(n.SetWorksheetActivateCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:r},{fromFindReplace:!0}),this._commandService.executeCommand(a.ScrollToCellCommand.id,{range:e.range.range},{fromFindReplace:!0})}_tryRestoreLastMatchesPosition(e,t){if(!e)return 0;let{subUnitId:n}=e.range,{startColumn:r,startRow:i}=e.range.range,a=t.findIndex(e=>{if(n!==e.range.subUnitId)return!1;let{startColumn:t,startRow:a}=e.range.range;return t===r&&a===i});return a>-1?a+1:0}moveToNextMatch(e){var t,n,r,a;if(!this._matches.length)return null;let o=(t=e==null?void 0:e.loop)==null?!1:t,s=(n=e==null?void 0:e.stayIfOnMatch)==null?!1:n,c=(r=e==null?void 0:e.noFocus)==null?!1:r,l=(a=e==null?void 0:e.ignoreSelection)==null?!1:a,u=this._findNextMatch(o,s,l);if(u){var d;let[e,t]=u;return this._matchesPosition=t+1,this._query.findScope===i.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(e.range.subUnitId).findIndex(t=>t===e):this._activeHighlightIndex=t,c||this._focusMatch(e),((d=this._workbook.getActiveSheet())==null?void 0:d.getSheetId())===e.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),e}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}moveToPreviousMatch(e){var t,n,r,a;if(!this._matches.length)return null;let o=(t=e==null?void 0:e.loop)==null?!1:t,s=(n=e==null?void 0:e.stayIfOnMatch)==null?!1:n,c=(r=e==null?void 0:e.noFocus)==null?!1:r,l=(a=e==null?void 0:e.ignoreSelection)==null?!1:a,u=this._findPreviousMatch(o,s,l);if(u){var d;let[e,t]=u;return this._matchesPosition=t+1,this._query.findScope===i.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(e.range.subUnitId).findIndex(t=>t===e):this._activeHighlightIndex=t,c||this._focusMatch(e),((d=this._workbook.getActiveSheet())==null?void 0:d.getSheetId())===e.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),e}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}_findPreviousMatch(e=!1,t=!1,n=!1){var r;if(this.currentMatch){let n=this._matches.findIndex(e=>e===this.currentMatch);if(t)return[this.currentMatch,n];let r=n-1;if(!e&&r<0)return null;let i=this._matches.length,a=(r+i)%i;return[this._matches[a],a]}let a=this._workbookSelections.getCurrentLastSelection();if(n||!a){let e=this._matches.length-1;return[this._matches[e],e]}if(this._query.findScope!==i.FindScope.UNIT)return this._findPreviousMatchByRange(this._matches,a.range);let o=(r=this._workbook.getActiveSheet())==null?void 0:r.getSheetId();if(!o)return null;let s=this._findPreviousWorksheetThatHasAMatch(o,e);return s?this._findPreviousMatchByRange(this._matchesByWorksheet.get(s),a.range):null}_findNextMatch(e=!1,t=!1,n=!1){var r;if(this.currentMatch){let n=this._matches.findIndex(e=>e===this.currentMatch);if(t)return[this.currentMatch,n];let r=n+1,i=this._matches.length;if(!e&&r>=i)return null;let a=r%i;return[this._matches[a],a]}let a=this._workbookSelections.getCurrentLastSelection();if(n||!a)return[this._matches[0],0];if(this._query.findScope!==i.FindScope.UNIT)return this._findNextMatchByRange(this._matches,a.range,t);let o=(r=this._workbook.getActiveSheet())==null?void 0:r.getSheetId();if(!o)return null;let s=this._findNextWorksheetThatHasAMatch(o,e);return s?this._findNextMatchByRange(this._matchesByWorksheet.get(s),a.range):null}_findPreviousWorksheetThatHasAMatch(e,n=!1){let r=this._workbook.getSheetOrders(),i=r.findIndex(t=>t===e),a=(n?(0,t.rotate)(r,i+1):r.slice(0,i+1)).findLast(e=>this._matchesByWorksheet.has(e));return a==null?null:a}_findNextWorksheetThatHasAMatch(e,n=!1){let r=this._workbook.getSheetOrders(),i=r.findIndex(t=>t===e),a=(n?(0,t.rotate)(r,i):r.slice(i)).find(e=>this._matchesByWorksheet.has(e));return a==null?null:a}_findNextMatchByRange(e,t,n=!1){let r=this._query.findDirection===i.FindDirection.ROW,a=e.findIndex(e=>{let i=e.range.range;if(!(r?h(t,i):g(t,i)))return!1;let a=m(t,i);return n?a:!a});a===-1&&(a=e.length-1);let o=e[a];return[o,this._matches.findIndex(e=>e===o)]}_findPreviousMatchByRange(e,t,n=!1){let r=this._query.findDirection===i.FindDirection.ROW,a=this._matches.findLastIndex(e=>{let i=e.range.range;if(!(r?_(t,i):v(t,i)))return!1;let a=m(t,i);return n?a:!a});a===-1&&(a=0);let o=e[a];return[o,this._matches.findIndex(e=>e===o)]}async replace(e){if(this._matchesCount===0||!this.currentMatch||!this._query||!this.currentMatch.replaceable)return!1;let t=this.currentMatch.range,r=this._workbook.getSheetBySheetId(this.currentMatch.range.subUnitId),a=this._getReplacedCellData(this.currentMatch,r,this._query.findBy===i.FindBy.FORMULA,this._query.findString,e,this._query.caseSensitive?`g`:`ig`),o={unitId:this.currentMatch.unitId,subUnitId:t.subUnitId,value:{[t.range.startRow]:{[t.range.startColumn]:a}}};return this._commandService.executeCommand(n.SetRangeValuesCommand.id,o)}async replaceAll(e){if(this._matchesCount===0||!this._query)return{success:0,failure:0};let n=this._workbook.getUnitId(),{findString:r,caseSensitive:a,findBy:o}=this._query,c=o===i.FindBy.FORMULA,l=a?`g`:`ig`,u=[];return(0,t.groupBy)(this._matches.filter(e=>e.replaceable),e=>e.range.subUnitId).forEach((n,i)=>{let a=new t.ObjectMatrix,o=this._workbook.getSheetBySheetId(i);n.forEach(t=>{let{startColumn:n,startRow:i}=t.range.range,s=this._getReplacedCellData(t,o,c,r,e,l);s&&a.setValue(i,n,s)}),u.push({count:n.length,subUnitId:i,value:a.getMatrix()})}),u?this._commandService.executeCommand(s.id,{unitId:n,replacements:u}):{success:0,failure:0}}_getReplacedCellData(e,n,r,i,a,o){var s;let{startRow:c,startColumn:l}=e.range.range,u=n.getCellRaw(c,l);if(e.isFormula)return r?{f:u.f.replace(new RegExp(w(i),o),a),v:null}:null;if((s=u.p)!=null&&s.body){let e=t.Tools.deepClone(u.p);return(0,t.replaceInDocumentBody)(e.body,i,a,this._query.caseSensitive),{p:e}}return{v:u.v.toString().replace(new RegExp(w(i),o),a)}}};C=x([b(2,t.IUniverInstanceService),b(3,r.IRenderManagerService),b(4,t.ICommandService),b(5,t.IContextService),b(6,(0,t.Inject)(t.ThemeService)),b(7,(0,t.Inject)(n.SheetsSelectionsService))],C);function w(e){return e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,`\\$&`)}let T=class extends t.Disposable{constructor(e,t,n){super(),this._univerInstanceService=e,this._renderManagerService=t,this._injector=n,f(this,`_findModelsByUnitId`,new Map)}async find(e){this._terminate();let n=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET);if(!n)return[];let r=this._preprocessQuery(e),i=this._renderManagerService.getRenderById(n.getUnitId()).with(a.SheetSkeletonManagerService),o=this._injector.createInstance(C,n,i);return this._findModelsByUnitId.set(n.getUnitId(),o),o.start(r),[o]}terminate(){this._terminate()}_terminate(){this._findModelsByUnitId.forEach(e=>e.dispose()),this._findModelsByUnitId.clear()}_preprocessQuery(e){let t=e.caseSensitive?e.findString:e.findString.toLowerCase();return t=t.trim(),{...e,findString:t}}};T=x([b(0,t.IUniverInstanceService),b(1,r.IRenderManagerService),b(2,(0,t.Inject)(t.Injector))],T);let E={hit:!1,replaceable:!1,isFormula:!1,rawData:null};function D(e,t,n,r,a){let{findBy:o}=r,s=o===i.FindBy.FORMULA,c=e.getCellRaw(t,n);return E.rawData=c,c!=null&&c.f?(E.isFormula=!0,s?O({v:c.f},r)?(E.hit=!0,E.replaceable=!0,E):(E.hit=!1,E.replaceable=!1,E):(E.replaceable=!1,O(a,r)?E.hit=!0:E.hit=!1,E)):(E.isFormula=!1,O(a,r)?c?(E.hit=!0,E.replaceable=!0):(E.hit=!0,E.replaceable=!1):(E.hit=!1,E.replaceable=!1),E)}function O(e,t){let n=k(e);return n?t.matchesTheWholeCell?(n=A(n),t.caseSensitive?n===t.findString:n.toLowerCase()===t.findString):t.caseSensitive?n.indexOf(t.findString)>-1:n.toLowerCase().indexOf(t.findString)>-1:!1}function k(e){var t,n;let r=(t=e==null||(n=e.p)==null||(n=n.body)==null?void 0:n.dataStream)==null?e==null?void 0:e.v:t;return typeof r==`number`?`${r}`:typeof r==`boolean`?r?`1`:`0`:r}function A(e){return e.replace(/^ +/g,``).replace(/ +$/g,``)}var j=`@univerjs/sheets-find-replace`,M=`0.18.0`;let N=`sheets-find-replace.config`;Symbol(N);let P={},F=class extends t.Plugin{constructor(e=P,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{...i}=(0,t.merge)({},P,this._config);this._configService.setConfig(N,i)}onStarting(){[[S]].forEach(e=>this._injector.add(e))}onSteady(){this._injector.get(S)}};f(F,`pluginName`,`SHEET_FIND_REPLACE_PLUGIN`),f(F,`packageName`,j),f(F,`version`,M),f(F,`type`,t.UniverInstanceType.UNIVER_SHEET),F=x([(0,t.DependentOn)(n.UniverSheetsPlugin,n.UniverSheetsPlugin,i.UniverFindReplacePlugin),b(1,(0,t.Inject)(t.Injector)),b(2,t.IConfigService)],F),e.SheetReplaceCommand=s,Object.defineProperty(e,`SheetsFindReplaceController`,{enumerable:!0,get:function(){return S}}),Object.defineProperty(e,`UniverSheetsFindReplacePlugin`,{enumerable:!0,get:function(){return F}})});
|
package/lib/umd/locale/ca-ES.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?module.exports=t():typeof define==`function`&&define.amd?define([],t):(e=typeof globalThis<`u`?globalThis:e||self,e.UniverSheetsFindReplaceCaES=t())})(this,function(){return{"sheet-find-replace":{replace:{"partial-failure":`No s’ha pogut substituir algunes cel·les`,failure:`No s’ha pogut substituir cap cel·la`}}}});
|
package/lib/umd/locale/en-US.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?module.exports=t():typeof define==`function`&&define.amd?define([],t):(e=typeof globalThis<`u`?globalThis:e||self,e.UniverSheetsFindReplaceEnUS=t())})(this,function(){return{"sheet-find-replace":{replace:{"partial-failure":`Failed to replace some cells`,failure:`Failed to replace all cells`}}}});
|
package/lib/umd/locale/es-ES.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?module.exports=t():typeof define==`function`&&define.amd?define([],t):(e=typeof globalThis<`u`?globalThis:e||self,e.UniverSheetsFindReplaceEsES=t())})(this,function(){return{"sheet-find-replace":{replace:{"partial-failure":`No se pudo reemplazar algunas celdas`,failure:`No se pudo reemplazar ninguna celda`}}}});
|
package/lib/umd/locale/fa-IR.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?module.exports=t():typeof define==`function`&&define.amd?define([],t):(e=typeof globalThis<`u`?globalThis:e||self,e.UniverSheetsFindReplaceFaIR=t())})(this,function(){return{"sheet-find-replace":{replace:{"partial-failure":`جایگزینی برخی سلولها ناموفق بود`,failure:`جایگزینی همه سلولها ناموفق بود`}}}});
|
package/lib/umd/locale/fr-FR.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?module.exports=t():typeof define==`function`&&define.amd?define([],t):(e=typeof globalThis<`u`?globalThis:e||self,e.UniverSheetsFindReplaceFrFR=t())})(this,function(){return{"sheet-find-replace":{replace:{"partial-failure":`Échec du remplacement de certaines cellules`,failure:`Échec du remplacement de toutes les cellules`}}}});
|
package/lib/umd/locale/ja-JP.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?module.exports=t():typeof define==`function`&&define.amd?define([],t):(e=typeof globalThis<`u`?globalThis:e||self,e.UniverSheetsFindReplaceJaJP=t())})(this,function(){return{"sheet-find-replace":{replace:{"partial-failure":`一部のセルの置換に失敗しました`,failure:`すべてのセルの置換に失敗しました`}}}});
|
package/lib/umd/locale/ko-KR.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?module.exports=t():typeof define==`function`&&define.amd?define([],t):(e=typeof globalThis<`u`?globalThis:e||self,e.UniverSheetsFindReplaceKoKR=t())})(this,function(){return{"sheet-find-replace":{replace:{"partial-failure":`일부 셀 교체에 실패했습니다`,failure:`모든 셀 교체에 실패했습니다`}}}});
|
package/lib/umd/locale/ru-RU.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?module.exports=t():typeof define==`function`&&define.amd?define([],t):(e=typeof globalThis<`u`?globalThis:e||self,e.UniverSheetsFindReplaceRuRU=t())})(this,function(){return{"sheet-find-replace":{replace:{"partial-failure":`Не удалось заменить некоторые ячейки`,failure:`Не удалось заменить все ячейки`}}}});
|
package/lib/umd/locale/sk-SK.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?module.exports=t():typeof define==`function`&&define.amd?define([],t):(e=typeof globalThis<`u`?globalThis:e||self,e.UniverSheetsFindReplaceSkSK=t())})(this,function(){return{"sheet-find-replace":{replace:{"partial-failure":`Nepodarilo sa nahradiť niektoré bunky`,failure:`Nepodarilo sa nahradiť všetky bunky`}}}});
|
package/lib/umd/locale/vi-VN.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?module.exports=t():typeof define==`function`&&define.amd?define([],t):(e=typeof globalThis<`u`?globalThis:e||self,e.UniverSheetsFindReplaceViVN=t())})(this,function(){return{"sheet-find-replace":{replace:{"partial-failure":`Thay thế một phần ô thất bại`,failure:`Thay thế thất bại`}}}});
|
package/lib/umd/locale/zh-CN.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?module.exports=t():typeof define==`function`&&define.amd?define([],t):(e=typeof globalThis<`u`?globalThis:e||self,e.UniverSheetsFindReplaceZhCN=t())})(this,function(){return{"sheet-find-replace":{replace:{"partial-failure":`部分单元格替换失败`,failure:`替换失败`}}}});
|
package/lib/umd/locale/zh-TW.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?module.exports=t():typeof define==`function`&&define.amd?define([],t):(e=typeof globalThis<`u`?globalThis:e||self,e.UniverSheetsFindReplaceZhTW=t())})(this,function(){return{"sheet-find-replace":{replace:{"partial-failure":`部分儲存格替換失敗`,failure:`替換失敗`}}}});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-find-replace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "UniverSheet find replace plugin",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -63,25 +63,26 @@
|
|
|
63
63
|
"rxjs": ">=7.0.0"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@univerjs/
|
|
67
|
-
"@univerjs/
|
|
68
|
-
"@univerjs/sheets": "0.
|
|
69
|
-
"@univerjs/sheets-ui": "0.
|
|
70
|
-
"@univerjs/find-replace": "0.
|
|
66
|
+
"@univerjs/core": "0.18.0",
|
|
67
|
+
"@univerjs/engine-render": "0.18.0",
|
|
68
|
+
"@univerjs/sheets": "0.18.0",
|
|
69
|
+
"@univerjs/sheets-ui": "0.18.0",
|
|
70
|
+
"@univerjs/find-replace": "0.18.0"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"rxjs": "^7.8.2",
|
|
74
74
|
"typescript": "^5.9.3",
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"@univerjs-infra/shared": "0.17.0"
|
|
75
|
+
"vitest": "^4.1.0",
|
|
76
|
+
"@univerjs-infra/shared": "0.18.0"
|
|
78
77
|
},
|
|
79
78
|
"scripts": {
|
|
80
79
|
"test": "vitest run",
|
|
81
80
|
"test:watch": "vitest",
|
|
82
81
|
"coverage": "vitest run --coverage",
|
|
83
82
|
"typecheck": "tsc --noEmit",
|
|
84
|
-
"build": "univer-cli build"
|
|
83
|
+
"build:bundle": "univer-cli build",
|
|
84
|
+
"build:types": "tsc -p tsconfig.node.json",
|
|
85
|
+
"build": "pnpm run build:bundle && pnpm run build:types"
|
|
85
86
|
},
|
|
86
87
|
"module": "./lib/es/index.js"
|
|
87
88
|
}
|