@univerjs/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 CHANGED
@@ -1,4 +1,4 @@
1
- "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);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const core=require("@univerjs/core"),ui=require("@univerjs/ui"),rxjs=require("rxjs"),design=require("@univerjs/design"),engineRender=require("@univerjs/engine-render"),require$$0=require("react"),PLUGIN_CONFIG_KEY="find-replace.config",defaultPluginConfig={};var __assign=function(){return __assign=Object.assign||function(t){for(var s,i=1,n2=arguments.length;i<n2;i++){s=arguments[i];for(var p2 in s)Object.prototype.hasOwnProperty.call(s,p2)&&(t[p2]=s[p2])}return t},__assign.apply(this,arguments)},__rest=function(s,e){var t={};for(var p2 in s)Object.prototype.hasOwnProperty.call(s,p2)&&e.indexOf(p2)<0&&(t[p2]=s[p2]);if(s!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,p2=Object.getOwnPropertySymbols(s);i<p2.length;i++)e.indexOf(p2[i])<0&&Object.prototype.propertyIsEnumerable.call(s,p2[i])&&(t[p2[i]]=s[p2[i]]);return t},IconBase=require$$0.forwardRef(function(props,ref){var icon=props.icon,id=props.id,className=props.className,extend=props.extend,restProps=__rest(props,["icon","id","className","extend"]),cls="univerjs-icon univerjs-icon-".concat(id," ").concat(className||"").trim(),idSuffix=require$$0.useRef("_".concat(generateShortUuid()));return render(icon,"".concat(id),{defIds:icon.defIds,idSuffix:idSuffix.current},__assign({ref,className:cls},restProps),extend)});function render(node,id,runtimeProps,rootProps,extend){return require$$0.createElement(node.tag,__assign(__assign({key:id},replaceRuntimeIdsAndExtInAttrs(node,runtimeProps,extend)),rootProps),(replaceRuntimeIdsInDefs(node,runtimeProps).children||[]).map(function(child,index){return render(child,"".concat(id,"-").concat(node.tag,"-").concat(index),runtimeProps,void 0,extend)}))}__name(render,"render");function replaceRuntimeIdsAndExtInAttrs(node,runtimeProps,extend){var attrs=__assign({},node.attrs);extend!=null&&extend.colorChannel1&&attrs.fill==="colorChannel1"&&(attrs.fill=extend.colorChannel1);var defIds=runtimeProps.defIds;return!defIds||defIds.length===0||(node.tag==="use"&&attrs["xlink:href"]&&(attrs["xlink:href"]=attrs["xlink:href"]+runtimeProps.idSuffix),Object.entries(attrs).forEach(function(_a5){var key=_a5[0],value=_a5[1];typeof value=="string"&&(attrs[key]=value.replace(/url\(#(.*)\)/,"url(#$1".concat(runtimeProps.idSuffix,")")))})),attrs}__name(replaceRuntimeIdsAndExtInAttrs,"replaceRuntimeIdsAndExtInAttrs");function replaceRuntimeIdsInDefs(node,runtimeProps){var _a5,defIds=runtimeProps.defIds;return!defIds||defIds.length===0?node:node.tag==="defs"&&(!((_a5=node.children)===null||_a5===void 0)&&_a5.length)?__assign(__assign({},node),{children:node.children.map(function(child){return typeof child.attrs.id=="string"&&defIds&&defIds.indexOf(child.attrs.id)>-1?__assign(__assign({},child),{attrs:__assign(__assign({},child.attrs),{id:child.attrs.id+runtimeProps.idSuffix})}):child})}):node}__name(replaceRuntimeIdsInDefs,"replaceRuntimeIdsInDefs");function generateShortUuid(){return Math.random().toString(36).substring(2,8)}__name(generateShortUuid,"generateShortUuid");IconBase.displayName="UniverIcon";var element={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_217_40",style:{maskType:"alpha"},width:17,height:17,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#D9D9D9",d:"M0.9 0.09H16.9V16.09H0.9z"}}]},{tag:"g",attrs:{mask:"url(#mask0_217_40)"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.39551 7.37266C2.39551 4.18105 4.98281 1.59375 8.17441 1.59375C11.366 1.59375 13.9533 4.18105 13.9533 7.37266C13.9533 8.72342 13.4898 9.96603 12.7133 10.95L15.1964 13.4331C15.4619 13.6986 15.4619 14.1291 15.1964 14.3946C14.9309 14.6601 14.5004 14.6601 14.2349 14.3946L11.7518 11.9115C10.7678 12.6881 9.52525 13.1516 8.17441 13.1516C4.98281 13.1516 2.39551 10.5642 2.39551 7.37266ZM8.17441 2.95349C5.73378 2.95349 3.75525 4.93202 3.75525 7.37266C3.75525 9.81333 5.73378 11.7918 8.17441 11.7918C10.6151 11.7918 12.5936 9.81333 12.5936 7.37266C12.5936 4.93202 10.6151 2.95349 8.17441 2.95349Z",fillRule:"evenodd",clipRule:"evenodd"}}]}]},SearchSingle16=require$$0.forwardRef(function(props,ref){return require$$0.createElement(IconBase,Object.assign({},props,{id:"search-single-16",ref,icon:element}))});SearchSingle16.displayName="SearchSingle16";const FIND_REPLACE_INPUT_FOCUS="FIND_REPLACE_INPUT_FOCUS",FIND_REPLACE_DIALOG_FOCUS="FIND_REPLACE_DIALOG_FOCUS",FIND_REPLACE_REPLACE_REVEALED="FIND_REPLACE_REPLACE_REVEALED";var __defProp$2=Object.defineProperty,__getOwnPropDesc$2=Object.getOwnPropertyDescriptor,__decorateClass$2=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$2(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$2(target,key,result),result},"__decorateClass$2"),__decorateParam$2=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$2");const _FindModel=class _FindModel extends core.Disposable{};__name(_FindModel,"FindModel");let FindModel=_FindModel;const IFindReplaceService=core.createIdentifier("find-replace.service");function shouldStateUpdateTriggerResearch(statusUpdate){return typeof statusUpdate.findString<"u"||typeof statusUpdate.inputtingFindString<"u"||typeof statusUpdate.findDirection<"u"||typeof statusUpdate.matchesTheWholeCell<"u"||typeof statusUpdate.caseSensitive<"u"||typeof statusUpdate.findScope<"u"||typeof statusUpdate.findBy<"u"}__name(shouldStateUpdateTriggerResearch,"shouldStateUpdateTriggerResearch");var _a;let FindReplaceModel=(_a=class extends core.Disposable{constructor(_state,_providers,_univerInstanceService){super();__publicField(this,"currentMatch$",new rxjs.BehaviorSubject(null));__publicField(this,"replaceables$",new rxjs.BehaviorSubject([]));__publicField(this,"_findModels",[]);__publicField(this,"_matchingModel",null);__publicField(this,"_matches",[]);__publicField(this,"_currentSearchingDisposables",null);this._state=_state,this._providers=_providers,this._univerInstanceService=_univerInstanceService,this.disposeWithMe(this._state.stateUpdates$.pipe(rxjs.throttleTime(200,void 0,{leading:!0,trailing:!0})).subscribe(async stateUpdate=>{const state=this._state.state;shouldStateUpdateTriggerResearch(stateUpdate)&&(state.findString!==""&&!state.replaceRevealed?(await this._startSearching(),this._state.changeState({findCompleted:!0})):stateUpdate.replaceRevealed!==!0&&this._stopSearching())}))}get searched(){return this._findModels.length>0}dispose(){super.dispose(),this._stopSearching(),this.currentMatch$.complete(),this.replaceables$.complete(),this._state.changeState({...createInitFindReplaceState(),revealed:!1})}async start(){if(!this._state.findString)return{results:[]};const complete=await this._startSearching();return this._state.changeState({findCompleted:!0}),complete}async _startSearching(){if(!this._state.findString)return{results:[]};const providers=Array.from(this._providers),findModels=this._findModels=(await Promise.all(providers.map(provider=>provider.find({findString:this._state.findString,findDirection:this._state.findDirection,findScope:this._state.findScope,findBy:this._state.findBy,replaceRevealed:this._state.replaceRevealed,caseSensitive:this._state.caseSensitive,matchesTheWholeCell:this._state.matchesTheWholeCell})))).flat();this._subscribeToModelsChanges(findModels);const newMatches=this._matches=findModels.map(c=>c.getMatches()).flat();return this.replaceables$.next(newMatches.filter(m2=>m2.replaceable)),newMatches.length?(this._moveToInitialMatch(findModels),this._state.changeState({matchesCount:newMatches.length}),{results:newMatches}):(this._state.changeState({matchesCount:0,matchesPosition:0}),{results:[]})}_stopSearching(){var _a5;this._providers.forEach(provider=>provider.terminate()),this._findModels=[],this._matches=[],this._matchingModel=null,(_a5=this._currentSearchingDisposables)==null||_a5.dispose(),this._currentSearchingDisposables=null,this.currentMatch$.next(null),this.replaceables$.next([]),this._state.changeState({findCompleted:!1,matchesCount:0,matchesPosition:0})}_subscribeToModelsChanges(models){const disposables=this._currentSearchingDisposables=new core.DisposableCollection,matchesUpdateSubscription=rxjs.combineLatest(models.map(model=>model.matchesUpdate$)).pipe(rxjs.debounceTime(220)).subscribe(([...allMatches])=>{const newMatches=this._matches=allMatches.flat();newMatches.length?(this._moveToInitialMatch(this._findModels,!0),this._state.changeState({matchesCount:newMatches.length}),this.replaceables$.next(newMatches.filter(m2=>m2.replaceable))):(this._state.changeState({matchesCount:0,matchesPosition:0}),this.replaceables$.next([]))});models.forEach(model=>disposables.add(core.toDisposable(model.activelyChangingMatch$.subscribe(match=>{const index=this._matches.findIndex(m2=>m2===match);this._state.changeState({matchesPosition:index+1})})))),disposables.add(core.toDisposable(matchesUpdateSubscription))}async replace(){return this._matchingModel?this._matchingModel.replace(this._state.replaceString):!1}async replaceAll(){const result=await Promise.all(this._findModels.map(m2=>m2.replaceAll(this._state.replaceString))).then(results=>results.reduce((acc,cur)=>(acc.success+=cur.success,acc.failure+=cur.failure,acc),{success:0,failure:0}));return result.failure===0&&this._stopSearching(),result}getCurrentMatch(){return this._state.matchesPosition>0?this._matches[this._state.matchesPosition-1]:null}_markMatch(match){const index=this._matches.findIndex(value=>value===match);this.currentMatch$.next(match),this._state.changeState({matchesPosition:index+1})}moveToNextMatch(){if(!this._matchingModel)return;const loopInCurrentUnit=this._findModels.length===1,nextMatch=this._matchingModel.moveToNextMatch({loop:loopInCurrentUnit});if(nextMatch)this._markMatch(nextMatch);else{const currentModelIndex=this._findModels.findIndex(m2=>m2===this._matchingModel);this._moveToNextUnitMatch(currentModelIndex)}}_moveToNextUnitMatch(startingIndex){const l2=this._findModels.length;for(let i=(startingIndex+1)%l2;i!==startingIndex;){const nextPositionModel=this._findModels[i],nextMatch=nextPositionModel.moveToNextMatch({ignoreSelection:!0});if(nextMatch){this._matchingModel=nextPositionModel,this._markMatch(nextMatch);return}i=(i+1)%l2}if(this._matchingModel){const nextMatch=this._matchingModel.moveToNextMatch({ignoreSelection:!0});nextMatch&&this._markMatch(nextMatch)}}moveToPreviousMatch(){if(!this._matchingModel)return;const loopInCurrentUnit=this._findModels.length===1,nextMatch=this._matchingModel.moveToPreviousMatch({loop:loopInCurrentUnit});if(nextMatch){const index=this._matches.findIndex(value=>value===nextMatch);this.currentMatch$.next(nextMatch),this._state.changeState({matchesPosition:index+1})}else{const l2=this._findModels.length,currentModelIndex=this._findModels.findIndex(m2=>m2===this._matchingModel);for(let i=(currentModelIndex-1+l2)%l2;i!==currentModelIndex;){const nextPositionModel=this._findModels[i],nextMatch3=nextPositionModel.moveToPreviousMatch({ignoreSelection:!0});if(nextMatch3){this._matchingModel=nextPositionModel,this._markMatch(nextMatch3);return}i=(i-1)%l2}const nextMatch2=this._matchingModel.moveToPreviousMatch({ignoreSelection:!0});nextMatch2&&this._markMatch(nextMatch2)}}_moveToInitialMatch(findModels,noFocus=!1){var _a5;const focusedUnitId=(_a5=this._univerInstanceService.getFocusedUnit())==null?void 0:_a5.getUnitId();if(!focusedUnitId)return-1;const i=findModels.findIndex(model=>model.unitId===focusedUnitId);if(i!==-1){this._matchingModel=findModels[i];const nextMatch=this._matchingModel.moveToNextMatch({stayIfOnMatch:!0,noFocus});if(nextMatch)return this._markMatch(nextMatch),i}return this._moveToNextUnitMatch(i),0}},__name(_a,"FindReplaceModel"),_a);FindReplaceModel=__decorateClass$2([__decorateParam$2(2,core.IUniverInstanceService)],FindReplaceModel);var FindDirection=(FindDirection2=>(FindDirection2.ROW="row",FindDirection2.COLUMN="column",FindDirection2))(FindDirection||{}),FindBy=(FindBy2=>(FindBy2.VALUE="value",FindBy2.FORMULA="formula",FindBy2))(FindBy||{}),FindScope=(FindScope2=>(FindScope2.SUBUNIT="subunit",FindScope2.UNIT="unit",FindScope2))(FindScope||{});function createInitFindReplaceState(){return{caseSensitive:!1,findBy:"value",findCompleted:!1,findDirection:"row",findScope:"subunit",findString:"",inputtingFindString:"",matchesCount:0,matchesPosition:0,matchesTheWholeCell:!1,replaceRevealed:!1,replaceString:"",revealed:!0}}__name(createInitFindReplaceState,"createInitFindReplaceState");const _FindReplaceState=class _FindReplaceState{constructor(){__publicField(this,"_stateUpdates$",new rxjs.Subject);__publicField(this,"stateUpdates$",this._stateUpdates$.asObservable());__publicField(this,"_state$",new rxjs.BehaviorSubject(createInitFindReplaceState()));__publicField(this,"state$",this._state$.asObservable());__publicField(this,"_findString","");__publicField(this,"_inputtingFindString","");__publicField(this,"_replaceString","");__publicField(this,"_revealed",!1);__publicField(this,"_replaceRevealed",!1);__publicField(this,"_matchesPosition",0);__publicField(this,"_matchesCount",0);__publicField(this,"_caseSensitive",!0);__publicField(this,"_matchesTheWholeCell",!1);__publicField(this,"_findDirection","row");__publicField(this,"_findScope","subunit");__publicField(this,"_findBy","value");__publicField(this,"_findCompleted",!1)}get state(){return this._state$.getValue()}get inputtingFindString(){return this._inputtingFindString}get findString(){return this._findString}get revealed(){return this._revealed}get replaceRevealed(){return this._replaceRevealed}get matchesPosition(){return this._matchesPosition}get matchesCount(){return this._matchesCount}get replaceString(){return this._replaceString}get caseSensitive(){return this._caseSensitive}get matchesTheWholeCell(){return this._matchesTheWholeCell}get findDirection(){return this._findDirection}get findScope(){return this._findScope}get findBy(){return this._findBy}get findCompleted(){return this._findCompleted}changeState(changes){let changed=!1;const changedState={};typeof changes.findString<"u"&&changes.findString!==this._findString&&(this._findString=changes.findString,changedState.findString=this._findString,changed=!0),typeof changes.revealed<"u"&&changes.revealed!==this._revealed&&(this._revealed=changes.revealed,changedState.revealed=changes.revealed,changed=!0),typeof changes.replaceRevealed<"u"&&changes.replaceRevealed!==this._replaceRevealed&&(this._replaceRevealed=changes.replaceRevealed,changedState.replaceRevealed=changes.replaceRevealed,changed=!0),typeof changes.replaceString<"u"&&changes.replaceString!==this._replaceString&&(this._replaceString=changes.replaceString,changedState.replaceString=changes.replaceString,changed=!0),typeof changes.matchesCount<"u"&&changes.matchesCount!==this._matchesCount&&(this._matchesCount=changes.matchesCount,changedState.matchesCount=changes.matchesCount,changed=!0),typeof changes.matchesPosition<"u"&&changes.matchesPosition!==this._matchesPosition&&(this._matchesPosition=changes.matchesPosition,changedState.matchesPosition=changes.matchesPosition,changed=!0),typeof changes.findBy<"u"&&changes.findBy!==this._findBy&&(this._findBy=changes.findBy,changedState.findBy=changes.findBy,changed=!0),typeof changes.findScope<"u"&&changes.findScope!==this._findScope&&(this._findScope=changes.findScope,changedState.findScope=changes.findScope,changed=!0),typeof changes.findDirection<"u"&&changes.findDirection!==this._findDirection&&(this._findDirection=changes.findDirection,changedState.findDirection=changes.findDirection,changed=!0),typeof changes.caseSensitive<"u"&&changes.caseSensitive!==this._caseSensitive&&(this._caseSensitive=changes.caseSensitive,changedState.caseSensitive=changes.caseSensitive,changed=!0),typeof changes.matchesTheWholeCell<"u"&&changes.matchesTheWholeCell!==this._matchesTheWholeCell&&(this._matchesTheWholeCell=changes.matchesTheWholeCell,changedState.matchesTheWholeCell=changes.matchesTheWholeCell,changed=!0),typeof changes.inputtingFindString<"u"&&changes.inputtingFindString!==this._inputtingFindString&&(this._inputtingFindString=changes.inputtingFindString,changedState.inputtingFindString=changes.inputtingFindString,changed=!0),typeof changes.findCompleted<"u"&&changes.findCompleted!==this._findCompleted&&(this._findCompleted=changes.findCompleted,changedState.findCompleted=changes.findCompleted,changed=!0),changed&&(this._state$.next({caseSensitive:this._caseSensitive,findBy:this._findBy,findCompleted:this._findCompleted,findDirection:this._findDirection,findScope:this._findScope,findString:this._findString,inputtingFindString:this._inputtingFindString,matchesCount:this._matchesCount,matchesPosition:this._matchesPosition,matchesTheWholeCell:this._matchesTheWholeCell,replaceRevealed:this._replaceRevealed,revealed:this._revealed}),this._stateUpdates$.next(changedState))}};__name(_FindReplaceState,"FindReplaceState");let FindReplaceState=_FindReplaceState;var _a2;let FindReplaceService=(_a2=class extends core.Disposable{constructor(_injector,_contextService){super();__publicField(this,"_providers",new Set);__publicField(this,"_state",new FindReplaceState);__publicField(this,"_model");__publicField(this,"_currentMatch$",new rxjs.BehaviorSubject(null));__publicField(this,"currentMatch$",this._currentMatch$.asObservable());__publicField(this,"_replaceables$",new rxjs.BehaviorSubject([]));__publicField(this,"replaceables$",this._replaceables$.asObservable());__publicField(this,"_focusSignal$",new rxjs.Subject);__publicField(this,"focusSignal$",this._focusSignal$.asObservable());this._injector=_injector,this._contextService=_contextService}get stateUpdates$(){return this._state.stateUpdates$}get state$(){return this._state.state$}get revealed(){return this._state.revealed}get replaceRevealed(){return this._state.replaceRevealed}dispose(){super.dispose(),this._currentMatch$.next(null),this._currentMatch$.complete(),this._replaceables$.next([]),this._replaceables$.complete(),this._focusSignal$.complete()}getCurrentMatch(){var _a5;return(_a5=this._model)==null?void 0:_a5.getCurrentMatch()}getFindString(){return this._state.findString}changeFindString(findString){this._state.changeState({findString})}focusFindInput(){this._focusSignal$.next()}changeInputtingFindString(value){value?this._state.changeState({inputtingFindString:value}):this._state.changeState({inputtingFindString:"",findString:""})}changeReplaceString(replaceString){this._state.changeState({replaceString})}changeMatchesTheWholeCell(matchesTheWholeCell){this._state.changeState({matchesTheWholeCell})}changeCaseSensitive(caseSensitive){this._state.changeState({caseSensitive})}changeFindBy(findBy){this._state.changeState({findBy}),this._toggleDisplayRawFormula(findBy==="formula")}changeFindScope(scope){this._state.changeState({findScope:scope})}changeFindDirection(direction){this._state.changeState({findDirection:direction})}moveToNextMatch(){this._model&&(this._state.replaceRevealed&&!this._model.searched?(this._state.changeState({findString:this._state.inputtingFindString}),this._model.start()):this._model.moveToNextMatch(),this._focusSignal$.next())}moveToPreviousMatch(){this._model&&(this._state.replaceRevealed&&!this._model.searched?(this._state.changeState({findString:this._state.inputtingFindString}),this._model.start()):this._model.moveToPreviousMatch(),this._focusSignal$.next())}async replace(){return this._model?this._model.replace():!1}async replaceAll(){if(!this._model)throw new Error("[FindReplaceService] replaceAll: model is not initialized!");return this._model.replaceAll()}revealReplace(){this._state.changeState({replaceRevealed:!0,inputtingFindString:this._state.findString}),this._toggleRevealReplace(!0)}start(revealReplace=!1){if(this._providers.size===0)return!1;this._model=this._injector.createInstance(FindReplaceModel,this._state,this._providers),this._model.currentMatch$.subscribe(match=>this._currentMatch$.next(match)),this._model.replaceables$.subscribe(replaceables=>this._replaceables$.next(replaceables));const newState=createInitFindReplaceState();return revealReplace&&(newState.replaceRevealed=!0),this._state.changeState(newState),this._toggleRevealReplace(revealReplace),!0}find(){var _a5;(_a5=this._model)==null||_a5.start()}terminate(){var _a5;(_a5=this._model)==null||_a5.dispose(),this._model=null,this._toggleDisplayRawFormula(!1),this._toggleRevealReplace(!1)}registerFindReplaceProvider(provider){return this._providers.add(provider),core.toDisposable(()=>this._providers.delete(provider))}_toggleRevealReplace(revealReplace){this._contextService.setContextValue(FIND_REPLACE_REPLACE_REVEALED,revealReplace)}_toggleDisplayRawFormula(force){this._contextService.setContextValue(engineRender.RENDER_RAW_FORMULA_KEY,force)}},__name(_a2,"FindReplaceService"),_a2);FindReplaceService=__decorateClass$2([__decorateParam$2(0,core.Inject(core.Injector)),__decorateParam$2(1,core.IContextService)],FindReplaceService);const ReplaceCurrentMatchCommand={id:"ui.command.replace-current-match",type:core.CommandType.COMMAND,handler:__name(accessor=>accessor.get(IFindReplaceService).replace(),"handler")},CONFIRM_REPLACE_ALL_ID="CONFIRM_REPLACE_ALL",ReplaceAllMatchesCommand={id:"ui.command.replace-all-matches",type:core.CommandType.COMMAND,handler:__name(async accessor=>{const confirmService=accessor.get(ui.IConfirmService),localeService=accessor.get(core.LocaleService),messageService=accessor.get(ui.IMessageService);if(!await confirmService.confirm({id:CONFIRM_REPLACE_ALL_ID,title:{title:localeService.t("find-replace.replace.confirm.title")},cancelText:localeService.t("button.cancel"),confirmText:localeService.t("button.confirm")}))return!1;const result=await accessor.get(IFindReplaceService).replaceAll(),{success,failure}=result;return failure>0?(success===0?messageService.show({type:design.MessageType.Error,content:localeService.t("find-replace.replace.all-failure")}):messageService.show({type:design.MessageType.Warning,content:localeService.t("find-replace.replace.partial-success",`${success}`,`${failure}`)}),!1):(messageService.show({type:design.MessageType.Success,content:localeService.t("find-replace.replace.all-success",`${success}`)}),!0)},"handler")},OpenFindDialogOperation={id:"ui.operation.open-find-dialog",type:core.CommandType.OPERATION,handler:__name(accessor=>{const findReplaceService=accessor.get(IFindReplaceService);return findReplaceService.revealed?findReplaceService.focusFindInput():findReplaceService.start(),!0},"handler")},OpenReplaceDialogOperation={id:"ui.operation.open-replace-dialog",type:core.CommandType.OPERATION,handler:__name(accessor=>{const findReplaceService=accessor.get(IFindReplaceService);return findReplaceService.revealed?findReplaceService.replaceRevealed?findReplaceService.focusFindInput():findReplaceService.revealReplace():findReplaceService.start(!0),!0},"handler")},GoToNextMatchOperation={type:core.CommandType.OPERATION,id:"ui.operation.go-to-next-match",handler:__name(accessor=>(accessor.get(IFindReplaceService).moveToNextMatch(),!0),"handler")},GoToPreviousMatchOperation={type:core.CommandType.OPERATION,id:"ui.operation.go-to-previous-match",handler:__name(accessor=>(accessor.get(IFindReplaceService).moveToPreviousMatch(),!0),"handler")};var jsxRuntime={exports:{}},reactJsxRuntime_production_min={};/**
1
+ "use strict";var Oe=Object.defineProperty;var Te=(i,e,n)=>e in i?Oe(i,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[e]=n;var l=(i,e,n)=>Te(i,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),u=require("@univerjs/ui"),g=require("rxjs"),p=require("@univerjs/design"),Pe=require("@univerjs/engine-render"),c=require("react"),Ee="find-replace.config",Ne={};var S=function(){return S=Object.assign||function(i){for(var e,n=1,t=arguments.length;n<t;n++){e=arguments[n];for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&(i[s]=e[s])}return i},S.apply(this,arguments)},$e=function(i,e){var n={};for(var t in i)Object.prototype.hasOwnProperty.call(i,t)&&e.indexOf(t)<0&&(n[t]=i[t]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,t=Object.getOwnPropertySymbols(i);s<t.length;s++)e.indexOf(t[s])<0&&Object.prototype.propertyIsEnumerable.call(i,t[s])&&(n[t[s]]=i[t[s]]);return n},Y=c.forwardRef(function(i,e){var n=i.icon,t=i.id,s=i.className,r=i.extend,a=$e(i,["icon","id","className","extend"]),h="univerjs-icon univerjs-icon-".concat(t," ").concat(s||"").trim(),f=c.useRef("_".concat(Ae()));return Z(n,"".concat(t),{defIds:n.defIds,idSuffix:f.current},S({ref:e,className:h},a),r)});function Z(i,e,n,t,s){return c.createElement(i.tag,S(S({key:e},je(i,n,s)),t),(Le(i,n).children||[]).map(function(r,a){return Z(r,"".concat(e,"-").concat(i.tag,"-").concat(a),n,void 0,s)}))}function je(i,e,n){var t=S({},i.attrs);n!=null&&n.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=n.colorChannel1);var s=e.defIds;return!s||s.length===0||(i.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+e.idSuffix),Object.entries(t).forEach(function(r){var a=r[0],h=r[1];typeof h=="string"&&(t[a]=h.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),t}function Le(i,e){var n,t=e.defIds;return!t||t.length===0?i:i.tag==="defs"&&(!((n=i.children)===null||n===void 0)&&n.length)?S(S({},i),{children:i.children.map(function(s){return typeof s.attrs.id=="string"&&t&&t.indexOf(s.attrs.id)>-1?S(S({},s),{attrs:S(S({},s.attrs),{id:s.attrs.id+e.idSuffix})}):s})}):i}function Ae(){return Math.random().toString(36).substring(2,8)}Y.displayName="UniverIcon";var we={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_217_40",style:{maskType:"alpha"},width:17,height:17,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#D9D9D9",d:"M0.9 0.09H16.9V16.09H0.9z"}}]},{tag:"g",attrs:{mask:"url(#mask0_217_40)"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.39551 7.37266C2.39551 4.18105 4.98281 1.59375 8.17441 1.59375C11.366 1.59375 13.9533 4.18105 13.9533 7.37266C13.9533 8.72342 13.4898 9.96603 12.7133 10.95L15.1964 13.4331C15.4619 13.6986 15.4619 14.1291 15.1964 14.3946C14.9309 14.6601 14.5004 14.6601 14.2349 14.3946L11.7518 11.9115C10.7678 12.6881 9.52525 13.1516 8.17441 13.1516C4.98281 13.1516 2.39551 10.5642 2.39551 7.37266ZM8.17441 2.95349C5.73378 2.95349 3.75525 4.93202 3.75525 7.37266C3.75525 9.81333 5.73378 11.7918 8.17441 11.7918C10.6151 11.7918 12.5936 9.81333 12.5936 7.37266C12.5936 4.93202 10.6151 2.95349 8.17441 2.95349Z",fillRule:"evenodd",clipRule:"evenodd"}}]}]},J=c.forwardRef(function(i,e){return c.createElement(Y,Object.assign({},i,{id:"search-single-16",ref:e,icon:we}))});J.displayName="SearchSingle16";const Q="FIND_REPLACE_INPUT_FOCUS",X="FIND_REPLACE_DIALOG_FOCUS",ee="FIND_REPLACE_REPLACE_REVEALED";var Ue=Object.defineProperty,Be=Object.getOwnPropertyDescriptor,te=(i,e,n,t)=>{for(var s=t>1?void 0:t?Be(e,n):e,r=i.length-1,a;r>=0;r--)(a=i[r])&&(s=(t?a(e,n,s):a(s))||s);return t&&s&&Ue(e,n,s),s},A=(i,e)=>(n,t)=>e(n,t,i);class ke extends o.Disposable{}const C=o.createIdentifier("find-replace.service");function We(i){return typeof i.findString<"u"||typeof i.inputtingFindString<"u"||typeof i.findDirection<"u"||typeof i.matchesTheWholeCell<"u"||typeof i.caseSensitive<"u"||typeof i.findScope<"u"||typeof i.findBy<"u"}let w=class extends o.Disposable{constructor(e,n,t){super();l(this,"currentMatch$",new g.BehaviorSubject(null));l(this,"replaceables$",new g.BehaviorSubject([]));l(this,"_findModels",[]);l(this,"_matchingModel",null);l(this,"_matches",[]);l(this,"_currentSearchingDisposables",null);this._state=e,this._providers=n,this._univerInstanceService=t,this.disposeWithMe(this._state.stateUpdates$.pipe(g.throttleTime(200,void 0,{leading:!0,trailing:!0})).subscribe(async s=>{const r=this._state.state;We(s)&&(r.findString!==""&&!r.replaceRevealed?(await this._startSearching(),this._state.changeState({findCompleted:!0})):s.replaceRevealed!==!0&&this._stopSearching())}))}get searched(){return this._findModels.length>0}dispose(){super.dispose(),this._stopSearching(),this.currentMatch$.complete(),this.replaceables$.complete(),this._state.changeState({...B(),revealed:!1})}async start(){if(!this._state.findString)return{results:[]};const e=await this._startSearching();return this._state.changeState({findCompleted:!0}),e}async _startSearching(){if(!this._state.findString)return{results:[]};const e=Array.from(this._providers),n=this._findModels=(await Promise.all(e.map(s=>s.find({findString:this._state.findString,findDirection:this._state.findDirection,findScope:this._state.findScope,findBy:this._state.findBy,replaceRevealed:this._state.replaceRevealed,caseSensitive:this._state.caseSensitive,matchesTheWholeCell:this._state.matchesTheWholeCell})))).flat();this._subscribeToModelsChanges(n);const t=this._matches=n.map(s=>s.getMatches()).flat();return this.replaceables$.next(t.filter(s=>s.replaceable)),t.length?(this._moveToInitialMatch(n),this._state.changeState({matchesCount:t.length}),{results:t}):(this._state.changeState({matchesCount:0,matchesPosition:0}),{results:[]})}_stopSearching(){var e;this._providers.forEach(n=>n.terminate()),this._findModels=[],this._matches=[],this._matchingModel=null,(e=this._currentSearchingDisposables)==null||e.dispose(),this._currentSearchingDisposables=null,this.currentMatch$.next(null),this.replaceables$.next([]),this._state.changeState({findCompleted:!1,matchesCount:0,matchesPosition:0})}_subscribeToModelsChanges(e){const n=this._currentSearchingDisposables=new o.DisposableCollection,t=g.combineLatest(e.map(s=>s.matchesUpdate$)).pipe(g.debounceTime(220)).subscribe(([...s])=>{const r=this._matches=s.flat();r.length?(this._moveToInitialMatch(this._findModels,!0),this._state.changeState({matchesCount:r.length}),this.replaceables$.next(r.filter(a=>a.replaceable))):(this._state.changeState({matchesCount:0,matchesPosition:0}),this.replaceables$.next([]))});e.forEach(s=>n.add(o.toDisposable(s.activelyChangingMatch$.subscribe(r=>{const a=this._matches.findIndex(h=>h===r);this._state.changeState({matchesPosition:a+1})})))),n.add(o.toDisposable(t))}async replace(){return this._matchingModel?this._matchingModel.replace(this._state.replaceString):!1}async replaceAll(){const e=await Promise.all(this._findModels.map(n=>n.replaceAll(this._state.replaceString))).then(n=>n.reduce((t,s)=>(t.success+=s.success,t.failure+=s.failure,t),{success:0,failure:0}));return e.failure===0&&this._stopSearching(),e}getCurrentMatch(){return this._state.matchesPosition>0?this._matches[this._state.matchesPosition-1]:null}_markMatch(e){const n=this._matches.findIndex(t=>t===e);this.currentMatch$.next(e),this._state.changeState({matchesPosition:n+1})}moveToNextMatch(){if(!this._matchingModel)return;const e=this._findModels.length===1,n=this._matchingModel.moveToNextMatch({loop:e});if(n)this._markMatch(n);else{const t=this._findModels.findIndex(s=>s===this._matchingModel);this._moveToNextUnitMatch(t)}}_moveToNextUnitMatch(e){const n=this._findModels.length;for(let t=(e+1)%n;t!==e;){const s=this._findModels[t],r=s.moveToNextMatch({ignoreSelection:!0});if(r){this._matchingModel=s,this._markMatch(r);return}t=(t+1)%n}if(this._matchingModel){const t=this._matchingModel.moveToNextMatch({ignoreSelection:!0});t&&this._markMatch(t)}}moveToPreviousMatch(){if(!this._matchingModel)return;const e=this._findModels.length===1,n=this._matchingModel.moveToPreviousMatch({loop:e});if(n){const t=this._matches.findIndex(s=>s===n);this.currentMatch$.next(n),this._state.changeState({matchesPosition:t+1})}else{const t=this._findModels.length,s=this._findModels.findIndex(a=>a===this._matchingModel);for(let a=(s-1+t)%t;a!==s;){const h=this._findModels[a],f=h.moveToPreviousMatch({ignoreSelection:!0});if(f){this._matchingModel=h,this._markMatch(f);return}a=(a-1)%t}const r=this._matchingModel.moveToPreviousMatch({ignoreSelection:!0});r&&this._markMatch(r)}}_moveToInitialMatch(e,n=!1){var r;const t=(r=this._univerInstanceService.getFocusedUnit())==null?void 0:r.getUnitId();if(!t)return-1;const s=e.findIndex(a=>a.unitId===t);if(s!==-1){this._matchingModel=e[s];const a=this._matchingModel.moveToNextMatch({stayIfOnMatch:!0,noFocus:n});if(a)return this._markMatch(a),s}return this._moveToNextUnitMatch(s),0}};w=te([A(2,o.IUniverInstanceService)],w);var D=(i=>(i.ROW="row",i.COLUMN="column",i))(D||{}),O=(i=>(i.VALUE="value",i.FORMULA="formula",i))(O||{}),T=(i=>(i.SUBUNIT="subunit",i.UNIT="unit",i))(T||{});function B(){return{caseSensitive:!1,findBy:"value",findCompleted:!1,findDirection:"row",findScope:"subunit",findString:"",inputtingFindString:"",matchesCount:0,matchesPosition:0,matchesTheWholeCell:!1,replaceRevealed:!1,replaceString:"",revealed:!0}}class Ge{constructor(){l(this,"_stateUpdates$",new g.Subject);l(this,"stateUpdates$",this._stateUpdates$.asObservable());l(this,"_state$",new g.BehaviorSubject(B()));l(this,"state$",this._state$.asObservable());l(this,"_findString","");l(this,"_inputtingFindString","");l(this,"_replaceString","");l(this,"_revealed",!1);l(this,"_replaceRevealed",!1);l(this,"_matchesPosition",0);l(this,"_matchesCount",0);l(this,"_caseSensitive",!0);l(this,"_matchesTheWholeCell",!1);l(this,"_findDirection","row");l(this,"_findScope","subunit");l(this,"_findBy","value");l(this,"_findCompleted",!1)}get state(){return this._state$.getValue()}get inputtingFindString(){return this._inputtingFindString}get findString(){return this._findString}get revealed(){return this._revealed}get replaceRevealed(){return this._replaceRevealed}get matchesPosition(){return this._matchesPosition}get matchesCount(){return this._matchesCount}get replaceString(){return this._replaceString}get caseSensitive(){return this._caseSensitive}get matchesTheWholeCell(){return this._matchesTheWholeCell}get findDirection(){return this._findDirection}get findScope(){return this._findScope}get findBy(){return this._findBy}get findCompleted(){return this._findCompleted}changeState(e){let n=!1;const t={};typeof e.findString<"u"&&e.findString!==this._findString&&(this._findString=e.findString,t.findString=this._findString,n=!0),typeof e.revealed<"u"&&e.revealed!==this._revealed&&(this._revealed=e.revealed,t.revealed=e.revealed,n=!0),typeof e.replaceRevealed<"u"&&e.replaceRevealed!==this._replaceRevealed&&(this._replaceRevealed=e.replaceRevealed,t.replaceRevealed=e.replaceRevealed,n=!0),typeof e.replaceString<"u"&&e.replaceString!==this._replaceString&&(this._replaceString=e.replaceString,t.replaceString=e.replaceString,n=!0),typeof e.matchesCount<"u"&&e.matchesCount!==this._matchesCount&&(this._matchesCount=e.matchesCount,t.matchesCount=e.matchesCount,n=!0),typeof e.matchesPosition<"u"&&e.matchesPosition!==this._matchesPosition&&(this._matchesPosition=e.matchesPosition,t.matchesPosition=e.matchesPosition,n=!0),typeof e.findBy<"u"&&e.findBy!==this._findBy&&(this._findBy=e.findBy,t.findBy=e.findBy,n=!0),typeof e.findScope<"u"&&e.findScope!==this._findScope&&(this._findScope=e.findScope,t.findScope=e.findScope,n=!0),typeof e.findDirection<"u"&&e.findDirection!==this._findDirection&&(this._findDirection=e.findDirection,t.findDirection=e.findDirection,n=!0),typeof e.caseSensitive<"u"&&e.caseSensitive!==this._caseSensitive&&(this._caseSensitive=e.caseSensitive,t.caseSensitive=e.caseSensitive,n=!0),typeof e.matchesTheWholeCell<"u"&&e.matchesTheWholeCell!==this._matchesTheWholeCell&&(this._matchesTheWholeCell=e.matchesTheWholeCell,t.matchesTheWholeCell=e.matchesTheWholeCell,n=!0),typeof e.inputtingFindString<"u"&&e.inputtingFindString!==this._inputtingFindString&&(this._inputtingFindString=e.inputtingFindString,t.inputtingFindString=e.inputtingFindString,n=!0),typeof e.findCompleted<"u"&&e.findCompleted!==this._findCompleted&&(this._findCompleted=e.findCompleted,t.findCompleted=e.findCompleted,n=!0),n&&(this._state$.next({caseSensitive:this._caseSensitive,findBy:this._findBy,findCompleted:this._findCompleted,findDirection:this._findDirection,findScope:this._findScope,findString:this._findString,inputtingFindString:this._inputtingFindString,matchesCount:this._matchesCount,matchesPosition:this._matchesPosition,matchesTheWholeCell:this._matchesTheWholeCell,replaceRevealed:this._replaceRevealed,revealed:this._revealed}),this._stateUpdates$.next(t))}}let U=class extends o.Disposable{constructor(e,n){super();l(this,"_providers",new Set);l(this,"_state",new Ge);l(this,"_model");l(this,"_currentMatch$",new g.BehaviorSubject(null));l(this,"currentMatch$",this._currentMatch$.asObservable());l(this,"_replaceables$",new g.BehaviorSubject([]));l(this,"replaceables$",this._replaceables$.asObservable());l(this,"_focusSignal$",new g.Subject);l(this,"focusSignal$",this._focusSignal$.asObservable());this._injector=e,this._contextService=n}get stateUpdates$(){return this._state.stateUpdates$}get state$(){return this._state.state$}get revealed(){return this._state.revealed}get replaceRevealed(){return this._state.replaceRevealed}dispose(){super.dispose(),this._currentMatch$.next(null),this._currentMatch$.complete(),this._replaceables$.next([]),this._replaceables$.complete(),this._focusSignal$.complete()}getCurrentMatch(){var e;return(e=this._model)==null?void 0:e.getCurrentMatch()}getFindString(){return this._state.findString}changeFindString(e){this._state.changeState({findString:e})}focusFindInput(){this._focusSignal$.next()}changeInputtingFindString(e){e?this._state.changeState({inputtingFindString:e}):this._state.changeState({inputtingFindString:"",findString:""})}changeReplaceString(e){this._state.changeState({replaceString:e})}changeMatchesTheWholeCell(e){this._state.changeState({matchesTheWholeCell:e})}changeCaseSensitive(e){this._state.changeState({caseSensitive:e})}changeFindBy(e){this._state.changeState({findBy:e}),this._toggleDisplayRawFormula(e==="formula")}changeFindScope(e){this._state.changeState({findScope:e})}changeFindDirection(e){this._state.changeState({findDirection:e})}moveToNextMatch(){this._model&&(this._state.replaceRevealed&&!this._model.searched?(this._state.changeState({findString:this._state.inputtingFindString}),this._model.start()):this._model.moveToNextMatch(),this._focusSignal$.next())}moveToPreviousMatch(){this._model&&(this._state.replaceRevealed&&!this._model.searched?(this._state.changeState({findString:this._state.inputtingFindString}),this._model.start()):this._model.moveToPreviousMatch(),this._focusSignal$.next())}async replace(){return this._model?this._model.replace():!1}async replaceAll(){if(!this._model)throw new Error("[FindReplaceService] replaceAll: model is not initialized!");return this._model.replaceAll()}revealReplace(){this._state.changeState({replaceRevealed:!0,inputtingFindString:this._state.findString}),this._toggleRevealReplace(!0)}start(e=!1){if(this._providers.size===0)return!1;this._model=this._injector.createInstance(w,this._state,this._providers),this._model.currentMatch$.subscribe(t=>this._currentMatch$.next(t)),this._model.replaceables$.subscribe(t=>this._replaceables$.next(t));const n=B();return e&&(n.replaceRevealed=!0),this._state.changeState(n),this._toggleRevealReplace(e),!0}find(){var e;(e=this._model)==null||e.start()}terminate(){var e;(e=this._model)==null||e.dispose(),this._model=null,this._toggleDisplayRawFormula(!1),this._toggleRevealReplace(!1)}registerFindReplaceProvider(e){return this._providers.add(e),o.toDisposable(()=>this._providers.delete(e))}_toggleRevealReplace(e){this._contextService.setContextValue(ee,e)}_toggleDisplayRawFormula(e){this._contextService.setContextValue(Pe.RENDER_RAW_FORMULA_KEY,e)}};U=te([A(0,o.Inject(o.Injector)),A(1,o.IContextService)],U);const k={id:"ui.command.replace-current-match",type:o.CommandType.COMMAND,handler:i=>i.get(C).replace()},Ve="CONFIRM_REPLACE_ALL",W={id:"ui.command.replace-all-matches",type:o.CommandType.COMMAND,handler:async i=>{const e=i.get(u.IConfirmService),n=i.get(o.LocaleService),t=i.get(u.IMessageService);if(!await e.confirm({id:Ve,title:{title:n.t("find-replace.replace.confirm.title")},cancelText:n.t("button.cancel"),confirmText:n.t("button.confirm")}))return!1;const r=await i.get(C).replaceAll(),{success:a,failure:h}=r;return h>0?(a===0?t.show({type:p.MessageType.Error,content:n.t("find-replace.replace.all-failure")}):t.show({type:p.MessageType.Warning,content:n.t("find-replace.replace.partial-success",`${a}`,`${h}`)}),!1):(t.show({type:p.MessageType.Success,content:n.t("find-replace.replace.all-success",`${a}`)}),!0)}},y={id:"ui.operation.open-find-dialog",type:o.CommandType.OPERATION,handler:i=>{const e=i.get(C);return e.revealed?e.focusFindInput():e.start(),!0}},E={id:"ui.operation.open-replace-dialog",type:o.CommandType.OPERATION,handler:i=>{const e=i.get(C);return e.revealed?e.replaceRevealed?e.focusFindInput():e.revealReplace():e.start(!0),!0}},G={type:o.CommandType.OPERATION,id:"ui.operation.go-to-next-match",handler:i=>(i.get(C).moveToNextMatch(),!0)},V={type:o.CommandType.OPERATION,id:"ui.operation.go-to-previous-match",handler:i=>(i.get(C).moveToPreviousMatch(),!0)};var ie={exports:{}},N={};/**
2
2
  * @license React
3
3
  * react-jsx-runtime.production.min.js
4
4
  *
@@ -6,4 +6,4 @@
6
6
  *
7
7
  * This source code is licensed under the MIT license found in the
8
8
  * LICENSE file in the root directory of this source tree.
9
- */var f=require$$0,k=Symbol.for("react.element"),l=Symbol.for("react.fragment"),m=Object.prototype.hasOwnProperty,n=f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,p={key:!0,ref:!0,__self:!0,__source:!0};function q(c,a,g){var b,d={},e=null,h=null;g!==void 0&&(e=""+g),a.key!==void 0&&(e=""+a.key),a.ref!==void 0&&(h=a.ref);for(b in a)m.call(a,b)&&!p.hasOwnProperty(b)&&(d[b]=a[b]);if(c&&c.defaultProps)for(b in a=c.defaultProps,a)d[b]===void 0&&(d[b]=a[b]);return{$$typeof:k,type:c,key:e,ref:h,props:d,_owner:n.current}}__name(q,"q");reactJsxRuntime_production_min.Fragment=l;reactJsxRuntime_production_min.jsx=q;reactJsxRuntime_production_min.jsxs=q;jsxRuntime.exports=reactJsxRuntime_production_min;var jsxRuntimeExports=jsxRuntime.exports;function SearchInput(props){const{findCompleted:findComplete,localeService,matchesCount,matchesPosition,findString,findReplaceService,onChange,...rest}=props,text=findComplete&&matchesCount===0?localeService.t("find-replace.dialog.no-result"):matchesCount===0?" ":void 0;return jsxRuntimeExports.jsx(design.InputWithSlot,{autoFocus:!0,placeholder:localeService.t("find-replace.dialog.find-placeholder"),slot:jsxRuntimeExports.jsx(design.Pager,{loop:!0,text,value:matchesPosition,total:matchesCount,onChange:__name(newIndex=>{matchesPosition===matchesCount&&newIndex===1?findReplaceService.moveToNextMatch():matchesPosition===1&&newIndex===matchesCount||newIndex<matchesPosition?findReplaceService.moveToPreviousMatch():findReplaceService.moveToNextMatch()},"onChange")}),value:findString,onChange:__name(value=>onChange==null?void 0:onChange(value),"onChange"),...rest})}__name(SearchInput,"SearchInput");const findReplaceDialogContainer="univer-find-replace-dialog-container",findReplaceExpandContainer="univer-find-replace-expand-container",buttonText="univer-button-text",findReplaceButtonsGroup="univer-find-replace-buttons-group",findReplaceButtonsGroupRight="univer-find-replace-buttons-group-right",styles={findReplaceDialogContainer,findReplaceExpandContainer,buttonText,findReplaceButtonsGroup,findReplaceButtonsGroupRight};function useFindInputFocus(findReplaceService,ref){const focus=require$$0.useCallback(()=>{var _a5;(_a5=document.querySelector(".univer-find-input input"))==null||_a5.focus()},[]),selectHasFocus=require$$0.useCallback(()=>{const allInputs=document.querySelectorAll(".univer-find-replace-dialog-container .univer-select-selection-search-input");return Array.from(allInputs).some(input=>input===document.activeElement)},[]);return require$$0.useImperativeHandle(ref,()=>({focus,selectHasFocus})),require$$0.useEffect(()=>{const subscription=findReplaceService.focusSignal$.subscribe(()=>focus());return()=>subscription.unsubscribe()},[findReplaceService,focus]),{focus,selectHasFocus}}__name(useFindInputFocus,"useFindInputFocus");const FindDialog=require$$0.forwardRef(__name(function(_props,ref){const localeService=core.useDependency(core.LocaleService),findReplaceService=core.useDependency(IFindReplaceService),commandService=core.useDependency(core.ICommandService),state=ui.useObservable(findReplaceService.state$,void 0,!0),{findCompleted,findString,matchesCount,matchesPosition}=state,revealReplace=require$$0.useCallback(()=>{commandService.executeCommand(OpenReplaceDialogOperation.id)},[commandService]),onFindStringChange=require$$0.useCallback(findString2=>findReplaceService.changeFindString(findString2),[findReplaceService]);return useFindInputFocus(findReplaceService,ref),jsxRuntimeExports.jsxs(require$$0.Fragment,{children:[jsxRuntimeExports.jsx(SearchInput,{findCompleted,className:"univer-find-input",matchesCount,matchesPosition,findReplaceService,localeService,findString,onChange:onFindStringChange}),jsxRuntimeExports.jsx("div",{className:styles.findReplaceExpandContainer,children:jsxRuntimeExports.jsx(design.Button,{type:"text",size:"small",onClick:revealReplace,children:localeService.t("find-replace.dialog.advanced-finding")})})]})},"FindDialogImpl")),ReplaceDialog=require$$0.forwardRef(__name(function(_props,ref){const findReplaceService=core.useDependency(IFindReplaceService),localeService=core.useDependency(core.LocaleService),commandService=core.useDependency(core.ICommandService),messageService=core.useDependency(ui.IMessageService),currentMatch=ui.useObservable(findReplaceService.currentMatch$,void 0,!0),replaceables=ui.useObservable(findReplaceService.replaceables$,void 0,!0),state=ui.useObservable(findReplaceService.state$,void 0,!0),{matchesCount,matchesPosition,findString,inputtingFindString,replaceString,caseSensitive,matchesTheWholeCell,findDirection,findScope,findBy,findCompleted}=state,findDisabled=inputtingFindString.length===0,replaceDisabled=matchesCount===0||!(currentMatch!=null&&currentMatch.replaceable),replaceAllDisabled=replaceables.length===0,onFindStringChange=require$$0.useCallback(newValue=>findReplaceService.changeInputtingFindString(newValue),[findReplaceService]),onReplaceStringChange=require$$0.useCallback(replaceString2=>findReplaceService.changeReplaceString(replaceString2),[findReplaceService]),{focus}=useFindInputFocus(findReplaceService,ref),onClickFindButton=require$$0.useCallback(()=>{findString===inputtingFindString?findReplaceService.moveToNextMatch():(findReplaceService.changeFindString(inputtingFindString),findReplaceService.find())},[findString,inputtingFindString,findReplaceService]),onClickReplaceButton=require$$0.useCallback(()=>commandService.executeCommand(ReplaceCurrentMatchCommand.id),[commandService]),onClickReplaceAllButton=require$$0.useCallback(async()=>{await commandService.executeCommand(ReplaceAllMatchesCommand.id),focus()},[commandService]),onChangeFindDirection=require$$0.useCallback(findDirection2=>{findReplaceService.changeFindDirection(findDirection2)},[findReplaceService]),onChangeFindScope=require$$0.useCallback(findScope2=>{findReplaceService.changeFindScope(findScope2)},[findReplaceService]),onChangeFindBy=require$$0.useCallback(findBy2=>{findReplaceService.changeFindBy(findBy2)},[findReplaceService]),findScopeOptions=useFindScopeOptions(localeService),findDirectionOptions=useFindDirectionOptions(localeService),findByOptions=useFindByOptions(localeService);return require$$0.useEffect(()=>{const shouldDisplayNoMatchInfo=findCompleted&&matchesCount===0;let messageDisposable=null;return shouldDisplayNoMatchInfo&&(messageDisposable=messageService.show({content:localeService.t("find-replace.dialog.no-match"),type:design.MessageType.Warning,duration:5e3})),()=>messageDisposable==null?void 0:messageDisposable.dispose()},[findCompleted,matchesCount,messageService,localeService]),jsxRuntimeExports.jsxs(require$$0.Fragment,{children:[jsxRuntimeExports.jsx(design.FormLayout,{label:localeService.t("find-replace.dialog.find"),children:jsxRuntimeExports.jsx(SearchInput,{findCompleted,className:"univer-find-input",matchesCount,matchesPosition,findReplaceService,localeService,findString:inputtingFindString,onChange:onFindStringChange})}),jsxRuntimeExports.jsx(design.FormLayout,{label:localeService.t("find-replace.dialog.replace"),children:jsxRuntimeExports.jsx(design.Input,{placeholder:localeService.t("find-replace.dialog.replace-placeholder"),value:replaceString,onChange:__name(value=>onReplaceStringChange(value),"onChange")})}),jsxRuntimeExports.jsx(design.FormLayout,{label:localeService.t("find-replace.dialog.find-direction.title"),children:jsxRuntimeExports.jsx(design.Select,{value:findDirection,options:findDirectionOptions,onChange:onChangeFindDirection})}),jsxRuntimeExports.jsx(design.FormDualColumnLayout,{children:jsxRuntimeExports.jsxs(require$$0.Fragment,{children:[jsxRuntimeExports.jsx(design.FormLayout,{label:localeService.t("find-replace.dialog.find-scope.title"),children:jsxRuntimeExports.jsx(design.Select,{value:findScope,options:findScopeOptions,onChange:onChangeFindScope})}),jsxRuntimeExports.jsx(design.FormLayout,{label:localeService.t("find-replace.dialog.find-by.title"),children:jsxRuntimeExports.jsx(design.Select,{value:findBy,options:findByOptions,onChange:onChangeFindBy})})]})}),jsxRuntimeExports.jsx(design.FormDualColumnLayout,{children:jsxRuntimeExports.jsxs(require$$0.Fragment,{children:[jsxRuntimeExports.jsx(design.FormLayout,{children:jsxRuntimeExports.jsx(design.Checkbox,{checked:caseSensitive,onChange:__name(checked=>{findReplaceService.changeCaseSensitive(checked)},"onChange"),children:localeService.t("find-replace.dialog.case-sensitive")})}),jsxRuntimeExports.jsx(design.FormLayout,{children:jsxRuntimeExports.jsx(design.Checkbox,{checked:matchesTheWholeCell,onChange:__name(checked=>{findReplaceService.changeMatchesTheWholeCell(checked)},"onChange"),children:localeService.t("find-replace.dialog.match-the-whole-cell")})})]})}),jsxRuntimeExports.jsxs("div",{className:styles.findReplaceButtonsGroup,children:[jsxRuntimeExports.jsx(design.Button,{type:"primary",onClick:onClickFindButton,disabled:findDisabled,children:localeService.t("find-replace.dialog.find")}),jsxRuntimeExports.jsxs("span",{className:styles.findReplaceButtonsGroupRight,children:[jsxRuntimeExports.jsx(design.Button,{disabled:replaceDisabled,onClick:onClickReplaceButton,children:localeService.t("find-replace.dialog.replace")}),jsxRuntimeExports.jsx(design.Button,{disabled:replaceAllDisabled,onClick:onClickReplaceAllButton,children:localeService.t("find-replace.dialog.replace-all")})]})]})]})},"ReplaceDIalogImpl"));function FindReplaceDialog(){const findReplaceService=core.useDependency(IFindReplaceService),layoutService=core.useDependency(ui.ILayoutService),contextService=core.useDependency(core.IContextService),state=ui.useObservable(findReplaceService.state$,void 0,!0),dialogContainerRef=require$$0.useRef(null);require$$0.useEffect(()=>{let disposable;return dialogContainerRef.current&&(disposable=layoutService.registerContainerElement(dialogContainerRef.current)),()=>disposable==null?void 0:disposable.dispose()},[layoutService]);const focusRef=require$$0.useRef(null),setDialogContainerFocus=require$$0.useCallback(focused=>contextService.setContextValue(FIND_REPLACE_DIALOG_FOCUS,focused),[contextService]),setDialogInputFocus=require$$0.useCallback(focused=>contextService.setContextValue(FIND_REPLACE_INPUT_FOCUS,focused),[contextService]);return require$$0.useEffect(()=>{var _a5;const focusSubscription=rxjs.fromEvent(document,"focusin").subscribe(event=>{var _a6;event.target&&((_a6=dialogContainerRef.current)!=null&&_a6.contains(event.target))?setDialogContainerFocus(!0):setDialogContainerFocus(!1),!focusRef.current||!focusRef.current.selectHasFocus()?setDialogInputFocus(!0):setDialogInputFocus(!1)});return(_a5=focusRef.current)==null||_a5.focus(),setDialogContainerFocus(!0),setDialogInputFocus(!0),()=>{focusSubscription.unsubscribe(),setDialogContainerFocus(!1)}},[setDialogContainerFocus,setDialogInputFocus]),jsxRuntimeExports.jsx("div",{className:styles.findReplaceDialogContainer,ref:dialogContainerRef,children:state.replaceRevealed?jsxRuntimeExports.jsx(ReplaceDialog,{ref:focusRef}):jsxRuntimeExports.jsx(FindDialog,{ref:focusRef})})}__name(FindReplaceDialog,"FindReplaceDialog");function useFindScopeOptions(localeService){const locale=localeService.getCurrentLocale();return require$$0.useMemo(()=>[{label:localeService.t("find-replace.dialog.find-scope.current-sheet"),value:FindScope.SUBUNIT},{label:localeService.t("find-replace.dialog.find-scope.workbook"),value:FindScope.UNIT}],[locale])}__name(useFindScopeOptions,"useFindScopeOptions");function useFindDirectionOptions(localeService){const locale=localeService.getCurrentLocale();return require$$0.useMemo(()=>[{label:localeService.t("find-replace.dialog.find-direction.row"),value:FindDirection.ROW},{label:localeService.t("find-replace.dialog.find-direction.column"),value:FindDirection.COLUMN}],[locale])}__name(useFindDirectionOptions,"useFindDirectionOptions");function useFindByOptions(localeService){const locale=localeService.getCurrentLocale();return require$$0.useMemo(()=>[{label:localeService.t("find-replace.dialog.find-by.value"),value:FindBy.VALUE},{label:localeService.t("find-replace.dialog.find-by.formula"),value:FindBy.FORMULA}],[locale])}__name(useFindByOptions,"useFindByOptions");function whenFindReplaceDialogFocused(contextService){return contextService.getContextValue(FIND_REPLACE_DIALOG_FOCUS)}__name(whenFindReplaceDialogFocused,"whenFindReplaceDialogFocused");function whenReplaceRevealed(contextService){return contextService.getContextValue(FIND_REPLACE_REPLACE_REVEALED)}__name(whenReplaceRevealed,"whenReplaceRevealed");function whenFindReplaceInputFocused(contextService){return contextService.getContextValue(FIND_REPLACE_INPUT_FOCUS)}__name(whenFindReplaceInputFocused,"whenFindReplaceInputFocused");const FIND_REPLACE_SHORTCUT_GROUP="7_find-replace-shortcuts";function whenSheetFocused(contextService){return contextService.getContextValue(core.FOCUSING_SHEET)}__name(whenSheetFocused,"whenSheetFocused");function whenEditorNotActivated(contextService){return!contextService.getContextValue(core.EDITOR_ACTIVATED)}__name(whenEditorNotActivated,"whenEditorNotActivated");const OpenFindDialogShortcutItem={id:OpenFindDialogOperation.id,description:"find-replace.shortcut.open-find-dialog",binding:ui.KeyCode.F|ui.MetaKeys.CTRL_COMMAND,group:FIND_REPLACE_SHORTCUT_GROUP,preconditions(contextService){return!whenFindReplaceDialogFocused(contextService)&&whenSheetFocused(contextService)&&whenEditorNotActivated(contextService)}},MacOpenFindDialogShortcutItem={id:OpenFindDialogOperation.id,description:"find-replace.shortcut.open-find-dialog",binding:ui.KeyCode.F|ui.MetaKeys.CTRL_COMMAND,mac:ui.KeyCode.F|ui.MetaKeys.MAC_CTRL,preconditions(contextService){return!whenFindReplaceDialogFocused(contextService)&&whenSheetFocused(contextService)&&whenEditorNotActivated(contextService)}},OpenReplaceDialogShortcutItem={id:OpenReplaceDialogOperation.id,description:"find-replace.shortcut.open-replace-dialog",binding:ui.KeyCode.H|ui.MetaKeys.CTRL_COMMAND,mac:ui.KeyCode.H|ui.MetaKeys.MAC_CTRL,group:FIND_REPLACE_SHORTCUT_GROUP,preconditions(contextService){return whenSheetFocused(contextService)&&whenEditorNotActivated(contextService)&&(!whenFindReplaceDialogFocused(contextService)||!whenReplaceRevealed(contextService))}},GoToNextFindMatchShortcutItem={id:GoToNextMatchOperation.id,description:"find-replace.shortcut.go-to-next-match",binding:ui.KeyCode.ENTER,group:FIND_REPLACE_SHORTCUT_GROUP,priority:1e3,preconditions(contextService){return whenFindReplaceInputFocused(contextService)&&whenFindReplaceDialogFocused(contextService)}},GoToPreviousFindMatchShortcutItem={id:GoToPreviousMatchOperation.id,description:"find-replace.shortcut.go-to-previous-match",binding:ui.KeyCode.ENTER|ui.MetaKeys.SHIFT,group:FIND_REPLACE_SHORTCUT_GROUP,priority:1e3,preconditions(contextService){return whenFindReplaceInputFocused(contextService)&&whenFindReplaceDialogFocused(contextService)}};function FindReplaceMenuItemFactory(accessor){const contextService=accessor.get(core.IContextService);return{id:OpenFindDialogOperation.id,icon:"SearchIcon",tooltip:"find-replace.toolbar",type:ui.MenuItemType.BUTTON,hidden$:ui.getMenuHiddenObservable(accessor,core.UniverInstanceType.UNIVER_SHEET),disabled$:rxjs.combineLatest([contextService.subscribeContextValue$(core.EDITOR_ACTIVATED),contextService.subscribeContextValue$(core.FOCUSING_SHEET)]).pipe(rxjs.map(([editorActivated,focusingSheet])=>editorActivated||!focusingSheet))}}__name(FindReplaceMenuItemFactory,"FindReplaceMenuItemFactory");const menuSchema={[ui.RibbonStartGroup.OTHERS]:{[OpenFindDialogOperation.id]:{order:2,menuItemFactory:FindReplaceMenuItemFactory}}};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");const FIND_REPLACE_DIALOG_ID="DESKTOP_FIND_REPLACE_DIALOG",FIND_REPLACE_PANEL_WIDTH=350,FIND_REPLACE_PANEL_RIGHT_PADDING=20,FIND_REPLACE_PANEL_TOP_PADDING=-90;var _a3;exports.FindReplaceController=(_a3=class extends core.RxDisposable{constructor(_univerInstanceService,_menuManagerService,_shortcutService,_commandService,_findReplaceService,_dialogService,_layoutService,_localeService,_componentManager,_injector){super();__publicField(this,"_closingListenerDisposable");this._univerInstanceService=_univerInstanceService,this._menuManagerService=_menuManagerService,this._shortcutService=_shortcutService,this._commandService=_commandService,this._findReplaceService=_findReplaceService,this._dialogService=_dialogService,this._layoutService=_layoutService,this._localeService=_localeService,this._componentManager=_componentManager,this._injector=_injector,this._initCommands(),this._initUI(),this._initShortcuts()}dispose(){var _a5;super.dispose(),(_a5=this._closingListenerDisposable)==null||_a5.dispose(),this._closingListenerDisposable=null}_initCommands(){[OpenFindDialogOperation,OpenReplaceDialogOperation,GoToNextMatchOperation,GoToPreviousMatchOperation,ReplaceAllMatchesCommand,ReplaceCurrentMatchCommand].forEach(c=>{this.disposeWithMe(this._commandService.registerCommand(c))})}_initShortcuts(){[OpenReplaceDialogShortcutItem,OpenFindDialogShortcutItem,MacOpenFindDialogShortcutItem,GoToPreviousFindMatchShortcutItem,GoToNextFindMatchShortcutItem].forEach(s=>this.disposeWithMe(this._shortcutService.registerShortcut(s)))}_initUI(){this.disposeWithMe(this._componentManager.register("FindReplaceDialog",FindReplaceDialog)),this.disposeWithMe(this._componentManager.register("SearchIcon",SearchSingle16)),this._menuManagerService.mergeMenu(menuSchema),this._findReplaceService.stateUpdates$.pipe(rxjs.takeUntil(this.dispose$)).subscribe(newState=>{newState.revealed===!0&&this._openPanel()})}_openPanel(){this._dialogService.open({id:FIND_REPLACE_DIALOG_ID,draggable:!0,width:FIND_REPLACE_PANEL_WIDTH,title:{title:this._localeService.t("find-replace.dialog.title")},children:{label:"FindReplaceDialog"},destroyOnClose:!0,defaultPosition:getFindReplaceDialogDefaultPosition(),preservePositionOnDestroy:!0,onClose:__name(()=>this.closePanel(),"onClose")}),this._closingListenerDisposable=core.toDisposable(this._univerInstanceService.focused$.pipe(rxjs.takeUntil(this.dispose$)).subscribe(focused=>{(!focused||!this._univerInstanceService.getUniverSheetInstance(focused))&&this.closePanel()}))}closePanel(){this._closingListenerDisposable&&(this._closingListenerDisposable.dispose(),this._closingListenerDisposable=null,this._dialogService.close(FIND_REPLACE_DIALOG_ID),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus()))}},__name(_a3,"FindReplaceController"),_a3);exports.FindReplaceController=__decorateClass$1([__decorateParam$1(0,core.IUniverInstanceService),__decorateParam$1(1,ui.IMenuManagerService),__decorateParam$1(2,ui.IShortcutService),__decorateParam$1(3,core.ICommandService),__decorateParam$1(4,IFindReplaceService),__decorateParam$1(5,ui.IDialogService),__decorateParam$1(6,ui.ILayoutService),__decorateParam$1(7,core.Inject(core.LocaleService)),__decorateParam$1(8,core.Inject(ui.ComponentManager)),__decorateParam$1(9,core.Inject(core.Injector))],exports.FindReplaceController);function getFindReplaceDialogDefaultPosition(){const{innerWidth}=window;return{x:(innerWidth-FIND_REPLACE_PANEL_WIDTH)/2-FIND_REPLACE_PANEL_RIGHT_PADDING,y:FIND_REPLACE_PANEL_TOP_PADDING}}__name(getFindReplaceDialogDefaultPosition,"getFindReplaceDialogDefaultPosition");var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__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");const PLUGIN_NAME="UNIVER_FIND_REPLACE_PLUGIN";var _a4;exports.UniverFindReplacePlugin=(_a4=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(){[[exports.FindReplaceController],[IFindReplaceService,{useClass:FindReplaceService}]].forEach(d=>this._injector.add(d))}onRendered(){this._injector.get(exports.FindReplaceController)}},__name(_a4,"UniverFindReplacePlugin"),__publicField(_a4,"pluginName",PLUGIN_NAME),_a4);exports.UniverFindReplacePlugin=__decorateClass([__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.IConfigService)],exports.UniverFindReplacePlugin);exports.FindBy=FindBy;exports.FindDirection=FindDirection;exports.FindModel=FindModel;exports.FindScope=FindScope;exports.GoToNextMatchOperation=GoToNextMatchOperation;exports.GoToPreviousMatchOperation=GoToPreviousMatchOperation;exports.IFindReplaceService=IFindReplaceService;exports.OpenFindDialogOperation=OpenFindDialogOperation;exports.OpenReplaceDialogOperation=OpenReplaceDialogOperation;exports.ReplaceAllMatchesCommand=ReplaceAllMatchesCommand;exports.ReplaceCurrentMatchCommand=ReplaceCurrentMatchCommand;
9
+ */var He=c,Ke=Symbol.for("react.element"),qe=Symbol.for("react.fragment"),ze=Object.prototype.hasOwnProperty,Ye=He.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Ze={key:!0,ref:!0,__self:!0,__source:!0};function ne(i,e,n){var t,s={},r=null,a=null;n!==void 0&&(r=""+n),e.key!==void 0&&(r=""+e.key),e.ref!==void 0&&(a=e.ref);for(t in e)ze.call(e,t)&&!Ze.hasOwnProperty(t)&&(s[t]=e[t]);if(i&&i.defaultProps)for(t in e=i.defaultProps,e)s[t]===void 0&&(s[t]=e[t]);return{$$typeof:Ke,type:i,key:r,ref:a,props:s,_owner:Ye.current}}N.Fragment=qe;N.jsx=ne;N.jsxs=ne;ie.exports=N;var d=ie.exports;function se(i){const{findCompleted:e,localeService:n,matchesCount:t,matchesPosition:s,findString:r,findReplaceService:a,onChange:h,...f}=i,v=e&&t===0?n.t("find-replace.dialog.no-result"):t===0?" ":void 0;return d.jsx(p.InputWithSlot,{autoFocus:!0,placeholder:n.t("find-replace.dialog.find-placeholder"),slot:d.jsx(p.Pager,{loop:!0,text:v,value:s,total:t,onChange:m=>{s===t&&m===1?a.moveToNextMatch():s===1&&m===t||m<s?a.moveToPreviousMatch():a.moveToNextMatch()}}),value:r,onChange:m=>h==null?void 0:h(m),...f})}const Je="univer-find-replace-dialog-container",Qe="univer-find-replace-expand-container",Xe="univer-button-text",et="univer-find-replace-buttons-group",tt="univer-find-replace-buttons-group-right",P={findReplaceDialogContainer:Je,findReplaceExpandContainer:Qe,buttonText:Xe,findReplaceButtonsGroup:et,findReplaceButtonsGroupRight:tt};function re(i,e){const n=c.useCallback(()=>{var s;(s=document.querySelector(".univer-find-input input"))==null||s.focus()},[]),t=c.useCallback(()=>{const s=document.querySelectorAll(".univer-find-replace-dialog-container .univer-select-selection-search-input");return Array.from(s).some(r=>r===document.activeElement)},[]);return c.useImperativeHandle(e,()=>({focus:n,selectHasFocus:t})),c.useEffect(()=>{const s=i.focusSignal$.subscribe(()=>n());return()=>s.unsubscribe()},[i,n]),{focus:n,selectHasFocus:t}}const it=c.forwardRef(function(e,n){const t=o.useDependency(o.LocaleService),s=o.useDependency(C),r=o.useDependency(o.ICommandService),a=u.useObservable(s.state$,void 0,!0),{findCompleted:h,findString:f,matchesCount:b,matchesPosition:v}=a,m=c.useCallback(()=>{r.executeCommand(E.id)},[r]),x=c.useCallback(M=>s.changeFindString(M),[s]);return re(s,n),d.jsxs(c.Fragment,{children:[d.jsx(se,{findCompleted:h,className:"univer-find-input",matchesCount:b,matchesPosition:v,findReplaceService:s,localeService:t,findString:f,onChange:x}),d.jsx("div",{className:P.findReplaceExpandContainer,children:d.jsx(p.Button,{type:"text",size:"small",onClick:m,children:t.t("find-replace.dialog.advanced-finding")})})]})}),nt=c.forwardRef(function(e,n){const t=o.useDependency(C),s=o.useDependency(o.LocaleService),r=o.useDependency(o.ICommandService),a=o.useDependency(u.IMessageService),h=u.useObservable(t.currentMatch$,void 0,!0),f=u.useObservable(t.replaceables$,void 0,!0),b=u.useObservable(t.state$,void 0,!0),{matchesCount:v,matchesPosition:m,findString:x,inputtingFindString:M,replaceString:ce,caseSensitive:le,matchesTheWholeCell:de,findDirection:ue,findScope:he,findBy:pe,findCompleted:j}=b,fe=M.length===0,_e=v===0||!(h!=null&&h.replaceable),ge=f.length===0,me=c.useCallback(_=>t.changeInputtingFindString(_),[t]),ve=c.useCallback(_=>t.changeReplaceString(_),[t]),{focus:Se}=re(t,n),Ce=c.useCallback(()=>{x===M?t.moveToNextMatch():(t.changeFindString(M),t.find())},[x,M,t]),Re=c.useCallback(()=>r.executeCommand(k.id),[r]),be=c.useCallback(async()=>{await r.executeCommand(W.id),Se()},[r]),Me=c.useCallback(_=>{t.changeFindDirection(_)},[t]),ye=c.useCallback(_=>{t.changeFindScope(_)},[t]),Ie=c.useCallback(_=>{t.changeFindBy(_)},[t]),xe=rt(s),Fe=at(s),De=ot(s);return c.useEffect(()=>{const _=j&&v===0;let F=null;return _&&(F=a.show({content:s.t("find-replace.dialog.no-match"),type:p.MessageType.Warning,duration:5e3})),()=>F==null?void 0:F.dispose()},[j,v,a,s]),d.jsxs(c.Fragment,{children:[d.jsx(p.FormLayout,{label:s.t("find-replace.dialog.find"),children:d.jsx(se,{findCompleted:j,className:"univer-find-input",matchesCount:v,matchesPosition:m,findReplaceService:t,localeService:s,findString:M,onChange:me})}),d.jsx(p.FormLayout,{label:s.t("find-replace.dialog.replace"),children:d.jsx(p.Input,{placeholder:s.t("find-replace.dialog.replace-placeholder"),value:ce,onChange:_=>ve(_)})}),d.jsx(p.FormLayout,{label:s.t("find-replace.dialog.find-direction.title"),children:d.jsx(p.Select,{value:ue,options:Fe,onChange:Me})}),d.jsx(p.FormDualColumnLayout,{children:d.jsxs(c.Fragment,{children:[d.jsx(p.FormLayout,{label:s.t("find-replace.dialog.find-scope.title"),children:d.jsx(p.Select,{value:he,options:xe,onChange:ye})}),d.jsx(p.FormLayout,{label:s.t("find-replace.dialog.find-by.title"),children:d.jsx(p.Select,{value:pe,options:De,onChange:Ie})})]})}),d.jsx(p.FormDualColumnLayout,{children:d.jsxs(c.Fragment,{children:[d.jsx(p.FormLayout,{children:d.jsx(p.Checkbox,{checked:le,onChange:_=>{t.changeCaseSensitive(_)},children:s.t("find-replace.dialog.case-sensitive")})}),d.jsx(p.FormLayout,{children:d.jsx(p.Checkbox,{checked:de,onChange:_=>{t.changeMatchesTheWholeCell(_)},children:s.t("find-replace.dialog.match-the-whole-cell")})})]})}),d.jsxs("div",{className:P.findReplaceButtonsGroup,children:[d.jsx(p.Button,{type:"primary",onClick:Ce,disabled:fe,children:s.t("find-replace.dialog.find")}),d.jsxs("span",{className:P.findReplaceButtonsGroupRight,children:[d.jsx(p.Button,{disabled:_e,onClick:Re,children:s.t("find-replace.dialog.replace")}),d.jsx(p.Button,{disabled:ge,onClick:be,children:s.t("find-replace.dialog.replace-all")})]})]})]})});function st(){const i=o.useDependency(C),e=o.useDependency(u.ILayoutService),n=o.useDependency(o.IContextService),t=u.useObservable(i.state$,void 0,!0),s=c.useRef(null);c.useEffect(()=>{let f;return s.current&&(f=e.registerContainerElement(s.current)),()=>f==null?void 0:f.dispose()},[e]);const r=c.useRef(null),a=c.useCallback(f=>n.setContextValue(X,f),[n]),h=c.useCallback(f=>n.setContextValue(Q,f),[n]);return c.useEffect(()=>{var b;const f=g.fromEvent(document,"focusin").subscribe(v=>{var m;v.target&&((m=s.current)!=null&&m.contains(v.target))?a(!0):a(!1),!r.current||!r.current.selectHasFocus()?h(!0):h(!1)});return(b=r.current)==null||b.focus(),a(!0),h(!0),()=>{f.unsubscribe(),a(!1)}},[a,h]),d.jsx("div",{className:P.findReplaceDialogContainer,ref:s,children:t.replaceRevealed?d.jsx(nt,{ref:r}):d.jsx(it,{ref:r})})}function rt(i){const e=i.getCurrentLocale();return c.useMemo(()=>[{label:i.t("find-replace.dialog.find-scope.current-sheet"),value:T.SUBUNIT},{label:i.t("find-replace.dialog.find-scope.workbook"),value:T.UNIT}],[e])}function at(i){const e=i.getCurrentLocale();return c.useMemo(()=>[{label:i.t("find-replace.dialog.find-direction.row"),value:D.ROW},{label:i.t("find-replace.dialog.find-direction.column"),value:D.COLUMN}],[e])}function ot(i){const e=i.getCurrentLocale();return c.useMemo(()=>[{label:i.t("find-replace.dialog.find-by.value"),value:O.VALUE},{label:i.t("find-replace.dialog.find-by.formula"),value:O.FORMULA}],[e])}function I(i){return i.getContextValue(X)}function ct(i){return i.getContextValue(ee)}function ae(i){return i.getContextValue(Q)}const $="7_find-replace-shortcuts";function H(i){return i.getContextValue(o.FOCUSING_SHEET)}function K(i){return!i.getContextValue(o.EDITOR_ACTIVATED)}const lt={id:y.id,description:"find-replace.shortcut.open-find-dialog",binding:u.KeyCode.F|u.MetaKeys.CTRL_COMMAND,group:$,preconditions(i){return!I(i)&&H(i)&&K(i)}},dt={id:y.id,description:"find-replace.shortcut.open-find-dialog",binding:u.KeyCode.F|u.MetaKeys.CTRL_COMMAND,mac:u.KeyCode.F|u.MetaKeys.MAC_CTRL,preconditions(i){return!I(i)&&H(i)&&K(i)}},ut={id:E.id,description:"find-replace.shortcut.open-replace-dialog",binding:u.KeyCode.H|u.MetaKeys.CTRL_COMMAND,mac:u.KeyCode.H|u.MetaKeys.MAC_CTRL,group:$,preconditions(i){return H(i)&&K(i)&&(!I(i)||!ct(i))}},ht={id:G.id,description:"find-replace.shortcut.go-to-next-match",binding:u.KeyCode.ENTER,group:$,priority:1e3,preconditions(i){return ae(i)&&I(i)}},pt={id:V.id,description:"find-replace.shortcut.go-to-previous-match",binding:u.KeyCode.ENTER|u.MetaKeys.SHIFT,group:$,priority:1e3,preconditions(i){return ae(i)&&I(i)}};function ft(i){const e=i.get(o.IContextService);return{id:y.id,icon:"SearchIcon",tooltip:"find-replace.toolbar",type:u.MenuItemType.BUTTON,hidden$:u.getMenuHiddenObservable(i,o.UniverInstanceType.UNIVER_SHEET),disabled$:g.combineLatest([e.subscribeContextValue$(o.EDITOR_ACTIVATED),e.subscribeContextValue$(o.FOCUSING_SHEET)]).pipe(g.map(([n,t])=>n||!t))}}const _t={[u.RibbonStartGroup.OTHERS]:{[y.id]:{order:2,menuItemFactory:ft}}};var gt=Object.defineProperty,mt=Object.getOwnPropertyDescriptor,vt=(i,e,n,t)=>{for(var s=t>1?void 0:t?mt(e,n):e,r=i.length-1,a;r>=0;r--)(a=i[r])&&(s=(t?a(e,n,s):a(s))||s);return t&&s&&gt(e,n,s),s},R=(i,e)=>(n,t)=>e(n,t,i);const q="DESKTOP_FIND_REPLACE_DIALOG",oe=350,St=20,Ct=-90;exports.FindReplaceController=class extends o.RxDisposable{constructor(n,t,s,r,a,h,f,b,v,m){super();l(this,"_closingListenerDisposable");this._univerInstanceService=n,this._menuManagerService=t,this._shortcutService=s,this._commandService=r,this._findReplaceService=a,this._dialogService=h,this._layoutService=f,this._localeService=b,this._componentManager=v,this._injector=m,this._initCommands(),this._initUI(),this._initShortcuts()}dispose(){var n;super.dispose(),(n=this._closingListenerDisposable)==null||n.dispose(),this._closingListenerDisposable=null}_initCommands(){[y,E,G,V,W,k].forEach(n=>{this.disposeWithMe(this._commandService.registerCommand(n))})}_initShortcuts(){[ut,lt,dt,pt,ht].forEach(n=>this.disposeWithMe(this._shortcutService.registerShortcut(n)))}_initUI(){this.disposeWithMe(this._componentManager.register("FindReplaceDialog",st)),this.disposeWithMe(this._componentManager.register("SearchIcon",J)),this._menuManagerService.mergeMenu(_t),this._findReplaceService.stateUpdates$.pipe(g.takeUntil(this.dispose$)).subscribe(n=>{n.revealed===!0&&this._openPanel()})}_openPanel(){this._dialogService.open({id:q,draggable:!0,width:oe,title:{title:this._localeService.t("find-replace.dialog.title")},children:{label:"FindReplaceDialog"},destroyOnClose:!0,defaultPosition:Rt(),preservePositionOnDestroy:!0,onClose:()=>this.closePanel()}),this._closingListenerDisposable=o.toDisposable(this._univerInstanceService.focused$.pipe(g.takeUntil(this.dispose$)).subscribe(n=>{(!n||!this._univerInstanceService.getUniverSheetInstance(n))&&this.closePanel()}))}closePanel(){this._closingListenerDisposable&&(this._closingListenerDisposable.dispose(),this._closingListenerDisposable=null,this._dialogService.close(q),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus()))}};exports.FindReplaceController=vt([R(0,o.IUniverInstanceService),R(1,u.IMenuManagerService),R(2,u.IShortcutService),R(3,o.ICommandService),R(4,C),R(5,u.IDialogService),R(6,u.ILayoutService),R(7,o.Inject(o.LocaleService)),R(8,o.Inject(u.ComponentManager)),R(9,o.Inject(o.Injector))],exports.FindReplaceController);function Rt(){const{innerWidth:i}=window;return{x:(i-oe)/2-St,y:Ct}}var bt=Object.defineProperty,Mt=Object.getOwnPropertyDescriptor,yt=(i,e,n,t)=>{for(var s=t>1?void 0:t?Mt(e,n):e,r=i.length-1,a;r>=0;r--)(a=i[r])&&(s=(t?a(e,n,s):a(s))||s);return t&&s&&bt(e,n,s),s},z=(i,e)=>(n,t)=>e(n,t,i);const It="UNIVER_FIND_REPLACE_PLUGIN";var L;exports.UniverFindReplacePlugin=(L=class extends o.Plugin{constructor(e=Ne,n,t){super(),this._config=e,this._injector=n,this._configService=t;const{...s}=this._config;this._configService.setConfig(Ee,s)}onStarting(){[[exports.FindReplaceController],[C,{useClass:U}]].forEach(e=>this._injector.add(e))}onRendered(){this._injector.get(exports.FindReplaceController)}},l(L,"pluginName",It),L);exports.UniverFindReplacePlugin=yt([z(1,o.Inject(o.Injector)),z(2,o.IConfigService)],exports.UniverFindReplacePlugin);exports.FindBy=O;exports.FindDirection=D;exports.FindModel=ke;exports.FindScope=T;exports.GoToNextMatchOperation=G;exports.GoToPreviousMatchOperation=V;exports.IFindReplaceService=C;exports.OpenFindDialogOperation=y;exports.OpenReplaceDialogOperation=E;exports.ReplaceAllMatchesCommand=W;exports.ReplaceCurrentMatchCommand=k;
@@ -0,0 +1 @@
1
+ "use strict";const e={"find-replace":{toolbar:"Find & Replace",shortcut:{"open-find-dialog":"Open Find Dialog","open-replace-dialog":"Open Replace Dialog","close-dialog":"Close Find & Replace Dialog","go-to-next-match":"Go to Next Match","go-to-previous-match":"Go to Previous Match"},dialog:{title:"Find",find:"Find",replace:"Replace","replace-all":"Replace All","case-sensitive":"Case Sensitive","find-placeholder":"Find in this Sheet","advanced-finding":"Advanced Searching & Replace","replace-placeholder":"Input Replace String","match-the-whole-cell":"Match the Whole Cell","find-direction":{title:"Find Direction",row:"Search by Row",column:"Search by Column"},"find-scope":{title:"Find Range","current-sheet":"Current Sheet",workbook:"Workbook"},"find-by":{title:"Find By",value:"Find by Value",formula:"Find Formula"},"no-match":"Finding completed but no match found.","no-result":"No Result"},replace:{"all-success":"Replaced all {0} matches","all-failure":"Replace failed",confirm:{title:"Are you sure to replace all matches?"}}},"find-replace-shortcuts":"Find & Replace"};module.exports=e;
@@ -0,0 +1 @@
1
+ "use strict";const e={"find-replace":{toolbar:"یافتن و جایگزینی",shortcut:{"open-find-dialog":"باز کردن پنجره گفتگوی یافتن","open-replace-dialog":"باز کردن پنجره گفتگوی جایگزینی","close-dialog":"بستن پنجره گفتگوی یافتن و جایگزینی","go-to-next-match":"رفتن به تطابق بعدی","go-to-previous-match":"رفتن به تطابق قبلی"},dialog:{title:"یافتن",find:"یافتن",replace:"جایگزینی","replace-all":"جایگزینی همه","case-sensitive":"حساس به حروف کوچک و بزرگ","find-placeholder":"یافتن در این برگ","advanced-finding":"جستجوی پیشرفته و جایگزینی","replace-placeholder":"ورود رشته جایگزین","match-the-whole-cell":"مطابقت با کل سلول","find-direction":{title:"جهت یافتن",row:"جستجو بر اساس سطر",column:"جستجو بر اساس ستون"},"find-scope":{title:"محدوده یافتن","current-sheet":"برگ فعلی",workbook:"کتاب کار"},"find-by":{title:"یافتن بر اساس",value:"یافتن بر اساس مقدار",formula:"یافتن فرمول"},"no-match":"یافتن تکمیل شد اما هیچ تطابقی یافت نشد.","no-result":"نتیجه‌ای وجود ندارد"},replace:{"all-success":"همه {0} تطابق جایگزین شد","all-failure":"جایگزینی ناموفق بود",confirm:{title:"آیا مطمئن هستید که همه تطابق‌ها را جایگزین کنید؟"}}},"find-replace-shortcuts":"یافتن و جایگزینی"};module.exports=e;
@@ -0,0 +1 @@
1
+ "use strict";const e={"find-replace":{toolbar:"Найти и заменить",shortcut:{"open-find-dialog":"Открыть диалог поиска","open-replace-dialog":"Открыть диалог замены","close-dialog":"Закрыть диалог поиска и замены","go-to-next-match":"Перейти к следующему совпадению","go-to-previous-match":"Перейти к предыдущему совпадению"},dialog:{title:"Найти",find:"Найти",replace:"Заменить","replace-all":"Заменить все","case-sensitive":"С учетом регистра","find-placeholder":"Найти в этом листе","advanced-finding":"Расширенный поиск и замена","replace-placeholder":"Введите строку для замены","match-the-whole-cell":"Точное совпадение","find-direction":{title:"Направление поиска",row:"Поиск по строкам",column:"Поиск по столбцам"},"find-scope":{title:"Область поиска","current-sheet":"Текущий лист",workbook:"Книга"},"find-by":{title:"Поиск по",value:"Поиск по значению",formula:"Поиск по формуле"},"no-match":"Поиск завершен, совпадений не найдено.","no-result":"Нет результатов"},replace:{"all-success":"Заменены все {0} совпадений","all-failure":"Не удалось заменить",confirm:{title:"Вы уверены, что хотите заменить все совпадения?"}}},"find-replace-shortcuts":"Найти и заменить"};module.exports=e;
@@ -0,0 +1 @@
1
+ "use strict";const t={"find-replace":{toolbar:"Tìm kiếm và Thay thế",shortcut:{"open-find-dialog":"Mở hộp thoại tìm kiếm","open-replace-dialog":"Mở hộp thoại thay thế","close-dialog":"Đóng hộp thoại tìm kiếm và thay thế","go-to-next-match":"Đến mục khớp tiếp theo","go-to-previous-match":"Đến mục khớp trước đó"},dialog:{title:"Tìm kiếm",find:"Tìm kiếm",replace:"Thay thế","replace-all":"Thay thế tất cả","find-placeholder":"Nhập nội dung tìm kiếm","advanced-finding":"Thay thế / Tìm kiếm nâng cao","replace-placeholder":"Nhập nội dung thay thế","case-sensitive":"Phân biệt chữ hoa chữ thường","match-the-whole-cell":"Khớp toàn bộ ô","find-scope":{title:"Phạm vi tìm kiếm","current-sheet":"Bảng hiện tại",workbook:"Toàn bộ sổ làm việc"},"find-direction":{title:"Thứ tự tìm kiếm",column:"Tìm theo cột",row:"Tìm theo hàng"},"find-by":{title:"Phương thức tìm kiếm",formula:"Tìm công thức",value:"Tìm giá trị"},"no-match":"Đã hoàn thành tìm kiếm nhưng không tìm thấy mục nào khớp","no-result":"Không có kết quả"},replace:{"all-success":"Đã thay thế tất cả {0} mục khớp","all-failure":"Thay thế thất bại",confirm:{title:"Bạn có chắc muốn thay thế tất cả các mục khớp không?"}}},"find-replace-shortcuts":"Tìm kiếm và Thay thế"};module.exports=t;
@@ -0,0 +1 @@
1
+ "use strict";const e={"find-replace":{toolbar:"查找替换",shortcut:{"open-find-dialog":"打开查找对话框","open-replace-dialog":"打开替换对话框","close-dialog":"关闭查找替换对话框","go-to-next-match":"下一个匹配项","go-to-previous-match":"下一个匹配项"},dialog:{title:"查找",find:"查找",replace:"替换","replace-all":"替换全部","find-placeholder":"输入查找内容","advanced-finding":"替换 / 高级查找","replace-placeholder":"输入替换内容","case-sensitive":"匹配大小写","match-the-whole-cell":"匹配整个单元格","find-scope":{title:"查找范围","current-sheet":"当前子表",workbook:"整个工作簿"},"find-direction":{title:"查找顺序",column:"按列查找",row:"按行查找"},"find-by":{title:"查找方式",formula:"查找公式",value:"查找值"},"no-match":"已完成搜索,但是未找到任何匹配项","no-result":"无结果"},replace:{"all-success":"已全部替换 {0} 个匹配项","all-failure":"替换失败",confirm:{title:"确定要替换所有的匹配项吗?"}}},"find-replace-shortcuts":"查找替换"};module.exports=e;
@@ -0,0 +1 @@
1
+ "use strict";const e={"find-replace":{toolbar:"尋找替換",shortcut:{"open-find-dialog":"開啟尋找對話框","open-replace-dialog":"開啟替換對話框","close-dialog":"關閉查找替換對話框","go-to-next-match":"下一個匹配項","go-to-previous-match":"下一個匹配項"},dialog:{title:"找",find:"找",replace:"替換","replace-all":"替換全部","find-placeholder":"輸入查找內容","advanced-finding":"取代 / 進階查找","replace-placeholder":"輸入替換內容","case-sensitive":"匹配大小寫","match-the-whole-cell":"符合整個儲存格","find-scope":{title:"找出範圍","current-sheet":"目前子表",workbook:"整個工作簿"},"find-direction":{title:"找出順序",column:"按列查找",row:"按行查找"},"find-by":{title:"找出方式",formula:"找出公式",value:"查找值"},"no-match":"已完成搜索,但是未找到任何匹配項","no-result":"無結果"},replace:{"all-success":"已全部替換 {0} 個匹配項","all-failure":"替換失敗",confirm:{title:"確定要取代所有的符合項目嗎? "}}},"find-replace-shortcuts":"尋找替換"};module.exports=e;