@univerjs/sheets-find-replace 0.1.12 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +343 -356
- package/lib/locale/en-US.json +8 -0
- package/lib/locale/ru-RU.json +8 -0
- package/lib/locale/zh-CN.json +8 -0
- package/lib/types/controllers/sheet-find-replace.controller.d.ts +3 -1
- package/lib/types/index.d.ts +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +18 -14
- package/lib/types/locale/index.d.ts +0 -18
|
@@ -40,6 +40,7 @@ export declare class SheetFindModel extends FindModel {
|
|
|
40
40
|
private readonly _themeService;
|
|
41
41
|
private readonly _sheetSkeletonManagerService;
|
|
42
42
|
private readonly _selectionManagerService;
|
|
43
|
+
private readonly _findReplaceController;
|
|
43
44
|
private readonly _matchesUpdate$;
|
|
44
45
|
readonly matchesUpdate$: import('rxjs').Observable<ISheetCellMatch[]>;
|
|
45
46
|
private readonly _activelyChangingMatch$;
|
|
@@ -60,7 +61,7 @@ export declare class SheetFindModel extends FindModel {
|
|
|
60
61
|
get matchesCount(): number;
|
|
61
62
|
get matchesPosition(): number;
|
|
62
63
|
get currentMatch(): Nullable<ISheetCellMatch>;
|
|
63
|
-
constructor(_workbook: Workbook, _univerInstanceService: IUniverInstanceService, _renderManagerService: IRenderManagerService, _commandService: ICommandService, _contextService: IContextService, _themeService: ThemeService, _sheetSkeletonManagerService: SheetSkeletonManagerService, _selectionManagerService: SelectionManagerService);
|
|
64
|
+
constructor(_workbook: Workbook, _univerInstanceService: IUniverInstanceService, _renderManagerService: IRenderManagerService, _commandService: ICommandService, _contextService: IContextService, _themeService: ThemeService, _sheetSkeletonManagerService: SheetSkeletonManagerService, _selectionManagerService: SelectionManagerService, _findReplaceController: SheetsFindReplaceController);
|
|
64
65
|
dispose(): void;
|
|
65
66
|
getMatches(): IFindMatch[];
|
|
66
67
|
start(query: IFindQuery): void;
|
|
@@ -103,6 +104,7 @@ export declare class SheetFindModel extends FindModel {
|
|
|
103
104
|
replace(replaceString: string): Promise<boolean>;
|
|
104
105
|
replaceAll(replaceString: string): Promise<IReplaceAllResult>;
|
|
105
106
|
private _getReplacedCellData;
|
|
107
|
+
private _getFindReplacePermissionCheck;
|
|
106
108
|
}
|
|
107
109
|
interface IValuePassingObject {
|
|
108
110
|
hit: boolean;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -13,5 +13,5 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
export { enUS, zhCN, ruRU } from './locale';
|
|
17
16
|
export { UniverSheetsFindReplacePlugin } from './plugin';
|
|
17
|
+
export { SheetsFindReplaceController } from './controllers/sheet-find-replace.controller';
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(d,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("@univerjs/find-replace"),require("@univerjs/engine-render"),require("@univerjs/sheets"),require("@univerjs/sheets-ui"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","@univerjs/find-replace","@univerjs/engine-render","@univerjs/sheets","@univerjs/sheets-ui","rxjs"],u):(d=typeof globalThis<"u"?globalThis:d||self,u(d.UniverSheetsFindReplace={},d.UniverCore,d["@wendellhu/redi"],d.UniverFindReplace,d.UniverEngineRender,d.UniverSheets,d.UniverSheetsUi,d.rxjs))})(this,function(d,u,m,S,U,M,k,w){"use strict";var Ce=Object.defineProperty;var we=(d,u,m)=>u in d?Ce(d,u,{enumerable:!0,configurable:!0,writable:!0,value:m}):d[u]=m;var _=(d,u,m)=>(we(d,typeof u!="symbol"?u+"":u,m),m);var F;const Q={"sheet-find-replace":{replace:{"partial-failure":"Failed to replace some cells",failure:"Failed to replace all cells"}}},X={"sheet-find-replace":{replace:{"partial-failure":"部分单元格替换失败",failure:"替换失败"}}},Y={"sheet-find-replace":{replace:{"partial-failure":"Не удалось заменить некоторые ячейки",failure:"Не удалось заменить все ячейки"}}};class z extends U.Shape{constructor(t,i){super(t,i);_(this,"_activated",!1);_(this,"_inHiddenRange",!1);_(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})`;U.Rect.drawWith(t,{width:this.width,height:this.height,fill:n,stroke:i?r:void 0,strokeWidth:i?2:0,evented:!1})}}const O={id:"sheet.command.replace",type:u.CommandType.COMMAND,handler:async(h,e)=>{const t=h.get(u.IUndoRedoService),i=h.get(u.ICommandService),{unitId:n,replacements:r}=e,s=t.__tempBatchingUndoRedo(n),o=await Promise.all(r.map(c=>i.executeCommand(M.SetRangeValuesCommand.id,{unitId:n,subUnitId:c.subUnitId,value:c.value})));return s.dispose(),G(o,r)}};function G(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 E(h,e){return h.startRow===e.startRow&&h.startColumn===e.startColumn}function A(h,e){return h.startRow<e.startRow||h.startRow===e.startRow&&h.startColumn<=e.startColumn}function D(h,e){return h.startColumn<e.startColumn||h.startColumn===e.startColumn&&h.startRow<=e.startRow}function K(h,e){return h.startRow>e.startRow||h.startRow===e.startRow&&h.startColumn>=e.startColumn}function J(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?u.Rectangle.equals(t,r):t.endRow===t.startRow&&t.endColumn===t.startColumn}var ee=Object.defineProperty,te=Object.getOwnPropertyDescriptor,B=(h,e,t,i)=>{for(var n=i>1?void 0:i?te(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&&ee(e,t,n),n},p=(h,e)=>(t,i)=>e(t,i,h);let x=class extends u.Disposable{constructor(e,t,i,n,r){super();_(this,"_provider");this._injector=e,this._findReplaceController=t,this._contextService=i,this._findReplaceService=n,this._commandService=r,this._init(),this._initCommands()}dispose(){super.dispose(),this._provider.dispose()}_init(){const e=this._injector.createInstance(T);this._provider=e,this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(e)),this.disposeWithMe(this._contextService.subscribeContextValue$(u.EDITOR_ACTIVATED).pipe(w.filter(t=>!!t)).subscribe(()=>this._findReplaceController.closePanel()))}_initCommands(){[O].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}};x=B([u.OnLifecycle(u.LifecycleStages.Steady,x),p(0,m.Inject(m.Injector)),p(1,m.Inject(S.FindReplaceController)),p(2,u.IContextService),p(3,S.IFindReplaceService),p(4,u.ICommandService)],x);const ie="sheets-find-replace-provider",ne=1e4;let W=class extends S.FindModel{constructor(e,t,i,n,r,s,o,c){super();_(this,"_matchesUpdate$",new w.Subject);_(this,"matchesUpdate$",this._matchesUpdate$.asObservable());_(this,"_activelyChangingMatch$",new w.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._workbook=e,this._univerInstanceService=t,this._renderManagerService=i,this._commandService=n,this._contextService=r,this._themeService=s,this._sheetSkeletonManagerService=o,this._selectionManagerService=c}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(U.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),l=o.getSheetId(),{results:a}=c;return a.length?this._matchesByWorksheet.set(l,c.results):this._matchesByWorksheet.delete(l),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(u.fromCallback(this._commandService.onCommandExecuted).pipe(w.filter(([s,o])=>s.id===M.SetWorksheetActiveOperation.id&&!(o!=null&&o.fromFindReplace))).subscribe(()=>{const s=this._workbook.getActiveSheet(),o=s.getSheetId();this._matchesByWorksheet.has(o)&&this._findNextMatchOnActiveSheetChange(s)})),this.disposeWithMe(u.fromCallback(this._commandService.onCommandExecuted).pipe(w.filter(([s])=>s.type===u.CommandType.MUTATION&&s.params.unitId===this._workbook.getUnitId()),w.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._selectionManagerService.getSelections();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 g;const c=this._workbook.getActiveSheet(),l=this._selectionManagerService.getSelections();return(g=l==null?void 0:l.some(v=>!Z(v,c)))!=null?g:!1};let n,r=!0,s=!1;const o=()=>{const c=this._workbook.getActiveSheet(),l=this.currentMatch;s=i();const a=this._selectionManagerService.getSelections(),g=s?this._findInSelections(c,a,e,t):this._findInWorksheet(c,e,t);return this._matches=g.results,this._matchesPosition=this._tryRestoreLastMatchesPosition(l,this._matches),r?(n=g,r=!1):this._matchesUpdate$.next(this._matches),this._updateFindHighlight(),g};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>this._updateFindHighlight())),this.disposeWithMe(w.merge(u.fromCallback(this._commandService.onCommandExecuted).pipe(w.filter(([c])=>{if(c.type===u.CommandType.MUTATION&&c.params.unitId===this._workbook.getUnitId())return!0;if(c.id===M.SetSelectionsOperation.id&&c.params.unitId===t){const l=i();return l===!1&&s===!1?!1:(s=l,!0)}return!1})),this._workbook.activeSheet$.pipe(w.skip(1))).pipe(w.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 l of c){const{row:a,col:g,colSpan:v,rowSpan:C,value:I}=l;if(r!=null&&r(a,g)||!I||e.getRowFiltered(a))continue;const{hit:R,replaceable:y,isFormula:b}=se(e,a,g,t,I);if(R){const P={provider:ie,unitId:n,replaceable:y,isFormula:b,range:{subUnitId:o,range:{startRow:a,startColumn:g,endColumn:g+(v!=null?v:1)-1,endRow:a+(C!=null?C:1)-1}}};s.push(P)}}return{results:s}}_findInSelections(e,t,i,n){const{findDirection:r}=i,s=r===S.FindDirection.ROW?A:D,o=new Set;return{results:t.map(l=>this._findInRange(e,i,l.range,n,(a,g)=>{const v=`${a}-${g}`;return o.has(v)?!0:(o.add(v),!1)}).results).flat().sort((l,a)=>s(l.range.range,a.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 C,I;this._disposeHighlights();const e=(C=this._sheetSkeletonManagerService.getCurrent())==null?void 0:C.skeleton;if(!e||!this._getSheetObject()||((I=this._univerInstanceService.getFocusedUnit())==null?void 0:I.getUnitId())!==this._workbook.getUnitId())return;const n=this._workbook.getUnitId(),r=this._renderManagerService.getRenderById(n);if(r==null)return;const{scene:s}=r,o=this._matches,c=this._themeService.getCurrentTheme().gold400,l=new u.ColorKit(c).toRgb(),a=this._workbook.getActiveSheet(),g=a.getSheetId(),v=o.filter(R=>R.range.subUnitId===g).map((R,y)=>{const{startColumn:b,startRow:P,endColumn:ue,endRow:de}=R.range.range,ge=k.getCoordByCell(P,b,s,e),fe=k.getCoordByCell(de,ue,s,e),{startX:$,startY:L}=ge,{endX:_e,endY:Se}=fe,V=!a.getRowRawVisible(P),q=!a.getColVisible(b),me=V||q,ve=q?2:_e-$,pe=V?2:Se-L,Ie={left:$,top:L,color:l,width:ve,height:pe,evented:!1,inHiddenRange:me};return new z(`find-highlight-${y}`,Ie)});s.addObjects(v,ne),this._highlightShapes=v,s.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 k.getSheetObject(this._univerInstanceService,this._renderManagerService)}_focusMatch(e){const t=e.range.subUnitId;t!==this._workbook.getActiveSheet().getSheetId()&&this._commandService.syncExecuteCommand(M.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: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:l}=o.range.range;return c===n&&l===r});return s>-1?s+1:0}moveToNextMatch(e){var s,o,c;if(!this._matches.length)return null;const t=(s=e==null?void 0:e.loop)!=null?s:!1,i=(o=e==null?void 0:e.stayIfOnMatch)!=null?o:!1,n=(c=e==null?void 0:e.noFocus)!=null?c:!1,r=this._findNextMatch(t,i);if(r){const[l,a]=r;return this._matchesPosition=a+1,this._query.findScope===S.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(l.range.subUnitId).findIndex(g=>g===l):this._activeHighlightIndex=a,n||this._focusMatch(l),this._workbook.getActiveSheet().getSheetId()===l.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),l}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}moveToPreviousMatch(e){var s,o,c;if(!this._matches.length)return null;const t=(s=e==null?void 0:e.loop)!=null?s:!1,i=(o=e==null?void 0:e.stayIfOnMatch)!=null?o:!1,n=(c=e==null?void 0:e.noFocus)!=null?c:!1,r=this._findPreviousMatch(t,i);if(r){const[l,a]=r;return this._matchesPosition=a+1,this._query.findScope===S.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(l.range.subUnitId).findIndex(g=>g===l):this._activeHighlightIndex=a,n||this._focusMatch(l),this._workbook.getActiveSheet().getSheetId()===l.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),l}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}_findPreviousMatch(e=!1,t=!1){if(this.currentMatch){const s=this._matches.findIndex(a=>a===this.currentMatch);if(t)return[this.currentMatch,s];const o=s-1;if(!e&&o<0)return null;const c=this._matches.length,l=(o+c)%c;return[this._matches[l],l]}const i=this._selectionManagerService.getSelections();if(!(i!=null&&i.length))return[this._matches[0],0];if(this._query.findScope!==S.FindScope.UNIT)return this._findPreviousMatchByRange(this._matches,i[0].range);const n=this._workbook.getActiveSheet().getSheetId(),r=this._findPreviousWorksheetThatHasAMatch(n,e);return r?this._findPreviousMatchByRange(this._matchesByWorksheet.get(r),i[0].range):null}_findNextMatch(e=!1,t=!1){if(this.currentMatch){const s=this._matches.findIndex(a=>a===this.currentMatch);if(t)return[this.currentMatch,s];const o=s+1,c=this._matches.length;if(!e&&o>=c)return null;const l=o%c;return[this._matches[l],l]}const i=this._selectionManagerService.getSelections();if(!(i!=null&&i.length))return[this._matches[0],0];if(this._query.findScope!==S.FindScope.UNIT)return this._findNextMatchByRange(this._matches,i[0].range,t);const n=this._workbook.getActiveSheet().getSheetId(),r=this._findNextWorksheetThatHasAMatch(n,e);return r?this._findNextMatchByRange(this._matchesByWorksheet.get(r),i[0].range):null}_findPreviousWorksheetThatHasAMatch(e,t=!1){const i=this._workbook.getSheetOrders(),n=i.findIndex(o=>o===e),s=(t?u.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?u.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?A(t,c):D(t,c)))return!1;const a=E(t,c);return i?a:!a});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?K(t,c):J(t,c)))return!1;const a=E(t,c);return i?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,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(M.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 u.groupBy(this._matches.filter(a=>a.replaceable),a=>a.range.subUnitId).forEach((a,g)=>{const v=new u.ObjectMatrix,C=this._workbook.getSheetBySheetId(g);a.forEach(I=>{const{startColumn:R,startRow:y}=I.range.range,b=this._getReplacedCellData(I,C,s,i,e,o);b&&v.setValue(y,R,b)}),c.push({count:a.length,subUnitId:g,value:v.getMatrix()})}),c?this._commandService.executeCommand(O.id,{unitId:t,replacements:c}):{success:0,failure:0}}_getReplacedCellData(e,t,i,n,r,s){var C;const o=e.range.range,{startRow:c,startColumn:l}=o,a=t.getCellRaw(c,l);if(e.isFormula)return i?{f:a.f.replace(new RegExp(j(n),s),r),v:null}:null;if(!!((C=a.p)!=null&&C.body)){const I=u.Tools.deepClone(a.p);return u.replaceInDocumentBody(I.body,n,r),{p:I}}return{v:a.v.toString().replace(new RegExp(j(n),s),r)}}};W=B([p(1,u.IUniverInstanceService),p(2,U.IRenderManagerService),p(3,u.ICommandService),p(4,u.IContextService),p(5,m.Inject(u.ThemeService)),p(6,m.Inject(k.SheetSkeletonManagerService)),p(7,m.Inject(M.SelectionManagerService))],W);function j(h){return h.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}let T=class extends u.Disposable{constructor(e,t){super();_(this,"_findModelsByUnitId",new Map);this._univerInstanceService=e,this._injector=t}async find(e){this._terminate();const t=this._univerInstanceService.getCurrentUnitForType(u.UniverInstanceType.UNIVER_SHEET);if(t){const i=this._injector.createInstance(W,t);this._findModelsByUnitId.set(t.getUnitId(),i);const n=this._preprocessQuery(e);return i.start(n),[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}}};T=B([p(0,u.IUniverInstanceService),p(1,m.Inject(m.Injector))],T);const f={hit:!1,replaceable:!1,isFormula:!1,rawData:null};function se(h,e,t,i,n){const{findBy:r}=i,s=r===S.FindBy.FORMULA,o=h.getCellRaw(e,t);return f.rawData=o,!(o!=null&&o.f)?(f.isFormula=!1,H(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?H({v:o.f},i)?(f.hit=!0,f.replaceable=!0,f):(f.hit=!1,f.replaceable=!1,f):(f.replaceable=!1,H(n,i)?f.hit=!0:f.hit=!1,f))}function H(h,e){let t=re(h);return t?e.matchesTheWholeCell?(t=oe(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 re(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 oe(h){return h.replace(/^ +/g,"").replace(/ +$/g,"")}var he=Object.defineProperty,ce=Object.getOwnPropertyDescriptor,ae=(h,e,t,i)=>{for(var n=i>1?void 0:i?ce(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&&he(e,t,n),n},N=(h,e)=>(t,i)=>e(t,i,h);const le="SHEET_FIND_REPLACE_PLUGIN";d.UniverSheetsFindReplacePlugin=(F=class extends u.Plugin{constructor(e,t,i){super(),this._injector=t,this._pluginService=i,this._pluginService.registerPlugin(S.UniverFindReplacePlugin)}onStarting(e){[[x]].forEach(t=>e.add(t))}},_(F,"pluginName",le),_(F,"type",u.UniverInstanceType.UNIVER_SHEET),F),d.UniverSheetsFindReplacePlugin=ae([N(1,m.Inject(m.Injector)),N(2,m.Inject(u.PluginService))],d.UniverSheetsFindReplacePlugin),d.enUS=Q,d.ruRU=Y,d.zhCN=X,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(u,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("@univerjs/find-replace"),require("@univerjs/engine-render"),require("@univerjs/sheets"),require("@univerjs/sheets-ui"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","@univerjs/find-replace","@univerjs/engine-render","@univerjs/sheets","@univerjs/sheets-ui","rxjs"],d):(u=typeof globalThis<"u"?globalThis:u||self,d(u.UniverSheetsFindReplace={},u.UniverCore,u["@wendellhu/redi"],u.UniverFindReplace,u.UniverEngineRender,u.UniverSheets,u.UniverSheetsUi,u.rxjs))})(this,function(u,d,S,m,F,k,b,R){"use strict";var ve=Object.defineProperty;var Ce=(u,d,S)=>d in u?ve(u,d,{enumerable:!0,configurable:!0,writable:!0,value:S}):u[d]=S;var f=(u,d,S)=>(Ce(u,typeof d!="symbol"?d+"":d,S),S);var U;var O=(t=>(t[t.View=0]="View",t[t.Edit=1]="Edit",t[t.ManageCollaborator=2]="ManageCollaborator",t[t.Print=3]="Print",t[t.Duplicate=4]="Duplicate",t[t.Comment=5]="Comment",t[t.Copy=6]="Copy",t[t.Share=7]="Share",t[t.Export=8]="Export",t[t.MoveWorksheet=9]="MoveWorksheet",t[t.DeleteWorksheet=10]="DeleteWorksheet",t[t.HideWorksheet=11]="HideWorksheet",t[t.RenameWorksheet=12]="RenameWorksheet",t[t.CreateWorksheet=13]="CreateWorksheet",t[t.SetWorksheetStyle=14]="SetWorksheetStyle",t[t.EditWorksheetCell=15]="EditWorksheetCell",t[t.InsertHyperlink=16]="InsertHyperlink",t[t.Sort=17]="Sort",t[t.Filter=18]="Filter",t[t.PivotTable=19]="PivotTable",t[t.FloatImg=20]="FloatImg",t[t.History=21]="History",t[t.RwHgtClWdt=22]="RwHgtClWdt",t[t.ViemRwHgtClWdt=23]="ViemRwHgtClWdt",t[t.ViewFilter=24]="ViewFilter",t[t.MoveSheet=25]="MoveSheet",t[t.DeleteSheet=26]="DeleteSheet",t[t.HideSheet=27]="HideSheet",t[t.CopySheet=28]="CopySheet",t[t.RenameSheet=29]="RenameSheet",t[t.CreateSheet=30]="CreateSheet",t[t.SelectProtectedCells=31]="SelectProtectedCells",t[t.SelectUnProtectedCells=32]="SelectUnProtectedCells",t[t.SetCellStyle=33]="SetCellStyle",t[t.SetCellValue=34]="SetCellValue",t[t.SetRowStyle=35]="SetRowStyle",t[t.SetColumnStyle=36]="SetColumnStyle",t[t.InsertRow=37]="InsertRow",t[t.InsertColumn=38]="InsertColumn",t[t.DeleteRow=39]="DeleteRow",t[t.DeleteColumn=40]="DeleteColumn",t[t.EditExtraObject=41]="EditExtraObject",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED",t))(O||{});class X extends F.Shape{constructor(i,n){super(i,n);f(this,"_activated",!1);f(this,"_inHiddenRange",!1);f(this,"_color");n&&this.setShapeProps(n)}setShapeProps(i){this._activated=!!i.activated,typeof i.inHiddenRange<"u"&&(this._inHiddenRange=i.inHiddenRange),typeof i.color<"u"&&(this._color=i.color),this.transformByState({width:i.width,height:i.height})}_draw(i){const n=this._activated,r=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 0.35)`,o=`rgb(${this._color.r}, ${this._color.g}, ${this._color.b})`;F.Rect.drawWith(i,{width:this.width,height:this.height,fill:r,stroke:n?o:void 0,strokeWidth:n?2:0,evented:!1})}}const D={id:"sheet.command.replace",type:d.CommandType.COMMAND,handler:async(t,e)=>{const i=t.get(d.IUndoRedoService),n=t.get(d.ICommandService),{unitId:r,replacements:o}=e,s=i.__tempBatchingUndoRedo(r),h=await Promise.all(o.map(c=>n.executeCommand(k.SetRangeValuesCommand.id,{unitId:r,subUnitId:c.subUnitId,value:c.value})));return s.dispose(),Y(h,o)}};function Y(t,e){let i=0,n=0;return t.forEach((r,o)=>{const s=e[o].count;r?i+=s:n+=s}),{success:i,failure:n}}function A(t,e){return t.startRow===e.startRow&&t.startColumn===e.startColumn}function j(t,e){return t.startRow<e.startRow||t.startRow===e.startRow&&t.startColumn<=e.startColumn}function N(t,e){return t.startColumn<e.startColumn||t.startColumn===e.startColumn&&t.startRow<=e.startRow}function Z(t,e){return t.startRow>e.startRow||t.startRow===e.startRow&&t.startColumn>=e.startColumn}function K(t,e){return t.startColumn>e.startColumn||t.startColumn===e.startColumn&&t.startRow>=e.startRow}function z(t,e){const{range:i}=t,{startRow:n,startColumn:r}=i,o=e.getMergedCell(n,r);return o?d.Rectangle.equals(i,o):i.endRow===i.startRow&&i.endColumn===i.startColumn}var J=Object.defineProperty,E=Object.getOwnPropertyDescriptor,x=(t,e,i,n)=>{for(var r=n>1?void 0:n?E(e,i):e,o=t.length-1,s;o>=0;o--)(s=t[o])&&(r=(n?s(e,i,r):s(r))||r);return n&&r&&J(e,i,r),r},v=(t,e)=>(i,n)=>e(i,n,t);u.SheetsFindReplaceController=class extends d.Disposable{constructor(i,n,r,o,s){super();f(this,"_provider");this._injector=i,this._findReplaceController=n,this._contextService=r,this._findReplaceService=o,this._commandService=s,this._init(),this._initCommands()}dispose(){super.dispose(),this._provider.dispose()}_init(){const i=this._injector.createInstance(H);this._provider=i,this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(i)),this.disposeWithMe(this._contextService.subscribeContextValue$(d.EDITOR_ACTIVATED).pipe(R.filter(n=>!!n)).subscribe(()=>this._findReplaceController.closePanel()))}_initCommands(){[D].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}},u.SheetsFindReplaceController=x([d.OnLifecycle(d.LifecycleStages.Steady,u.SheetsFindReplaceController),v(0,S.Inject(S.Injector)),v(1,S.Inject(m.FindReplaceController)),v(2,d.IContextService),v(3,m.IFindReplaceService),v(4,d.ICommandService)],u.SheetsFindReplaceController);const ee="sheets-find-replace-provider",te=1e4;let W=class extends m.FindModel{constructor(e,i,n,r,o,s,h,c,a){super();f(this,"_matchesUpdate$",new R.Subject);f(this,"matchesUpdate$",this._matchesUpdate$.asObservable());f(this,"_activelyChangingMatch$",new R.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);this._workbook=e,this._univerInstanceService=i,this._renderManagerService=n,this._commandService=r,this._contextService=o,this._themeService=s,this._sheetSkeletonManagerService=h,this._selectionManagerService=c,this._findReplaceController=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===m.FindBy.FORMULA?this._toggleDisplayRawFormula(!0):this._toggleDisplayRawFormula(!1),e.findScope){case m.FindScope.UNIT:this.findInWorkbook(e);break;case m.FindScope.SUBUNIT:default:this.findInActiveWorksheet(e);break}}_toggleDisplayRawFormula(e){this._contextService.setContextValue(F.RENDER_RAW_FORMULA_KEY,e)}findInWorkbook(e){const i=this._workbook.getUnitId();let n,r=!0;const o=()=>{const s=this._workbook.getSheets().filter(h=>!h.isSheetHidden()).map(h=>{const c=this._findInWorksheet(h,e,i),a=h.getSheetId(),{results:l}=c;return l.length?this._matchesByWorksheet.set(a,c.results):this._matchesByWorksheet.delete(a),c});this._matches=s.map(h=>h.results).flat(),this._updateFindHighlight(),r?(n={results:this._matches},r=!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).pipe(R.filter(([s,h])=>s.id===k.SetWorksheetActiveOperation.id&&!(h!=null&&h.fromFindReplace))).subscribe(()=>{const s=this._workbook.getActiveSheet(),h=s.getSheetId();this._matchesByWorksheet.has(h)&&this._findNextMatchOnActiveSheetChange(s)})),this.disposeWithMe(d.fromCallback(this._commandService.onCommandExecuted).pipe(R.filter(([s])=>s.type===d.CommandType.MUTATION&&s.params.unitId===this._workbook.getUnitId()),R.throttleTime(600,void 0,{leading:!1,trailing:!0})).subscribe(()=>o())),o(),n}_findNextMatchOnActiveSheetChange(e){let i,n,r=0;const o=this._matchesByWorksheet.get(e.getSheetId()),s=this._selectionManagerService.getSelections();s!=null&&s.length?([i,r]=this._findNextMatchByRange(o,s[0].range),n=o.findIndex(h=>h===i)):(i=o[0],n=0,r=this._matches.findIndex(h=>h===i)),this._matchesPosition=r+1,this._activelyChangingMatch$.next(i),this._activeHighlightIndex=n,this._updateFindHighlight(),this._updateCurrentHighlightShape(n)}findInActiveWorksheet(e){const i=this._workbook.getUnitId(),n=()=>{var g;const c=this._workbook.getActiveSheet(),a=this._selectionManagerService.getSelections();return(g=a==null?void 0:a.some(C=>!z(C,c)))!=null?g:!1};let r,o=!0,s=!1;const h=()=>{const c=this._workbook.getActiveSheet(),a=this.currentMatch;s=n();const l=this._selectionManagerService.getSelections(),g=s?this._findInSelections(c,l,e,i):this._findInWorksheet(c,e,i);return this._matches=g.results,this._matchesPosition=this._tryRestoreLastMatchesPosition(a,this._matches),o?(r=g,o=!1):this._matchesUpdate$.next(this._matches),this._updateFindHighlight(),g};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>this._updateFindHighlight())),this.disposeWithMe(R.merge(d.fromCallback(this._commandService.onCommandExecuted).pipe(R.filter(([c])=>{if(c.type===d.CommandType.MUTATION&&c.params.unitId===this._workbook.getUnitId())return!0;if(c.id===k.SetSelectionsOperation.id&&c.params.unitId===i){const a=n();return a===!1&&s===!1?!1:(s=a,!0)}return!1})),this._workbook.activeSheet$.pipe(R.skip(1))).pipe(R.debounceTime(200)).subscribe(()=>h())),h(),r}_findInRange(e,i,n,r,o){const s=[],h=e.getSheetId(),c=(i.findDirection===m.FindDirection.COLUMN?e.iterateByColumn:e.iterateByRow).bind(e)(n);for(const a of c){const{row:l,col:g,colSpan:C,rowSpan:p,value:I}=a;if(!this._getFindReplacePermissionCheck({row:l,col:g,unitId:r,subUnitId:h})||o!=null&&o(l,g)||!I||e.getRowFiltered(l))continue;const{hit:M,replaceable:w,isFormula:P}=ie(e,l,g,i,I);if(M){const T={provider:ee,unitId:r,replaceable:w,isFormula:P,range:{subUnitId:h,range:{startRow:l,startColumn:g,endColumn:g+(C!=null?C:1)-1,endRow:l+(p!=null?p:1)-1}}};s.push(T)}}return{results:s}}_findInSelections(e,i,n,r){const{findDirection:o}=n,s=o===m.FindDirection.ROW?j:N,h=new Set;return{results:i.map(a=>this._findInRange(e,n,a.range,r,(l,g)=>{const C=`${l}-${g}`;return h.has(C)?!0:(h.add(C),!1)}).results).flat().sort((a,l)=>s(a.range.range,l.range.range)?-1:1)}}_findInWorksheet(e,i,n){const r=e.getRowCount(),o=e.getColumnCount(),s={startRow:0,startColumn:0,endRow:r-1,endColumn:o-1};return this._findInRange(e,i,s,n)}_disposeHighlights(){var e;this._highlightShapes.forEach(i=>{i.getScene().makeDirty(),i.dispose()}),this._highlightShapes=[],(e=this._currentHighlightShape)==null||e.dispose(),this._currentHighlightShape=null}_updateFindHighlight(){var p,I;this._disposeHighlights();const e=(p=this._sheetSkeletonManagerService.getCurrent())==null?void 0:p.skeleton;if(!e||!this._getSheetObject()||((I=this._univerInstanceService.getFocusedUnit())==null?void 0:I.getUnitId())!==this._workbook.getUnitId())return;const r=this._workbook.getUnitId(),o=this._renderManagerService.getRenderById(r);if(o==null)return;const{scene:s}=o,h=this._matches,c=this._themeService.getCurrentTheme().gold400,a=new d.ColorKit(c).toRgb(),l=this._workbook.getActiveSheet(),g=l.getSheetId(),C=h.filter(y=>y.range.subUnitId===g).map((y,M)=>{const{startColumn:w,startRow:P,endColumn:T,endRow:ae}=y.range.range,le=b.getCoordByCell(P,w,s,e),de=b.getCoordByCell(ae,T,s,e),{startX:L,startY:G}=le,{endX:ue,endY:ge}=de,q=!l.getRowRawVisible(P),Q=!l.getColVisible(w),_e=q||Q,fe=Q?2:ue-L,Se=q?2:ge-G,me={left:L,top:G,color:a,width:fe,height:Se,evented:!1,inHiddenRange:_e,zIndex:te};return new X(`find-highlight-${M}`,me)});s.addObjects(C),this._highlightShapes=C,s.makeDirty()}_updateCurrentHighlightShape(e){var i;if((i=this._currentHighlightShape)==null||i.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 b.getSheetObject(this._univerInstanceService,this._renderManagerService)}_focusMatch(e){const i=e.range.subUnitId;i!==this._workbook.getActiveSheet().getSheetId()&&this._commandService.syncExecuteCommand(k.SetWorksheetActivateCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:i},{fromFindReplace:!0}),this._commandService.syncExecuteCommand(b.ScrollToCellCommand.id,{range:e.range.range},{fromFindReplace:!0})}_tryRestoreLastMatchesPosition(e,i){if(!e)return 0;const{subUnitId:n}=e.range,{startColumn:r,startRow:o}=e.range.range,s=i.findIndex(h=>{if(n!==h.range.subUnitId)return!1;const{startColumn:c,startRow:a}=h.range.range;return c===r&&a===o});return s>-1?s+1:0}moveToNextMatch(e){var s,h,c;if(!this._matches.length)return null;const i=(s=e==null?void 0:e.loop)!=null?s:!1,n=(h=e==null?void 0:e.stayIfOnMatch)!=null?h:!1,r=(c=e==null?void 0:e.noFocus)!=null?c:!1,o=this._findNextMatch(i,n);if(o){const[a,l]=o;return this._matchesPosition=l+1,this._query.findScope===m.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(a.range.subUnitId).findIndex(g=>g===a):this._activeHighlightIndex=l,r||this._focusMatch(a),this._workbook.getActiveSheet().getSheetId()===a.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),a}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}moveToPreviousMatch(e){var s,h,c;if(!this._matches.length)return null;const i=(s=e==null?void 0:e.loop)!=null?s:!1,n=(h=e==null?void 0:e.stayIfOnMatch)!=null?h:!1,r=(c=e==null?void 0:e.noFocus)!=null?c:!1,o=this._findPreviousMatch(i,n);if(o){const[a,l]=o;return this._matchesPosition=l+1,this._query.findScope===m.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(a.range.subUnitId).findIndex(g=>g===a):this._activeHighlightIndex=l,r||this._focusMatch(a),this._workbook.getActiveSheet().getSheetId()===a.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),a}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}_findPreviousMatch(e=!1,i=!1){if(this.currentMatch){const s=this._matches.findIndex(l=>l===this.currentMatch);if(i)return[this.currentMatch,s];const h=s-1;if(!e&&h<0)return null;const c=this._matches.length,a=(h+c)%c;return[this._matches[a],a]}const n=this._selectionManagerService.getSelections();if(!(n!=null&&n.length))return[this._matches[0],0];if(this._query.findScope!==m.FindScope.UNIT)return this._findPreviousMatchByRange(this._matches,n[0].range);const r=this._workbook.getActiveSheet().getSheetId(),o=this._findPreviousWorksheetThatHasAMatch(r,e);return o?this._findPreviousMatchByRange(this._matchesByWorksheet.get(o),n[0].range):null}_findNextMatch(e=!1,i=!1){if(this.currentMatch){const s=this._matches.findIndex(l=>l===this.currentMatch);if(i)return[this.currentMatch,s];const h=s+1,c=this._matches.length;if(!e&&h>=c)return null;const a=h%c;return[this._matches[a],a]}const n=this._selectionManagerService.getSelections();if(!(n!=null&&n.length))return[this._matches[0],0];if(this._query.findScope!==m.FindScope.UNIT)return this._findNextMatchByRange(this._matches,n[0].range,i);const r=this._workbook.getActiveSheet().getSheetId(),o=this._findNextWorksheetThatHasAMatch(r,e);return o?this._findNextMatchByRange(this._matchesByWorksheet.get(o),n[0].range):null}_findPreviousWorksheetThatHasAMatch(e,i=!1){const n=this._workbook.getSheetOrders(),r=n.findIndex(h=>h===e),s=(i?d.rotate(n,r+1):n.slice(0,r+1)).findLast(h=>this._matchesByWorksheet.has(h));return s!=null?s:null}_findNextWorksheetThatHasAMatch(e,i=!1){const n=this._workbook.getSheetOrders(),r=n.findIndex(h=>h===e),s=(i?d.rotate(n,r):n.slice(r)).find(h=>this._matchesByWorksheet.has(h));return s!=null?s:null}_findNextMatchByRange(e,i,n=!1){const r=this._query.findDirection===m.FindDirection.ROW;let o=e.findIndex(h=>{const c=h.range.range;if(!(r?j(i,c):N(i,c)))return!1;const l=A(i,c);return n?l:!l});o===-1&&(o=e.length-1);const s=e[o];return[s,this._matches.findIndex(h=>h===s)]}_findPreviousMatchByRange(e,i,n=!1){const r=this._query.findDirection===m.FindDirection.ROW;let o=this._matches.findLastIndex(h=>{const c=h.range.range;if(!(r?Z(i,c):K(i,c)))return!1;const l=A(i,c);return n?l:!l});o===-1&&(o=0);const s=e[o];return[s,this._matches.findIndex(h=>h===s)]}async replace(e){if(this._matchesCount===0||!this.currentMatch||!this._query||!this.currentMatch.replaceable)return!1;const i=this.currentMatch.range,n=this._workbook.getSheetBySheetId(this.currentMatch.range.subUnitId),r=this._getReplacedCellData(this.currentMatch,n,this._query.findBy===m.FindBy.FORMULA,this._query.findString,e,this._query.caseSensitive?"g":"ig"),o={unitId:this.currentMatch.unitId,subUnitId:i.subUnitId,value:{[i.range.startRow]:{[i.range.startColumn]:r}}};return this._commandService.executeCommand(k.SetRangeValuesCommand.id,o)}async replaceAll(e){if(this._matchesCount===0||!this._query)return{success:0,failure:0};const i=this._workbook.getUnitId(),{findString:n,caseSensitive:r,findBy:o}=this._query,s=o===m.FindBy.FORMULA,h=r?"g":"ig",c=[];return d.groupBy(this._matches.filter(l=>l.replaceable),l=>l.range.subUnitId).forEach((l,g)=>{const C=new d.ObjectMatrix,p=this._workbook.getSheetBySheetId(g);l.forEach(I=>{const{startColumn:y,startRow:M}=I.range.range,w=this._getReplacedCellData(I,p,s,n,e,h);w&&C.setValue(M,y,w)}),c.push({count:l.length,subUnitId:g,value:C.getMatrix()})}),c?this._commandService.executeCommand(D.id,{unitId:i,replacements:c}):{success:0,failure:0}}_getReplacedCellData(e,i,n,r,o,s){var p;const h=e.range.range,{startRow:c,startColumn:a}=h,l=i.getCellRaw(c,a);if(e.isFormula)return n?{f:l.f.replace(new RegExp($(r),s),o),v:null}:null;if(!!((p=l.p)!=null&&p.body)){const I=d.Tools.deepClone(l.p);return d.replaceInDocumentBody(I.body,r,o),{p:I}}return{v:l.v.toString().replace(new RegExp($(r),s),o)}}_getFindReplacePermissionCheck(e){var a,l;const{row:i,col:n,subUnitId:r}=e,s=this._univerInstanceService.getCurrentUnitForType(d.UniverInstanceType.UNIVER_SHEET).getSheetBySheetId(r);if(!s)return!1;const h=(l=(a=s.getCell(i,n))==null?void 0:a.selectionProtection)==null?void 0:l[0];return(h==null?void 0:h[O.View])!==!1}};W=x([v(1,d.IUniverInstanceService),v(2,F.IRenderManagerService),v(3,d.ICommandService),v(4,d.IContextService),v(5,S.Inject(d.ThemeService)),v(6,S.Inject(b.SheetSkeletonManagerService)),v(7,S.Inject(k.SelectionManagerService)),v(8,S.Inject(u.SheetsFindReplaceController))],W);function $(t){return t.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}let H=class extends d.Disposable{constructor(e,i){super();f(this,"_findModelsByUnitId",new Map);this._univerInstanceService=e,this._injector=i}async find(e){this._terminate();const i=this._univerInstanceService.getCurrentUnitForType(d.UniverInstanceType.UNIVER_SHEET);if(i){const n=this._injector.createInstance(W,i);this._findModelsByUnitId.set(i.getUnitId(),n);const r=this._preprocessQuery(e);return n.start(r),[n]}return[]}terminate(){this._terminate()}_terminate(){this._findModelsByUnitId.forEach(e=>e.dispose()),this._findModelsByUnitId.clear()}_preprocessQuery(e){let i=e.caseSensitive?e.findString:e.findString.toLowerCase();return i=i.trim(),{...e,findString:i}}};H=x([v(0,d.IUniverInstanceService),v(1,S.Inject(S.Injector))],H);const _={hit:!1,replaceable:!1,isFormula:!1,rawData:null};function ie(t,e,i,n,r){const{findBy:o}=n,s=o===m.FindBy.FORMULA,h=t.getCellRaw(e,i);return _.rawData=h,!(h!=null&&h.f)?(_.isFormula=!1,B(r,n)?h?(_.hit=!0,_.replaceable=!0):(_.hit=!0,_.replaceable=!1):(_.hit=!1,_.replaceable=!1),_):(_.isFormula=!0,s?B({v:h.f},n)?(_.hit=!0,_.replaceable=!0,_):(_.hit=!1,_.replaceable=!1,_):(_.replaceable=!1,B(r,n)?_.hit=!0:_.hit=!1,_))}function B(t,e){let i=ne(t);return i?e.matchesTheWholeCell?(i=se(i),e.caseSensitive?i===e.findString:i.toLowerCase()===e.findString):e.caseSensitive?i.indexOf(e.findString)>-1:i.toLowerCase().indexOf(e.findString)>-1:!1}function ne(t){var i,n,r;const e=(r=(n=(i=t==null?void 0:t.p)==null?void 0:i.body)==null?void 0:n.dataStream)!=null?r:t==null?void 0:t.v;return typeof e=="number"?`${e}`:typeof e=="boolean"?e?"1":"0":e}function se(t){return t.replace(/^ +/g,"").replace(/ +$/g,"")}var re=Object.defineProperty,oe=Object.getOwnPropertyDescriptor,he=(t,e,i,n)=>{for(var r=n>1?void 0:n?oe(e,i):e,o=t.length-1,s;o>=0;o--)(s=t[o])&&(r=(n?s(e,i,r):s(r))||r);return n&&r&&re(e,i,r),r},V=(t,e)=>(i,n)=>e(i,n,t);const ce="SHEET_FIND_REPLACE_PLUGIN";u.UniverSheetsFindReplacePlugin=(U=class extends d.Plugin{constructor(e,i,n){super(),this._injector=i,this._pluginService=n,this._pluginService.registerPlugin(m.UniverFindReplacePlugin)}onStarting(e){[[u.SheetsFindReplaceController]].forEach(i=>e.add(i))}},f(U,"pluginName",ce),f(U,"type",d.UniverInstanceType.UNIVER_SHEET),U),u.UniverSheetsFindReplacePlugin=he([V(1,S.Inject(S.Injector)),V(2,S.Inject(d.PluginService))],u.UniverSheetsFindReplacePlugin),Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-find-replace",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "UniverSheet find replace plugin",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"require": "./lib/cjs/*",
|
|
32
32
|
"types": "./lib/types/index.d.ts"
|
|
33
33
|
},
|
|
34
|
+
"./locale/*": "./lib/locale/*.json",
|
|
34
35
|
"./lib/*": "./lib/*"
|
|
35
36
|
},
|
|
36
37
|
"main": "./lib/cjs/index.js",
|
|
@@ -52,25 +53,28 @@
|
|
|
52
53
|
"peerDependencies": {
|
|
53
54
|
"@wendellhu/redi": "0.15.2",
|
|
54
55
|
"rxjs": ">=7.0.0",
|
|
55
|
-
"@univerjs/core": "0.1.
|
|
56
|
-
"@univerjs/
|
|
57
|
-
"@univerjs/
|
|
58
|
-
"@univerjs/
|
|
59
|
-
"@univerjs/sheets": "0.1.
|
|
56
|
+
"@univerjs/core": "0.1.13",
|
|
57
|
+
"@univerjs/find-replace": "0.1.13",
|
|
58
|
+
"@univerjs/engine-render": "0.1.13",
|
|
59
|
+
"@univerjs/sheets-ui": "0.1.13",
|
|
60
|
+
"@univerjs/sheets": "0.1.13"
|
|
61
|
+
},
|
|
62
|
+
"dependencies": {
|
|
63
|
+
"@univerjs/protocol": "0.1.34"
|
|
60
64
|
},
|
|
61
65
|
"devDependencies": {
|
|
62
66
|
"@wendellhu/redi": "0.15.2",
|
|
63
67
|
"rxjs": "^7.8.1",
|
|
64
68
|
"typescript": "^5.4.5",
|
|
65
|
-
"vite": "^5.2.
|
|
69
|
+
"vite": "^5.2.12",
|
|
66
70
|
"vitest": "^1.6.0",
|
|
67
|
-
"@univerjs/core": "0.1.
|
|
68
|
-
"@univerjs/engine-
|
|
69
|
-
"@univerjs/
|
|
70
|
-
"@univerjs/
|
|
71
|
-
"@univerjs/sheets": "0.1.
|
|
72
|
-
"@univerjs/
|
|
73
|
-
"@univerjs/
|
|
71
|
+
"@univerjs/core": "0.1.13",
|
|
72
|
+
"@univerjs/engine-render": "0.1.13",
|
|
73
|
+
"@univerjs/shared": "0.1.13",
|
|
74
|
+
"@univerjs/engine-formula": "0.1.13",
|
|
75
|
+
"@univerjs/sheets": "0.1.13",
|
|
76
|
+
"@univerjs/find-replace": "0.1.13",
|
|
77
|
+
"@univerjs/sheets-ui": "0.1.13"
|
|
74
78
|
},
|
|
75
79
|
"scripts": {
|
|
76
80
|
"test": "vitest run",
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2023-present DreamNum Inc.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
export { default as enUS } from './en-US';
|
|
17
|
-
export { default as zhCN } from './zh-CN';
|
|
18
|
-
export { default as ruRU } from './ru-RU';
|