@univerjs/sheets-find-replace 0.4.2 → 0.5.0-beta.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/index.js +1 -1
- package/lib/cjs/locale/en-US.js +1 -0
- package/lib/cjs/locale/fa-IR.js +1 -0
- package/lib/cjs/locale/ru-RU.js +1 -0
- package/lib/cjs/locale/vi-VN.js +1 -0
- package/lib/cjs/locale/zh-CN.js +1 -0
- package/lib/cjs/locale/zh-TW.js +1 -0
- package/lib/es/index.js +415 -433
- package/lib/es/locale/en-US.js +11 -0
- package/lib/es/locale/fa-IR.js +11 -0
- package/lib/{locale/ru-RU.json → es/locale/ru-RU.js} +7 -4
- package/lib/{locale/vi-VN.json → es/locale/vi-VN.js} +7 -4
- package/lib/{locale/zh-CN.json → es/locale/zh-CN.js} +7 -4
- package/lib/{locale/zh-TW.json → es/locale/zh-TW.js} +7 -4
- package/lib/umd/index.js +1 -1
- package/lib/umd/locale/en-US.js +1 -0
- package/lib/umd/locale/fa-IR.js +1 -0
- package/lib/umd/locale/ru-RU.js +1 -0
- package/lib/umd/locale/vi-VN.js +1 -0
- package/lib/umd/locale/zh-CN.js +1 -0
- package/lib/umd/locale/zh-TW.js +1 -0
- package/package.json +28 -20
- package/lib/locale/en-US.json +0 -8
- package/lib/locale/fa-IR.json +0 -8
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
{
|
|
1
|
+
const e = {
|
|
2
2
|
"sheet-find-replace": {
|
|
3
|
-
|
|
3
|
+
replace: {
|
|
4
4
|
"partial-failure": "Не удалось заменить некоторые ячейки",
|
|
5
|
-
|
|
5
|
+
failure: "Не удалось заменить все ячейки"
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
|
-
}
|
|
8
|
+
};
|
|
9
|
+
export {
|
|
10
|
+
e as default
|
|
11
|
+
};
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(global,factory){typeof exports=="object"&&typeof module<"u"?factory(exports,require("@univerjs/core"),require("@univerjs/find-replace"),require("@univerjs/sheets"),require("@univerjs/engine-render"),require("@univerjs/sheets-ui"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/find-replace","@univerjs/sheets","@univerjs/engine-render","@univerjs/sheets-ui","rxjs"],factory):(global=typeof globalThis<"u"?globalThis:global||self,factory(global.UniverSheetsFindReplace={},global.UniverCore,global.UniverFindReplace,global.UniverSheets,global.UniverEngineRender,global.UniverSheetsUi,global.rxjs))})(this,function(exports2,core,findReplace,sheets,engineRender,sheetsUi,rxjs){"use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);var _a,_b,_c,_d;const PLUGIN_CONFIG_KEY="sheets-find-replace.config",defaultPluginConfig={},SheetReplaceCommand={id:"sheet.command.replace",type:core.CommandType.COMMAND,handler:__name(async(accessor,params)=>{const undoRedoService=accessor.get(core.IUndoRedoService),commandService=accessor.get(core.ICommandService),{unitId,replacements}=params,disposeBatchingHandler=undoRedoService.__tempBatchingUndoRedo(unitId),results=await Promise.all(replacements.map(replacement=>commandService.executeCommand(sheets.SetRangeValuesCommand.id,{unitId,subUnitId:replacement.subUnitId,value:replacement.value})));return disposeBatchingHandler.dispose(),getReplaceAllResult(results,replacements)},"handler")};function getReplaceAllResult(results,replacements){let success=0,failure=0;return results.forEach((r,index)=>{const count=replacements[index].count;r?success+=count:failure+=count}),{success,failure}}__name(getReplaceAllResult,"getReplaceAllResult");const _SheetFindReplaceHighlightShape=class _SheetFindReplaceHighlightShape extends engineRender.Shape{constructor(key,props){super(key,props);__publicField(this,"_activated",!1);__publicField(this,"_inHiddenRange",!1);__publicField(this,"_color");props&&this.setShapeProps(props)}setShapeProps(props){this._activated=!!props.activated,typeof props.inHiddenRange<"u"&&(this._inHiddenRange=props.inHiddenRange),typeof props.color<"u"&&(this._color=props.color),this.transformByState({width:props.width,height:props.height})}_draw(ctx){const activated=this._activated,color=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 0.35)`,borderColor=`rgb(${this._color.r}, ${this._color.g}, ${this._color.b})`;engineRender.Rect.drawWith(ctx,{width:this.width,height:this.height,fill:color,stroke:activated?borderColor:void 0,strokeWidth:activated?2:0,evented:!1})}};__name(_SheetFindReplaceHighlightShape,"SheetFindReplaceHighlightShape");let SheetFindReplaceHighlightShape=_SheetFindReplaceHighlightShape;function isSamePosition(range1,range2){return range1.startRow===range2.startRow&&range1.startColumn===range2.startColumn}__name(isSamePosition,"isSamePosition");function isBehindPositionWithRowPriority(range1,range2){return range1.startRow<range2.startRow||range1.startRow===range2.startRow&&range1.startColumn<=range2.startColumn}__name(isBehindPositionWithRowPriority,"isBehindPositionWithRowPriority");function isBehindPositionWithColumnPriority(range1,range2){return range1.startColumn<range2.startColumn||range1.startColumn===range2.startColumn&&range1.startRow<=range2.startRow}__name(isBehindPositionWithColumnPriority,"isBehindPositionWithColumnPriority");function isBeforePositionWithRowPriority(range1,range2){return range1.startRow>range2.startRow||range1.startRow===range2.startRow&&range1.startColumn>=range2.startColumn}__name(isBeforePositionWithRowPriority,"isBeforePositionWithRowPriority");function isBeforePositionWithColumnPriority(range1,range2){return range1.startColumn>range2.startColumn||range1.startColumn===range2.startColumn&&range1.startRow>=range2.startRow}__name(isBeforePositionWithColumnPriority,"isBeforePositionWithColumnPriority");function isSelectionSingleCell(selection,worksheet){const{range}=selection,{startRow,startColumn}=range,hasMergedCell=worksheet.getMergedCell(startRow,startColumn);return hasMergedCell?core.Rectangle.equals(range,hasMergedCell):range.endRow===range.startRow&&range.endColumn===range.startColumn}__name(isSelectionSingleCell,"isSelectionSingleCell");var __defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$1");exports2.SheetsFindReplaceController=(_a=class extends core.Disposable{constructor(_injector,_findReplaceController,_contextService,_findReplaceService,_commandService){super();__publicField(this,"_provider");this._injector=_injector,this._findReplaceController=_findReplaceController,this._contextService=_contextService,this._findReplaceService=_findReplaceService,this._commandService=_commandService,this._init(),this._initCommands()}dispose(){super.dispose(),this._findReplaceController.closePanel(),this._provider.dispose()}_init(){const provider=this._injector.createInstance(SheetsFindReplaceProvider);this._provider=provider,this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(provider)),this.disposeWithMe(this._contextService.subscribeContextValue$(core.EDITOR_ACTIVATED).pipe(rxjs.filter(v=>!!v)).subscribe(()=>this._findReplaceController.closePanel()))}_initCommands(){[SheetReplaceCommand].forEach(command=>this.disposeWithMe(this._commandService.registerCommand(command)))}},__name(_a,"SheetsFindReplaceController"),_a),exports2.SheetsFindReplaceController=__decorateClass$1([__decorateParam$1(0,core.Inject(core.Injector)),__decorateParam$1(1,core.Inject(findReplace.FindReplaceController)),__decorateParam$1(2,core.IContextService),__decorateParam$1(3,findReplace.IFindReplaceService),__decorateParam$1(4,core.ICommandService)],exports2.SheetsFindReplaceController);const SHEETS_FIND_REPLACE_PROVIDER_NAME="sheets-find-replace-provider",FIND_REPLACE_Z_INDEX=1e4;let SheetFindModel=(_b=class extends findReplace.FindModel{constructor(_workbook,_sheetSkeletonManagerService,_univerInstanceService,_renderManagerService,_commandService,_contextService,_themeService,_selectionManagerService){super();__publicField(this,"_matchesUpdate$",new rxjs.Subject);__publicField(this,"matchesUpdate$",this._matchesUpdate$.asObservable());__publicField(this,"_activelyChangingMatch$",new rxjs.Subject);__publicField(this,"activelyChangingMatch$",this._activelyChangingMatch$.asObservable());__publicField(this,"_matchesByWorksheet",new Map);__publicField(this,"_matches",[]);__publicField(this,"_matchesPosition",0);__publicField(this,"_activeHighlightIndex",-1);__publicField(this,"_highlightShapes",[]);__publicField(this,"_currentHighlightShape",null);__publicField(this,"_query",null);__publicField(this,"_workbookSelections");this._workbook=_workbook,this._sheetSkeletonManagerService=_sheetSkeletonManagerService,this._univerInstanceService=_univerInstanceService,this._renderManagerService=_renderManagerService,this._commandService=_commandService,this._contextService=_contextService,this._themeService=_themeService,this._workbookSelections=_selectionManagerService.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(query){switch(this._query=query,query.findBy===findReplace.FindBy.FORMULA?this._toggleDisplayRawFormula(!0):this._toggleDisplayRawFormula(!1),query.findScope){case findReplace.FindScope.UNIT:this.findInWorkbook(query);break;case findReplace.FindScope.SUBUNIT:default:this.findInActiveWorksheet(query);break}}_toggleDisplayRawFormula(force){this._contextService.setContextValue(engineRender.RENDER_RAW_FORMULA_KEY,force)}findInWorkbook(query){const unitId=this._workbook.getUnitId();let complete,firstSearch=!0;const findInWorkbook=__name(()=>{const allCompletes=this._workbook.getSheets().filter(worksheet=>!worksheet.isSheetHidden()).map(worksheet=>{const complete2=this._findInWorksheet(worksheet,query,unitId),sheetId=worksheet.getSheetId(),{results}=complete2;return results.length?this._matchesByWorksheet.set(sheetId,complete2.results):this._matchesByWorksheet.delete(sheetId),complete2});this._matches=allCompletes.map(c=>c.results).flat(),this._updateFindHighlight(),firstSearch?(complete={results:this._matches},firstSearch=!1):this._matchesUpdate$.next(this._matches)},"findInWorkbook");return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>{this._updateFindHighlight(),this._updateCurrentHighlightShape(this._activeHighlightIndex)})),this.disposeWithMe(core.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(rxjs.filter(([command,options])=>command.id===sheets.SetWorksheetActiveOperation.id&&!(options!=null&&options.fromFindReplace))).subscribe(()=>{const activeSheet=this._workbook.getActiveSheet();if(!activeSheet)return;const activeSheetId=activeSheet.getSheetId();this._matchesByWorksheet.has(activeSheetId)&&this._findNextMatchOnActiveSheetChange(activeSheet)})),this.disposeWithMe(core.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(rxjs.filter(([command])=>command.type===core.CommandType.MUTATION&&command.params.unitId===this._workbook.getUnitId()),rxjs.throttleTime(600,void 0,{leading:!1,trailing:!0})).subscribe(()=>findInWorkbook())),findInWorkbook(),complete}_findNextMatchOnActiveSheetChange(activeSheet){let match,index,globalIndex=0;const matchesByWorksheet=this._matchesByWorksheet.get(activeSheet.getSheetId()),selections=this._workbookSelections.getCurrentSelections();selections!=null&&selections.length?([match,globalIndex]=this._findNextMatchByRange(matchesByWorksheet,selections[0].range),index=matchesByWorksheet.findIndex(m=>m===match)):(match=matchesByWorksheet[0],index=0,globalIndex=this._matches.findIndex(m=>m===match)),this._matchesPosition=globalIndex+1,this._activelyChangingMatch$.next(match),this._activeHighlightIndex=index,this._updateFindHighlight(),this._updateCurrentHighlightShape(index)}findInActiveWorksheet(query){const unitId=this._workbook.getUnitId(),checkShouldFindInSelections=__name(()=>{var _a2;const currentWorksheet=this._workbook.getActiveSheet();if(!currentWorksheet)return!1;const currentSelections=this._workbookSelections.getCurrentSelections();return(_a2=currentSelections==null?void 0:currentSelections.some(selection=>!isSelectionSingleCell(selection,currentWorksheet)))!=null?_a2:!1},"checkShouldFindInSelections");let complete,firstSearch=!0,findBySelections=!1;const performFindInWorksheet=__name(()=>{const currentWorksheet=this._workbook.getActiveSheet();if(!currentWorksheet)return{results:[]};const lastMatch=this.currentMatch;findBySelections=checkShouldFindInSelections();const currentSelections=this._workbookSelections.getCurrentSelections(),newComplete=findBySelections?this._findInSelections(currentWorksheet,currentSelections,query,unitId):this._findInWorksheet(currentWorksheet,query,unitId);return this._matches=newComplete.results,this._matchesPosition=this._tryRestoreLastMatchesPosition(lastMatch,this._matches),firstSearch?(complete=newComplete,firstSearch=!1):this._matchesUpdate$.next(this._matches),this._updateFindHighlight(),newComplete},"performFindInWorksheet");return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>this._updateFindHighlight())),this.disposeWithMe(rxjs.merge(core.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(rxjs.filter(([command])=>{if(command.type===core.CommandType.MUTATION&&command.params.unitId===this._workbook.getUnitId())return!0;if(command.id===sheets.SetSelectionsOperation.id&&command.params.unitId===unitId){const shouldFindBySelections=checkShouldFindInSelections();return shouldFindBySelections===!1&&findBySelections===!1?!1:(findBySelections=shouldFindBySelections,!0)}return!1})),this._workbook.activeSheet$.pipe(rxjs.skip(1))).pipe(rxjs.debounceTime(200)).subscribe(()=>performFindInWorksheet())),performFindInWorksheet(),complete}_findInRange(worksheet,query,range,unitId,dedupeFn){const results=[],subUnitId=worksheet.getSheetId(),iter=(query.findDirection===findReplace.FindDirection.COLUMN?worksheet.iterateByColumn:worksheet.iterateByRow).bind(worksheet)(range);for(const value of iter){const{row,col,colSpan,rowSpan,value:cellData}=value;if(dedupeFn!=null&&dedupeFn(row,col)||!cellData||worksheet.getRowFiltered(row))continue;const{hit,replaceable,isFormula}=hitCell(worksheet,row,col,query,cellData);if(hit){const result={provider:SHEETS_FIND_REPLACE_PROVIDER_NAME,unitId,replaceable,isFormula,range:{subUnitId,range:{startRow:row,startColumn:col,endColumn:col+(colSpan!=null?colSpan:1)-1,endRow:row+(rowSpan!=null?rowSpan:1)-1}}};results.push(result)}}return{results}}_findInSelections(worksheet,selections,query,unitId){const{findDirection}=query,sortFn=findDirection===findReplace.FindDirection.ROW?isBehindPositionWithRowPriority:isBehindPositionWithColumnPriority,dedupeSet=new Set;return{results:selections.map(selection=>this._findInRange(worksheet,query,selection.range,unitId,(row,col)=>{const key=`${row}-${col}`;return dedupeSet.has(key)?!0:(dedupeSet.add(key),!1)}).results).flat().sort((a,b)=>sortFn(a.range.range,b.range.range)?-1:1)}}_findInWorksheet(worksheet,query,unitId){const rowCount=worksheet.getRowCount(),colCount=worksheet.getColumnCount(),range={startRow:0,startColumn:0,endRow:rowCount-1,endColumn:colCount-1};return this._findInRange(worksheet,query,range,unitId)}_disposeHighlights(){var _a2;this._highlightShapes.forEach(shape=>{var _a3;(_a3=shape.getScene())==null||_a3.makeDirty(),shape.dispose()}),this._highlightShapes=[],(_a2=this._currentHighlightShape)==null||_a2.dispose(),this._currentHighlightShape=null}_updateFindHighlight(){var _a2;this._disposeHighlights();const skeleton=(_a2=this._sheetSkeletonManagerService.getCurrent())==null?void 0:_a2.skeleton;if(!skeleton)return;const unitId=this._workbook.getUnitId(),currentRender=this._renderManagerService.getRenderById(unitId);if(currentRender==null)return;const{scene}=currentRender,matches=this._matches,searchBackgroundColor=this._themeService.getCurrentTheme().gold400,color=new core.ColorKit(searchBackgroundColor).toRgb(),worksheet=this._workbook.getActiveSheet();if(!worksheet)return;const activeSheetId=worksheet.getSheetId(),highlightShapes=matches.filter(match=>match.range.subUnitId===activeSheetId).map((find,index)=>{const{startColumn,startRow,endColumn,endRow}=find.range.range,startPosition=sheetsUi.getCoordByCell(startRow,startColumn,scene,skeleton),endPosition=sheetsUi.getCoordByCell(endRow,endColumn,scene,skeleton),{startX,startY}=startPosition,{endX,endY}=endPosition,rowHidden=!worksheet.getRowRawVisible(startRow),columnHidden=!worksheet.getColVisible(startColumn),inHiddenRange=rowHidden||columnHidden,width=columnHidden?2:endX-startX,height=rowHidden?2:endY-startY,props={left:startX,top:startY,color,width,height,evented:!1,inHiddenRange,zIndex:FIND_REPLACE_Z_INDEX};return new SheetFindReplaceHighlightShape(`find-highlight-${index}`,props)});scene.addObjects(highlightShapes),this._highlightShapes=highlightShapes,scene.makeDirty()}_updateCurrentHighlightShape(matchIndex){var _a2;if((_a2=this._currentHighlightShape)==null||_a2.setShapeProps({activated:!1}),this._currentHighlightShape=null,matchIndex!==void 0){const shape=this._highlightShapes[matchIndex];if(!shape)return;this._currentHighlightShape=shape,shape.setShapeProps({activated:!0})}}_getSheetObject(){return sheetsUi.getSheetObject(this._univerInstanceService,this._renderManagerService)}_focusMatch(match){var _a2;const subUnitId=match.range.subUnitId;subUnitId!==((_a2=this._workbook.getActiveSheet())==null?void 0:_a2.getSheetId())&&this._commandService.executeCommand(sheets.SetWorksheetActivateCommand.id,{unitId:this._workbook.getUnitId(),subUnitId},{fromFindReplace:!0}),this._commandService.executeCommand(sheetsUi.ScrollToCellCommand.id,{range:match.range.range},{fromFindReplace:!0})}_tryRestoreLastMatchesPosition(lastMatch,newMatches){if(!lastMatch)return 0;const{subUnitId:lastSubUnitId}=lastMatch.range,{startColumn:lastStartColumn,startRow:lastStartRow}=lastMatch.range.range,index=newMatches.findIndex(match=>{if(lastSubUnitId!==match.range.subUnitId)return!1;const{startColumn,startRow}=match.range.range;return startColumn===lastStartColumn&&startRow===lastStartRow});return index>-1?index+1:0}moveToNextMatch(params){var _a2,_b2,_c2,_d2,_e;if(!this._matches.length)return null;const loop=(_a2=params==null?void 0:params.loop)!=null?_a2:!1,stayIfOnMatch=(_b2=params==null?void 0:params.stayIfOnMatch)!=null?_b2:!1,noFocus=(_c2=params==null?void 0:params.noFocus)!=null?_c2:!1,ignoreSelection=(_d2=params==null?void 0:params.ignoreSelection)!=null?_d2:!1,matchToMove=this._findNextMatch(loop,stayIfOnMatch,ignoreSelection);if(matchToMove){const[match,index]=matchToMove;return this._matchesPosition=index+1,this._query.findScope===findReplace.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(match.range.subUnitId).findIndex(m=>m===match):this._activeHighlightIndex=index,noFocus||this._focusMatch(match),((_e=this._workbook.getActiveSheet())==null?void 0:_e.getSheetId())===match.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),match}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}moveToPreviousMatch(params){var _a2,_b2,_c2,_d2,_e;if(!this._matches.length)return null;const loop=(_a2=params==null?void 0:params.loop)!=null?_a2:!1,stayIfOnMatch=(_b2=params==null?void 0:params.stayIfOnMatch)!=null?_b2:!1,noFocus=(_c2=params==null?void 0:params.noFocus)!=null?_c2:!1,ignoreSelection=(_d2=params==null?void 0:params.ignoreSelection)!=null?_d2:!1,matchToMove=this._findPreviousMatch(loop,stayIfOnMatch,ignoreSelection);if(matchToMove){const[match,index]=matchToMove;return this._matchesPosition=index+1,this._query.findScope===findReplace.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(match.range.subUnitId).findIndex(m=>m===match):this._activeHighlightIndex=index,noFocus||this._focusMatch(match),((_e=this._workbook.getActiveSheet())==null?void 0:_e.getSheetId())===match.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),match}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}_findPreviousMatch(loop=!1,stayIfOnMatch=!1,ignoreSelection=!1){var _a2;if(this.currentMatch){const currentMatchIndex=this._matches.findIndex(match=>match===this.currentMatch);if(stayIfOnMatch)return[this.currentMatch,currentMatchIndex];const nextMatchIndex=currentMatchIndex-1;if(!loop&&nextMatchIndex<0)return null;const length=this._matches.length,modded=(nextMatchIndex+length)%length;return[this._matches[modded],modded]}const lastSelection=this._workbookSelections.getCurrentLastSelection();if(ignoreSelection||!lastSelection){const lastIndex=this._matches.length-1;return[this._matches[lastIndex],lastIndex]}if(this._query.findScope!==findReplace.FindScope.UNIT)return this._findPreviousMatchByRange(this._matches,lastSelection.range);const currentSheetId=(_a2=this._workbook.getActiveSheet())==null?void 0:_a2.getSheetId();if(!currentSheetId)return null;const worksheetThatHasMatch=this._findPreviousWorksheetThatHasAMatch(currentSheetId,loop);return worksheetThatHasMatch?this._findPreviousMatchByRange(this._matchesByWorksheet.get(worksheetThatHasMatch),lastSelection.range):null}_findNextMatch(loop=!1,stayIfOnMatch=!1,ignoreSelection=!1){var _a2;if(this.currentMatch){const currentMatchIndex=this._matches.findIndex(match=>match===this.currentMatch);if(stayIfOnMatch)return[this.currentMatch,currentMatchIndex];const nextMatchIndex=currentMatchIndex+1,length=this._matches.length;if(!loop&&nextMatchIndex>=length)return null;const modded=nextMatchIndex%length;return[this._matches[modded],modded]}const last=this._workbookSelections.getCurrentLastSelection();if(ignoreSelection||!last)return[this._matches[0],0];if(this._query.findScope!==findReplace.FindScope.UNIT)return this._findNextMatchByRange(this._matches,last.range,stayIfOnMatch);const currentSheetId=(_a2=this._workbook.getActiveSheet())==null?void 0:_a2.getSheetId();if(!currentSheetId)return null;const worksheetThatHasMatch=this._findNextWorksheetThatHasAMatch(currentSheetId,loop);return worksheetThatHasMatch?this._findNextMatchByRange(this._matchesByWorksheet.get(worksheetThatHasMatch),last.range):null}_findPreviousWorksheetThatHasAMatch(currentWorksheet,loop=!1){const rawWorksheetsInOrder=this._workbook.getSheetOrders(),currentSheetIndex=rawWorksheetsInOrder.findIndex(sheet=>sheet===currentWorksheet),first=(loop?core.rotate(rawWorksheetsInOrder,currentSheetIndex+1):rawWorksheetsInOrder.slice(0,currentSheetIndex+1)).findLast(worksheet=>this._matchesByWorksheet.has(worksheet));return first!=null?first:null}_findNextWorksheetThatHasAMatch(currentWorksheet,loop=!1){const rawWorksheetsInOrder=this._workbook.getSheetOrders(),currentSheetIndex=rawWorksheetsInOrder.findIndex(sheet=>sheet===currentWorksheet),first=(loop?core.rotate(rawWorksheetsInOrder,currentSheetIndex):rawWorksheetsInOrder.slice(currentSheetIndex)).find(worksheet=>this._matchesByWorksheet.has(worksheet));return first!=null?first:null}_findNextMatchByRange(matches,range,stayIfOnMatch=!1){const findByRow=this._query.findDirection===findReplace.FindDirection.ROW;let index=matches.findIndex(match2=>{const matchRange=match2.range.range;if(!(findByRow?isBehindPositionWithRowPriority(range,matchRange):isBehindPositionWithColumnPriority(range,matchRange)))return!1;const isSame=isSamePosition(range,matchRange);return stayIfOnMatch?isSame:!isSame});index===-1&&(index=matches.length-1);const match=matches[index];return[match,this._matches.findIndex(m=>m===match)]}_findPreviousMatchByRange(matches,range,stayIfOnMatch=!1){const findByRow=this._query.findDirection===findReplace.FindDirection.ROW;let index=this._matches.findLastIndex(match2=>{const matchRange=match2.range.range;if(!(findByRow?isBeforePositionWithRowPriority(range,matchRange):isBeforePositionWithColumnPriority(range,matchRange)))return!1;const isSame=isSamePosition(range,matchRange);return stayIfOnMatch?isSame:!isSame});index===-1&&(index=0);const match=matches[index];return[match,this._matches.findIndex(m=>m===match)]}async replace(replaceString){if(this._matchesCount===0||!this.currentMatch||!this._query||!this.currentMatch.replaceable)return!1;const range=this.currentMatch.range,targetWorksheet=this._workbook.getSheetBySheetId(this.currentMatch.range.subUnitId),newContent=this._getReplacedCellData(this.currentMatch,targetWorksheet,this._query.findBy===findReplace.FindBy.FORMULA,this._query.findString,replaceString,this._query.caseSensitive?"g":"ig"),params={unitId:this.currentMatch.unitId,subUnitId:range.subUnitId,value:{[range.range.startRow]:{[range.range.startColumn]:newContent}}};return this._commandService.executeCommand(sheets.SetRangeValuesCommand.id,params)}async replaceAll(replaceString){if(this._matchesCount===0||!this._query)return{success:0,failure:0};const unitId=this._workbook.getUnitId(),{findString,caseSensitive,findBy}=this._query,shouldReplaceFormula=findBy===findReplace.FindBy.FORMULA,replaceFlag=caseSensitive?"g":"ig",replacements=[];return core.groupBy(this._matches.filter(m=>m.replaceable),match=>match.range.subUnitId).forEach((matches,subUnitId)=>{const matrix=new core.ObjectMatrix,worksheet=this._workbook.getSheetBySheetId(subUnitId);matches.forEach(match=>{const{startColumn,startRow}=match.range.range,newCellData=this._getReplacedCellData(match,worksheet,shouldReplaceFormula,findString,replaceString,replaceFlag);newCellData&&matrix.setValue(startRow,startColumn,newCellData)}),replacements.push({count:matches.length,subUnitId,value:matrix.getMatrix()})}),replacements?this._commandService.executeCommand(SheetReplaceCommand.id,{unitId,replacements}):{success:0,failure:0}}_getReplacedCellData(match,worksheet,shouldReplaceFormula,findString,replaceString,replaceFlag){var _a2;const range=match.range.range,{startRow,startColumn}=range,currentContent=worksheet.getCellRaw(startRow,startColumn);if(match.isFormula)return shouldReplaceFormula?{f:currentContent.f.replace(new RegExp(escapeRegExp(findString),replaceFlag),replaceString),v:null}:null;if(!!((_a2=currentContent.p)!=null&&_a2.body)){const clonedRichText=core.Tools.deepClone(currentContent.p);return core.replaceInDocumentBody(clonedRichText.body,findString,replaceString),{p:clonedRichText}}return{v:currentContent.v.toString().replace(new RegExp(escapeRegExp(findString),replaceFlag),replaceString)}}},__name(_b,"SheetFindModel"),_b);SheetFindModel=__decorateClass$1([__decorateParam$1(2,core.IUniverInstanceService),__decorateParam$1(3,engineRender.IRenderManagerService),__decorateParam$1(4,core.ICommandService),__decorateParam$1(5,core.IContextService),__decorateParam$1(6,core.Inject(core.ThemeService)),__decorateParam$1(7,core.Inject(sheets.SheetsSelectionsService))],SheetFindModel);function escapeRegExp(text){return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}__name(escapeRegExp,"escapeRegExp");let SheetsFindReplaceProvider=(_c=class extends core.Disposable{constructor(_univerInstanceService,_renderManagerService,_injector){super();__publicField(this,"_findModelsByUnitId",new Map);this._univerInstanceService=_univerInstanceService,this._renderManagerService=_renderManagerService,this._injector=_injector}async find(query){this._terminate();const allWorkbooks=this._univerInstanceService.getAllUnitsForType(core.UniverInstanceType.UNIVER_SHEET),parsedQuery=this._preprocessQuery(query);return allWorkbooks.map(workbook=>{const skeletonManagerService=this._renderManagerService.getRenderById(workbook.getUnitId()).with(sheetsUi.SheetSkeletonManagerService),sheetFind=this._injector.createInstance(SheetFindModel,workbook,skeletonManagerService);return this._findModelsByUnitId.set(workbook.getUnitId(),sheetFind),sheetFind.start(parsedQuery),sheetFind})}terminate(){this._terminate()}_terminate(){this._findModelsByUnitId.forEach(model=>model.dispose()),this._findModelsByUnitId.clear()}_preprocessQuery(query){let findString=query.caseSensitive?query.findString:query.findString.toLowerCase();return findString=findString.trim(),{...query,findString}}},__name(_c,"SheetsFindReplaceProvider"),_c);SheetsFindReplaceProvider=__decorateClass$1([__decorateParam$1(0,core.IUniverInstanceService),__decorateParam$1(1,engineRender.IRenderManagerService),__decorateParam$1(2,core.Inject(core.Injector))],SheetsFindReplaceProvider);const VALUE_PASSING_OBJECT={hit:!1,replaceable:!1,isFormula:!1,rawData:null};function hitCell(worksheet,row,col,query,cellData){const{findBy}=query,findByFormula=findBy===findReplace.FindBy.FORMULA,rawData=worksheet.getCellRaw(row,col);return VALUE_PASSING_OBJECT.rawData=rawData,!(rawData!=null&&rawData.f)?(VALUE_PASSING_OBJECT.isFormula=!1,matchCellData(cellData,query)?rawData?(VALUE_PASSING_OBJECT.hit=!0,VALUE_PASSING_OBJECT.replaceable=!0):(VALUE_PASSING_OBJECT.hit=!0,VALUE_PASSING_OBJECT.replaceable=!1):(VALUE_PASSING_OBJECT.hit=!1,VALUE_PASSING_OBJECT.replaceable=!1),VALUE_PASSING_OBJECT):(VALUE_PASSING_OBJECT.isFormula=!0,findByFormula?matchCellData({v:rawData.f},query)?(VALUE_PASSING_OBJECT.hit=!0,VALUE_PASSING_OBJECT.replaceable=!0,VALUE_PASSING_OBJECT):(VALUE_PASSING_OBJECT.hit=!1,VALUE_PASSING_OBJECT.replaceable=!1,VALUE_PASSING_OBJECT):(VALUE_PASSING_OBJECT.replaceable=!1,matchCellData(cellData,query)?VALUE_PASSING_OBJECT.hit=!0:VALUE_PASSING_OBJECT.hit=!1,VALUE_PASSING_OBJECT))}__name(hitCell,"hitCell");function matchCellData(cellData,query){let value=extractPureValue(cellData);return value?query.matchesTheWholeCell?(value=trimLeadingTrailingWhitespace(value),query.caseSensitive?value===query.findString:value.toLowerCase()===query.findString):query.caseSensitive?value.indexOf(query.findString)>-1:value.toLowerCase().indexOf(query.findString)>-1:!1}__name(matchCellData,"matchCellData");function extractPureValue(cell){var _a2,_b2,_c2;const rawValue=(_c2=(_b2=(_a2=cell==null?void 0:cell.p)==null?void 0:_a2.body)==null?void 0:_b2.dataStream)!=null?_c2:cell==null?void 0:cell.v;return typeof rawValue=="number"?`${rawValue}`:typeof rawValue=="boolean"?rawValue?"1":"0":rawValue}__name(extractPureValue,"extractPureValue");function trimLeadingTrailingWhitespace(value){return value.replace(/^ +/g,"").replace(/ +$/g,"")}__name(trimLeadingTrailingWhitespace,"trimLeadingTrailingWhitespace");var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__defNormalProp2=__name((obj,key,value)=>key in obj?__defProp2(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value,"__defNormalProp"),__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam"),__publicField2=__name((obj,key,value)=>__defNormalProp2(obj,typeof key!="symbol"?key+"":key,value),"__publicField");const NAME="SHEET_FIND_REPLACE_PLUGIN";exports2.UniverSheetsFindReplacePlugin=(_d=class extends core.Plugin{constructor(_config=defaultPluginConfig,_injector,_configService){super(),this._config=_config,this._injector=_injector,this._configService=_configService;const{...rest}=this._config;this._configService.setConfig(PLUGIN_CONFIG_KEY,rest)}onStarting(){[[exports2.SheetsFindReplaceController]].forEach(d=>this._injector.add(d))}onSteady(){this._injector.get(exports2.SheetsFindReplaceController)}},__name(_d,"UniverSheetsFindReplacePlugin"),_d),__publicField2(exports2.UniverSheetsFindReplacePlugin,"pluginName",NAME),__publicField2(exports2.UniverSheetsFindReplacePlugin,"type",core.UniverInstanceType.UNIVER_SHEET),exports2.UniverSheetsFindReplacePlugin=__decorateClass([core.DependentOn(sheets.UniverSheetsPlugin,sheets.UniverSheetsPlugin,findReplace.UniverFindReplacePlugin),__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.IConfigService)],exports2.UniverSheetsFindReplacePlugin),exports2.SheetReplaceCommand=SheetReplaceCommand,Object.defineProperty(exports2,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(_,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/find-replace"),require("@univerjs/sheets"),require("@univerjs/engine-render"),require("@univerjs/sheets-ui"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/find-replace","@univerjs/sheets","@univerjs/engine-render","@univerjs/sheets-ui","rxjs"],a):(_=typeof globalThis<"u"?globalThis:_||self,a(_.UniverSheetsFindReplace={},_.UniverCore,_.UniverFindReplace,_.UniverSheets,_.UniverEngineRender,_.UniverSheetsUi,_.rxjs))})(this,function(_,a,f,R,k,M,C){"use strict";var Se=Object.defineProperty;var me=(_,a,f)=>a in _?Se(_,a,{enumerable:!0,configurable:!0,writable:!0,value:f}):_[a]=f;var m=(_,a,f)=>me(_,typeof a!="symbol"?a+"":a,f);const G="sheets-find-replace.config",Y={},F={id:"sheet.command.replace",type:a.CommandType.COMMAND,handler:async(h,e)=>{const t=h.get(a.IUndoRedoService),i=h.get(a.ICommandService),{unitId:n,replacements:r}=e,s=t.__tempBatchingUndoRedo(n),o=await Promise.all(r.map(c=>i.executeCommand(R.SetRangeValuesCommand.id,{unitId:n,subUnitId:c.subUnitId,value:c.value})));return s.dispose(),q(o,r)}};function q(h,e){let t=0,i=0;return h.forEach((n,r)=>{const s=e[r].count;n?t+=s:i+=s}),{success:t,failure:i}}class K extends k.Shape{constructor(t,i){super(t,i);m(this,"_activated",!1);m(this,"_inHiddenRange",!1);m(this,"_color");i&&this.setShapeProps(i)}setShapeProps(t){this._activated=!!t.activated,typeof t.inHiddenRange<"u"&&(this._inHiddenRange=t.inHiddenRange),typeof t.color<"u"&&(this._color=t.color),this.transformByState({width:t.width,height:t.height})}_draw(t){const i=this._activated,n=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 0.35)`,r=`rgb(${this._color.r}, ${this._color.g}, ${this._color.b})`;k.Rect.drawWith(t,{width:this.width,height:this.height,fill:n,stroke:i?r:void 0,strokeWidth:i?2:0,evented:!1})}}function T(h,e){return h.startRow===e.startRow&&h.startColumn===e.startColumn}function H(h,e){return h.startRow<e.startRow||h.startRow===e.startRow&&h.startColumn<=e.startColumn}function O(h,e){return h.startColumn<e.startColumn||h.startColumn===e.startColumn&&h.startRow<=e.startRow}function 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.defineProperty,Z=Object.getOwnPropertyDescriptor,U=(h,e,t,i)=>{for(var n=i>1?void 0:i?Z(e,t):e,r=h.length-1,s;r>=0;r--)(s=h[r])&&(n=(i?s(e,t,n):s(n))||n);return i&&n&&J(e,t,n),n},p=(h,e)=>(t,i)=>e(t,i,h);_.SheetsFindReplaceController=class extends a.Disposable{constructor(t,i,n,r,s){super();m(this,"_provider");this._injector=t,this._findReplaceController=i,this._contextService=n,this._findReplaceService=r,this._commandService=s,this._init(),this._initCommands()}dispose(){super.dispose(),this._findReplaceController.closePanel(),this._provider.dispose()}_init(){const t=this._injector.createInstance(x);this._provider=t,this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(t)),this.disposeWithMe(this._contextService.subscribeContextValue$(a.EDITOR_ACTIVATED).pipe(C.filter(i=>!!i)).subscribe(()=>this._findReplaceController.closePanel()))}_initCommands(){[F].forEach(t=>this.disposeWithMe(this._commandService.registerCommand(t)))}},_.SheetsFindReplaceController=U([p(0,a.Inject(a.Injector)),p(1,a.Inject(f.FindReplaceController)),p(2,a.IContextService),p(3,f.IFindReplaceService),p(4,a.ICommandService)],_.SheetsFindReplaceController);const ee="sheets-find-replace-provider",te=1e4;let P=class extends f.FindModel{constructor(e,t,i,n,r,s,o,c){super();m(this,"_matchesUpdate$",new C.Subject);m(this,"matchesUpdate$",this._matchesUpdate$.asObservable());m(this,"_activelyChangingMatch$",new C.Subject);m(this,"activelyChangingMatch$",this._activelyChangingMatch$.asObservable());m(this,"_matchesByWorksheet",new Map);m(this,"_matches",[]);m(this,"_matchesPosition",0);m(this,"_activeHighlightIndex",-1);m(this,"_highlightShapes",[]);m(this,"_currentHighlightShape",null);m(this,"_query",null);m(this,"_workbookSelections");this._workbook=e,this._sheetSkeletonManagerService=t,this._univerInstanceService=i,this._renderManagerService=n,this._commandService=r,this._contextService=s,this._themeService=o,this._workbookSelections=c.getWorkbookSelections(this.unitId)}get _matchesCount(){return this._matches.length}get unitId(){return this._workbook.getUnitId()}get matchesCount(){return this._matchesCount}get matchesPosition(){return this._matchesPosition}get currentMatch(){return this._matchesPosition>0?this._matches[this._matchesPosition-1]:null}dispose(){super.dispose(),this._disposeHighlights(),this._toggleDisplayRawFormula(!1)}getMatches(){return this._matches}start(e){switch(this._query=e,e.findBy===f.FindBy.FORMULA?this._toggleDisplayRawFormula(!0):this._toggleDisplayRawFormula(!1),e.findScope){case f.FindScope.UNIT:this.findInWorkbook(e);break;case f.FindScope.SUBUNIT:default:this.findInActiveWorksheet(e);break}}_toggleDisplayRawFormula(e){this._contextService.setContextValue(k.RENDER_RAW_FORMULA_KEY,e)}findInWorkbook(e){const t=this._workbook.getUnitId();let i,n=!0;const r=()=>{const s=this._workbook.getSheets().filter(o=>!o.isSheetHidden()).map(o=>{const c=this._findInWorksheet(o,e,t),d=o.getSheetId(),{results:l}=c;return l.length?this._matchesByWorksheet.set(d,c.results):this._matchesByWorksheet.delete(d),c});this._matches=s.map(o=>o.results).flat(),this._updateFindHighlight(),n?(i={results:this._matches},n=!1):this._matchesUpdate$.next(this._matches)};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>{this._updateFindHighlight(),this._updateCurrentHighlightShape(this._activeHighlightIndex)})),this.disposeWithMe(a.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(C.filter(([s,o])=>s.id===R.SetWorksheetActiveOperation.id&&!(o!=null&&o.fromFindReplace))).subscribe(()=>{const s=this._workbook.getActiveSheet();if(!s)return;const o=s.getSheetId();this._matchesByWorksheet.has(o)&&this._findNextMatchOnActiveSheetChange(s)})),this.disposeWithMe(a.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(C.filter(([s])=>s.type===a.CommandType.MUTATION&&s.params.unitId===this._workbook.getUnitId()),C.throttleTime(600,void 0,{leading:!1,trailing:!0})).subscribe(()=>r())),r(),i}_findNextMatchOnActiveSheetChange(e){let t,i,n=0;const r=this._matchesByWorksheet.get(e.getSheetId()),s=this._workbookSelections.getCurrentSelections();s!=null&&s.length?([t,n]=this._findNextMatchByRange(r,s[0].range),i=r.findIndex(o=>o===t)):(t=r[0],i=0,n=this._matches.findIndex(o=>o===t)),this._matchesPosition=n+1,this._activelyChangingMatch$.next(t),this._activeHighlightIndex=i,this._updateFindHighlight(),this._updateCurrentHighlightShape(i)}findInActiveWorksheet(e){const t=this._workbook.getUnitId(),i=()=>{var u;const c=this._workbook.getActiveSheet();if(!c)return!1;const d=this._workbookSelections.getCurrentSelections();return(u=d==null?void 0:d.some(g=>!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(C.merge(a.fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(C.filter(([c])=>{if(c.type===a.CommandType.MUTATION&&c.params.unitId===this._workbook.getUnitId())return!0;if(c.id===R.SetSelectionsOperation.id&&c.params.unitId===t){const d=i();return d===!1&&s===!1?!1:(s=d,!0)}return!1})),this._workbook.activeSheet$.pipe(C.skip(1))).pipe(C.debounceTime(200)).subscribe(()=>o())),o(),n}_findInRange(e,t,i,n,r){const s=[],o=e.getSheetId(),c=(t.findDirection===f.FindDirection.COLUMN?e.iterateByColumn:e.iterateByRow).bind(e)(i);for(const d of c){const{row:l,col:u,colSpan:g,rowSpan:v,value:I}=d;if(r!=null&&r(l,u)||!I||e.getRowFiltered(l))continue;const{hit:b,replaceable:y,isFormula:w}=ie(e,l,u,t,I);if(b){const W={provider:ee,unitId:n,replaceable:y,isFormula:w,range:{subUnitId:o,range:{startRow:l,startColumn:u,endColumn:u+(g!=null?g:1)-1,endRow:l+(v!=null?v:1)-1}}};s.push(W)}}return{results:s}}_findInSelections(e,t,i,n){const{findDirection:r}=i,s=r===f.FindDirection.ROW?H:O,o=new Set;return{results:t.map(d=>this._findInRange(e,i,d.range,n,(l,u)=>{const g=`${l}-${u}`;return o.has(g)?!0:(o.add(g),!1)}).results).flat().sort((d,l)=>s(d.range.range,l.range.range)?-1:1)}}_findInWorksheet(e,t,i){const n=e.getRowCount(),r=e.getColumnCount(),s={startRow:0,startColumn:0,endRow:n-1,endColumn:r-1};return this._findInRange(e,t,s,i)}_disposeHighlights(){var e;this._highlightShapes.forEach(t=>{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.getCurrentTheme().gold400,o=new a.ColorKit(s).toRgb(),c=this._workbook.getActiveSheet();if(!c)return;const d=c.getSheetId(),l=r.filter(g=>g.range.subUnitId===d).map((g,v)=>{const{startColumn:I,startRow:b,endColumn:y,endRow:w}=g.range.range,W=M.getCoordByCell(b,I,n,e),ae=M.getCoordByCell(w,y,n,e),{startX:j,startY:$}=W,{endX:le,endY:de}=ae,L=!c.getRowRawVisible(b),V=!c.getColVisible(I),ue=L||V,ge=V?2:le-j,_e=L?2:de-$,fe={left:j,top:$,color:o,width:ge,height:_e,evented:!1,inHiddenRange:ue,zIndex:te};return new K(`find-highlight-${v}`,fe)});n.addObjects(l),this._highlightShapes=l,n.makeDirty()}_updateCurrentHighlightShape(e){var t;if((t=this._currentHighlightShape)==null||t.setShapeProps({activated:!1}),this._currentHighlightShape=null,e!==void 0){const i=this._highlightShapes[e];if(!i)return;this._currentHighlightShape=i,i.setShapeProps({activated:!0})}}_getSheetObject(){return M.getSheetObject(this._univerInstanceService,this._renderManagerService)}_focusMatch(e){var i;const t=e.range.subUnitId;t!==((i=this._workbook.getActiveSheet())==null?void 0:i.getSheetId())&&this._commandService.executeCommand(R.SetWorksheetActivateCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:t},{fromFindReplace:!0}),this._commandService.executeCommand(M.ScrollToCellCommand.id,{range:e.range.range},{fromFindReplace:!0})}_tryRestoreLastMatchesPosition(e,t){if(!e)return 0;const{subUnitId:i}=e.range,{startColumn:n,startRow:r}=e.range.range,s=t.findIndex(o=>{if(i!==o.range.subUnitId)return!1;const{startColumn:c,startRow:d}=o.range.range;return c===n&&d===r});return s>-1?s+1:0}moveToNextMatch(e){var o,c,d,l,u;if(!this._matches.length)return null;const t=(o=e==null?void 0:e.loop)!=null?o:!1,i=(c=e==null?void 0:e.stayIfOnMatch)!=null?c:!1,n=(d=e==null?void 0:e.noFocus)!=null?d:!1,r=(l=e==null?void 0:e.ignoreSelection)!=null?l:!1,s=this._findNextMatch(t,i,r);if(s){const[g,v]=s;return this._matchesPosition=v+1,this._query.findScope===f.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(g.range.subUnitId).findIndex(I=>I===g):this._activeHighlightIndex=v,n||this._focusMatch(g),((u=this._workbook.getActiveSheet())==null?void 0:u.getSheetId())===g.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),g}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}moveToPreviousMatch(e){var o,c,d,l,u;if(!this._matches.length)return null;const t=(o=e==null?void 0:e.loop)!=null?o:!1,i=(c=e==null?void 0:e.stayIfOnMatch)!=null?c:!1,n=(d=e==null?void 0:e.noFocus)!=null?d:!1,r=(l=e==null?void 0:e.ignoreSelection)!=null?l:!1,s=this._findPreviousMatch(t,i,r);if(s){const[g,v]=s;return this._matchesPosition=v+1,this._query.findScope===f.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(g.range.subUnitId).findIndex(I=>I===g):this._activeHighlightIndex=v,n||this._focusMatch(g),((u=this._workbook.getActiveSheet())==null?void 0:u.getSheetId())===g.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),g}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}_findPreviousMatch(e=!1,t=!1,i=!1){var o;if(this.currentMatch){const c=this._matches.findIndex(g=>g===this.currentMatch);if(t)return[this.currentMatch,c];const d=c-1;if(!e&&d<0)return null;const l=this._matches.length,u=(d+l)%l;return[this._matches[u],u]}const n=this._workbookSelections.getCurrentLastSelection();if(i||!n){const c=this._matches.length-1;return[this._matches[c],c]}if(this._query.findScope!==f.FindScope.UNIT)return this._findPreviousMatchByRange(this._matches,n.range);const r=(o=this._workbook.getActiveSheet())==null?void 0:o.getSheetId();if(!r)return null;const s=this._findPreviousWorksheetThatHasAMatch(r,e);return s?this._findPreviousMatchByRange(this._matchesByWorksheet.get(s),n.range):null}_findNextMatch(e=!1,t=!1,i=!1){var o;if(this.currentMatch){const c=this._matches.findIndex(g=>g===this.currentMatch);if(t)return[this.currentMatch,c];const d=c+1,l=this._matches.length;if(!e&&d>=l)return null;const u=d%l;return[this._matches[u],u]}const n=this._workbookSelections.getCurrentLastSelection();if(i||!n)return[this._matches[0],0];if(this._query.findScope!==f.FindScope.UNIT)return this._findNextMatchByRange(this._matches,n.range,t);const r=(o=this._workbook.getActiveSheet())==null?void 0:o.getSheetId();if(!r)return null;const s=this._findNextWorksheetThatHasAMatch(r,e);return s?this._findNextMatchByRange(this._matchesByWorksheet.get(s),n.range):null}_findPreviousWorksheetThatHasAMatch(e,t=!1){const i=this._workbook.getSheetOrders(),n=i.findIndex(o=>o===e),s=(t?a.rotate(i,n+1):i.slice(0,n+1)).findLast(o=>this._matchesByWorksheet.has(o));return s!=null?s:null}_findNextWorksheetThatHasAMatch(e,t=!1){const i=this._workbook.getSheetOrders(),n=i.findIndex(o=>o===e),s=(t?a.rotate(i,n):i.slice(n)).find(o=>this._matchesByWorksheet.has(o));return s!=null?s:null}_findNextMatchByRange(e,t,i=!1){const n=this._query.findDirection===f.FindDirection.ROW;let r=e.findIndex(o=>{const c=o.range.range;if(!(n?H(t,c):O(t,c)))return!1;const l=T(t,c);return i?l:!l});r===-1&&(r=e.length-1);const s=e[r];return[s,this._matches.findIndex(o=>o===s)]}_findPreviousMatchByRange(e,t,i=!1){const n=this._query.findDirection===f.FindDirection.ROW;let r=this._matches.findLastIndex(o=>{const c=o.range.range;if(!(n?Q(t,c):X(t,c)))return!1;const l=T(t,c);return i?l:!l});r===-1&&(r=0);const s=e[r];return[s,this._matches.findIndex(o=>o===s)]}async replace(e){if(this._matchesCount===0||!this.currentMatch||!this._query||!this.currentMatch.replaceable)return!1;const t=this.currentMatch.range,i=this._workbook.getSheetBySheetId(this.currentMatch.range.subUnitId),n=this._getReplacedCellData(this.currentMatch,i,this._query.findBy===f.FindBy.FORMULA,this._query.findString,e,this._query.caseSensitive?"g":"ig"),r={unitId:this.currentMatch.unitId,subUnitId:t.subUnitId,value:{[t.range.startRow]:{[t.range.startColumn]:n}}};return this._commandService.executeCommand(R.SetRangeValuesCommand.id,r)}async replaceAll(e){if(this._matchesCount===0||!this._query)return{success:0,failure:0};const t=this._workbook.getUnitId(),{findString:i,caseSensitive:n,findBy:r}=this._query,s=r===f.FindBy.FORMULA,o=n?"g":"ig",c=[];return a.groupBy(this._matches.filter(l=>l.replaceable),l=>l.range.subUnitId).forEach((l,u)=>{const g=new a.ObjectMatrix,v=this._workbook.getSheetBySheetId(u);l.forEach(I=>{const{startColumn:b,startRow:y}=I.range.range,w=this._getReplacedCellData(I,v,s,i,e,o);w&&g.setValue(y,b,w)}),c.push({count:l.length,subUnitId:u,value:g.getMatrix()})}),c?this._commandService.executeCommand(F.id,{unitId:t,replacements:c}):{success:0,failure:0}}_getReplacedCellData(e,t,i,n,r,s){var v;const o=e.range.range,{startRow:c,startColumn:d}=o,l=t.getCellRaw(c,d);if(e.isFormula)return i?{f:l.f.replace(new RegExp(E(n),s),r),v:null}:null;if(!!((v=l.p)!=null&&v.body)){const I=a.Tools.deepClone(l.p);return a.replaceInDocumentBody(I.body,n,r,this._query.caseSensitive),{p:I}}return{v:l.v.toString().replace(new RegExp(E(n),s),r)}}};P=U([p(2,a.IUniverInstanceService),p(3,k.IRenderManagerService),p(4,a.ICommandService),p(5,a.IContextService),p(6,a.Inject(a.ThemeService)),p(7,a.Inject(R.SheetsSelectionsService))],P);function E(h){return h.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}let x=class extends a.Disposable{constructor(e,t,i){super();m(this,"_findModelsByUnitId",new Map);this._univerInstanceService=e,this._renderManagerService=t,this._injector=i}async find(e){this._terminate();const t=this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET),i=this._preprocessQuery(e);return t.map(r=>{const s=this._renderManagerService.getRenderById(r.getUnitId()).with(M.SheetSkeletonManagerService),o=this._injector.createInstance(P,r,s);return this._findModelsByUnitId.set(r.getUnitId(),o),o.start(i),o})}terminate(){this._terminate()}_terminate(){this._findModelsByUnitId.forEach(e=>e.dispose()),this._findModelsByUnitId.clear()}_preprocessQuery(e){let t=e.caseSensitive?e.findString:e.findString.toLowerCase();return t=t.trim(),{...e,findString:t}}};x=U([p(0,a.IUniverInstanceService),p(1,k.IRenderManagerService),p(2,a.Inject(a.Injector))],x);const S={hit:!1,replaceable:!1,isFormula:!1,rawData:null};function ie(h,e,t,i,n){const{findBy:r}=i,s=r===f.FindBy.FORMULA,o=h.getCellRaw(e,t);return S.rawData=o,!(o!=null&&o.f)?(S.isFormula=!1,B(n,i)?o?(S.hit=!0,S.replaceable=!0):(S.hit=!0,S.replaceable=!1):(S.hit=!1,S.replaceable=!1),S):(S.isFormula=!0,s?B({v:o.f},i)?(S.hit=!0,S.replaceable=!0,S):(S.hit=!1,S.replaceable=!1,S):(S.replaceable=!1,B(n,i)?S.hit=!0:S.hit=!1,S))}function B(h,e){let t=ne(h);return t?e.matchesTheWholeCell?(t=se(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 ne(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 se(h){return h.replace(/^ +/g,"").replace(/ +$/g,"")}var A=Object.defineProperty,re=Object.getOwnPropertyDescriptor,oe=(h,e,t)=>e in h?A(h,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):h[e]=t,he=(h,e,t,i)=>{for(var n=i>1?void 0:i?re(e,t):e,r=h.length-1,s;r>=0;r--)(s=h[r])&&(n=(i?s(e,t,n):s(n))||n);return i&&n&&A(e,t,n),n},D=(h,e)=>(t,i)=>e(t,i,h),N=(h,e,t)=>oe(h,typeof e!="symbol"?e+"":e,t);const ce="SHEET_FIND_REPLACE_PLUGIN";_.UniverSheetsFindReplacePlugin=class extends a.Plugin{constructor(e=Y,t,i){super(),this._config=e,this._injector=t,this._configService=i;const{...n}=this._config;this._configService.setConfig(G,n)}onStarting(){[[_.SheetsFindReplaceController]].forEach(e=>this._injector.add(e))}onSteady(){this._injector.get(_.SheetsFindReplaceController)}},N(_.UniverSheetsFindReplacePlugin,"pluginName",ce),N(_.UniverSheetsFindReplacePlugin,"type",a.UniverInstanceType.UNIVER_SHEET),_.UniverSheetsFindReplacePlugin=he([a.DependentOn(R.UniverSheetsPlugin,R.UniverSheetsPlugin,f.UniverFindReplacePlugin),D(1,a.Inject(a.Injector)),D(2,a.IConfigService)],_.UniverSheetsFindReplacePlugin),_.SheetReplaceCommand=F,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(e,l){typeof exports=="object"&&typeof module<"u"?module.exports=l():typeof define=="function"&&define.amd?define(l):(e=typeof globalThis<"u"?globalThis:e||self,e.UniverSheetsFindReplaceEnUS=l())})(this,function(){"use strict";return{"sheet-find-replace":{replace:{"partial-failure":"Failed to replace some cells",failure:"Failed to replace all cells"}}}});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(e,i){typeof exports=="object"&&typeof module<"u"?module.exports=i():typeof define=="function"&&define.amd?define(i):(e=typeof globalThis<"u"?globalThis:e||self,e.UniverSheetsFindReplaceFaIR=i())})(this,function(){"use strict";return{"sheet-find-replace":{replace:{"partial-failure":"جایگزینی برخی سلولها ناموفق بود",failure:"جایگزینی همه سلولها ناموفق بود"}}}});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(e,i){typeof exports=="object"&&typeof module<"u"?module.exports=i():typeof define=="function"&&define.amd?define(i):(e=typeof globalThis<"u"?globalThis:e||self,e.UniverSheetsFindReplaceRuRU=i())})(this,function(){"use strict";return{"sheet-find-replace":{replace:{"partial-failure":"Не удалось заменить некоторые ячейки",failure:"Не удалось заменить все ячейки"}}}});
|
|
@@ -0,0 +1 @@
|
|
|
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(){"use strict";return{"sheet-find-replace":{replace:{"partial-failure":"Thay thế một phần ô thất bại",failure:"Thay thế thất bại"}}}});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(e,i){typeof exports=="object"&&typeof module<"u"?module.exports=i():typeof define=="function"&&define.amd?define(i):(e=typeof globalThis<"u"?globalThis:e||self,e.UniverSheetsFindReplaceZhCN=i())})(this,function(){"use strict";return{"sheet-find-replace":{replace:{"partial-failure":"部分单元格替换失败",failure:"替换失败"}}}});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(e,i){typeof exports=="object"&&typeof module<"u"?module.exports=i():typeof define=="function"&&define.amd?define(i):(e=typeof globalThis<"u"?globalThis:e||self,e.UniverSheetsFindReplaceZhTW=i())})(this,function(){"use strict";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.5.0-beta.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "UniverSheet find replace plugin",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -31,11 +31,14 @@
|
|
|
31
31
|
"require": "./lib/cjs/*",
|
|
32
32
|
"types": "./lib/types/index.d.ts"
|
|
33
33
|
},
|
|
34
|
-
"./
|
|
35
|
-
|
|
34
|
+
"./locale/*": {
|
|
35
|
+
"import": "./lib/es/locale/*.js",
|
|
36
|
+
"require": "./lib/cjs/locale/*.js",
|
|
37
|
+
"types": "./lib/types/locale/*.d.ts"
|
|
38
|
+
},
|
|
39
|
+
"./lib/*": "./lib/*"
|
|
36
40
|
},
|
|
37
|
-
"main": "./lib/
|
|
38
|
-
"module": "./lib/es/index.js",
|
|
41
|
+
"main": "./lib/es/index.js",
|
|
39
42
|
"types": "./lib/types/index.d.ts",
|
|
40
43
|
"publishConfig": {
|
|
41
44
|
"access": "public"
|
|
@@ -50,22 +53,22 @@
|
|
|
50
53
|
"rxjs": ">=7.0.0"
|
|
51
54
|
},
|
|
52
55
|
"dependencies": {
|
|
53
|
-
"@univerjs/protocol": "0.1.39-alpha.
|
|
54
|
-
"@univerjs/core": "0.
|
|
55
|
-
"@univerjs/engine-formula": "0.
|
|
56
|
-
"@univerjs/
|
|
57
|
-
"@univerjs/
|
|
58
|
-
"@univerjs/sheets
|
|
59
|
-
"@univerjs/sheets": "0.
|
|
56
|
+
"@univerjs/protocol": "0.1.39-alpha.45",
|
|
57
|
+
"@univerjs/core": "0.5.0-beta.0",
|
|
58
|
+
"@univerjs/engine-formula": "0.5.0-beta.0",
|
|
59
|
+
"@univerjs/find-replace": "0.5.0-beta.0",
|
|
60
|
+
"@univerjs/engine-render": "0.5.0-beta.0",
|
|
61
|
+
"@univerjs/sheets": "0.5.0-beta.0",
|
|
62
|
+
"@univerjs/sheets-ui": "0.5.0-beta.0"
|
|
60
63
|
},
|
|
61
64
|
"devDependencies": {
|
|
62
65
|
"rxjs": "^7.8.1",
|
|
63
66
|
"typescript": "^5.6.3",
|
|
64
|
-
"vite": "^5.4.
|
|
65
|
-
"vitest": "^2.1.
|
|
66
|
-
"@univerjs-infra/shared": "0.
|
|
67
|
+
"vite": "^5.4.11",
|
|
68
|
+
"vitest": "^2.1.5",
|
|
69
|
+
"@univerjs-infra/shared": "0.5.0-beta.0"
|
|
67
70
|
},
|
|
68
|
-
"
|
|
71
|
+
"space": {
|
|
69
72
|
".": {
|
|
70
73
|
"import": "./lib/es/index.js",
|
|
71
74
|
"require": "./lib/cjs/index.js",
|
|
@@ -76,14 +79,19 @@
|
|
|
76
79
|
"require": "./lib/cjs/*",
|
|
77
80
|
"types": "./lib/types/index.d.ts"
|
|
78
81
|
},
|
|
79
|
-
"./
|
|
80
|
-
|
|
82
|
+
"./locale/*": {
|
|
83
|
+
"import": "./lib/es/locale/*.js",
|
|
84
|
+
"require": "./lib/cjs/locale/*.js",
|
|
85
|
+
"types": "./lib/types/locale/*.d.ts"
|
|
86
|
+
},
|
|
87
|
+
"./lib/*": "./lib/*"
|
|
81
88
|
},
|
|
82
89
|
"scripts": {
|
|
83
90
|
"test": "vitest run",
|
|
84
91
|
"test:watch": "vitest",
|
|
85
92
|
"coverage": "vitest run --coverage",
|
|
86
93
|
"lint:types": "tsc --noEmit",
|
|
87
|
-
"build": "
|
|
88
|
-
}
|
|
94
|
+
"build": "univer-cli build"
|
|
95
|
+
},
|
|
96
|
+
"module": "./lib/es/index.js"
|
|
89
97
|
}
|
package/lib/locale/en-US.json
DELETED