@univerjs/find-replace 0.3.0-alpha.1 → 0.3.0-nightly.202410111606

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"),engineRender=require("@univerjs/engine-render"),require$$0=require("react"),design=require("@univerjs/design");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 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 __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={};/**
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;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")};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([core.OnLifecycle(core.LifecycleStages.Rendered,exports.FindReplaceController),__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");const PLUGIN_CONFIG_KEY="find-replace.config",defaultPluginConfig={};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)})}},__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 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;
package/lib/es/index.js CHANGED
@@ -2,12 +2,13 @@ var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
3
3
  var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
4
4
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
5
- import { createIdentifier, Inject, Injector, Disposable, IUniverInstanceService, IContextService, DisposableCollection, toDisposable, CommandType, LocaleService, useDependency, ICommandService, FOCUSING_SHEET, EDITOR_ACTIVATED, UniverInstanceType, OnLifecycle, LifecycleStages, RxDisposable, Plugin, IConfigService } from "@univerjs/core";
5
+ import { createIdentifier, Inject, Injector, Disposable, IUniverInstanceService, IContextService, DisposableCollection, toDisposable, CommandType, LocaleService, useDependency, ICommandService, FOCUSING_SHEET, EDITOR_ACTIVATED, UniverInstanceType, RxDisposable, Plugin, IConfigService } from "@univerjs/core";
6
6
  import { IConfirmService, IMessageService, useObservable, ILayoutService, KeyCode, MetaKeys, MenuItemType, getMenuHiddenObservable, RibbonStartGroup, ComponentManager, IMenuManagerService, IShortcutService, IDialogService } from "@univerjs/ui";
7
7
  import { throttleTime, BehaviorSubject, combineLatest, debounceTime, Subject, fromEvent, map, takeUntil } from "rxjs";
8
+ import { MessageType, InputWithSlot, Pager, Button, FormLayout, Input, Select, FormDualColumnLayout, Checkbox } from "@univerjs/design";
8
9
  import { RENDER_RAW_FORMULA_KEY } from "@univerjs/engine-render";
9
10
  import require$$0, { forwardRef, useRef, createElement, useCallback, Fragment, useEffect, useMemo, useImperativeHandle } from "react";
10
- import { MessageType, InputWithSlot, Pager, Button, FormLayout, Input, Select, FormDualColumnLayout, Checkbox } from "@univerjs/design";
11
+ const PLUGIN_CONFIG_KEY = "find-replace.config", defaultPluginConfig = {};
11
12
  var __assign = function() {
12
13
  return __assign = Object.assign || function(t) {
13
14
  for (var s, i = 1, n2 = arguments.length; i < n2; i++) {
@@ -441,7 +442,35 @@ FindReplaceService = __decorateClass$2([
441
442
  __decorateParam$2(0, Inject(Injector)),
442
443
  __decorateParam$2(1, IContextService)
443
444
  ], FindReplaceService);
444
- const OpenFindDialogOperation = {
445
+ const ReplaceCurrentMatchCommand = {
446
+ id: "ui.command.replace-current-match",
447
+ type: CommandType.COMMAND,
448
+ handler: /* @__PURE__ */ __name((accessor) => accessor.get(IFindReplaceService).replace(), "handler")
449
+ }, CONFIRM_REPLACE_ALL_ID = "CONFIRM_REPLACE_ALL", ReplaceAllMatchesCommand = {
450
+ id: "ui.command.replace-all-matches",
451
+ type: CommandType.COMMAND,
452
+ handler: /* @__PURE__ */ __name(async (accessor) => {
453
+ const confirmService = accessor.get(IConfirmService), localeService = accessor.get(LocaleService), messageService = accessor.get(IMessageService);
454
+ if (!await confirmService.confirm({
455
+ id: CONFIRM_REPLACE_ALL_ID,
456
+ title: { title: localeService.t("find-replace.replace.confirm.title") },
457
+ cancelText: localeService.t("button.cancel"),
458
+ confirmText: localeService.t("button.confirm")
459
+ }))
460
+ return !1;
461
+ const result = await accessor.get(IFindReplaceService).replaceAll(), { success, failure } = result;
462
+ return failure > 0 ? (success === 0 ? messageService.show({
463
+ type: MessageType.Error,
464
+ content: localeService.t("find-replace.replace.all-failure")
465
+ }) : messageService.show({
466
+ type: MessageType.Warning,
467
+ content: localeService.t("find-replace.replace.partial-success", `${success}`, `${failure}`)
468
+ }), !1) : (messageService.show({
469
+ type: MessageType.Success,
470
+ content: localeService.t("find-replace.replace.all-success", `${success}`)
471
+ }), !0);
472
+ }, "handler")
473
+ }, OpenFindDialogOperation = {
445
474
  id: "ui.operation.open-find-dialog",
446
475
  type: CommandType.OPERATION,
447
476
  handler: /* @__PURE__ */ __name((accessor) => {
@@ -488,35 +517,6 @@ reactJsxRuntime_production_min.jsx = q;
488
517
  reactJsxRuntime_production_min.jsxs = q;
489
518
  jsxRuntime.exports = reactJsxRuntime_production_min;
490
519
  var jsxRuntimeExports = jsxRuntime.exports;
491
- const ReplaceCurrentMatchCommand = {
492
- id: "ui.command.replace-current-match",
493
- type: CommandType.COMMAND,
494
- handler: /* @__PURE__ */ __name((accessor) => accessor.get(IFindReplaceService).replace(), "handler")
495
- }, CONFIRM_REPLACE_ALL_ID = "CONFIRM_REPLACE_ALL", ReplaceAllMatchesCommand = {
496
- id: "ui.command.replace-all-matches",
497
- type: CommandType.COMMAND,
498
- handler: /* @__PURE__ */ __name(async (accessor) => {
499
- const confirmService = accessor.get(IConfirmService), localeService = accessor.get(LocaleService), messageService = accessor.get(IMessageService);
500
- if (!await confirmService.confirm({
501
- id: CONFIRM_REPLACE_ALL_ID,
502
- title: { title: localeService.t("find-replace.replace.confirm.title") },
503
- cancelText: localeService.t("button.cancel"),
504
- confirmText: localeService.t("button.confirm")
505
- }))
506
- return !1;
507
- const result = await accessor.get(IFindReplaceService).replaceAll(), { success, failure } = result;
508
- return failure > 0 ? (success === 0 ? messageService.show({
509
- type: MessageType.Error,
510
- content: localeService.t("find-replace.replace.all-failure")
511
- }) : messageService.show({
512
- type: MessageType.Warning,
513
- content: localeService.t("find-replace.replace.partial-success", `${success}`, `${failure}`)
514
- }), !1) : (messageService.show({
515
- type: MessageType.Success,
516
- content: localeService.t("find-replace.replace.all-success", `${success}`)
517
- }), !0);
518
- }, "handler")
519
- };
520
520
  function SearchInput(props) {
521
521
  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;
522
522
  return /* @__PURE__ */ jsxRuntimeExports.jsx(
@@ -880,7 +880,6 @@ let FindReplaceController = (_a3 = class extends RxDisposable {
880
880
  }
881
881
  }, __name(_a3, "FindReplaceController"), _a3);
882
882
  FindReplaceController = __decorateClass$1([
883
- OnLifecycle(LifecycleStages.Rendered, FindReplaceController),
884
883
  __decorateParam$1(0, IUniverInstanceService),
885
884
  __decorateParam$1(1, IMenuManagerService),
886
885
  __decorateParam$1(2, IShortcutService),
@@ -897,7 +896,6 @@ function getFindReplaceDialogDefaultPosition() {
897
896
  return { x: (innerWidth - FIND_REPLACE_PANEL_WIDTH) / 2 - FIND_REPLACE_PANEL_RIGHT_PADDING, y: FIND_REPLACE_PANEL_TOP_PADDING };
898
897
  }
899
898
  __name(getFindReplaceDialogDefaultPosition, "getFindReplaceDialogDefaultPosition");
900
- const PLUGIN_CONFIG_KEY = "find-replace.config", defaultPluginConfig = {};
901
899
  var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
902
900
  for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
903
901
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
@@ -915,11 +913,10 @@ let UniverFindReplacePlugin = (_a4 = class extends Plugin {
915
913
  [
916
914
  [FindReplaceController],
917
915
  [IFindReplaceService, { useClass: FindReplaceService }]
918
- ].forEach(
919
- (d) => {
920
- this._injector.add(d);
921
- }
922
- );
916
+ ].forEach((d) => this._injector.add(d));
917
+ }
918
+ onRendered() {
919
+ this._injector.get(FindReplaceController);
923
920
  }
924
921
  }, __name(_a4, "UniverFindReplacePlugin"), __publicField(_a4, "pluginName", PLUGIN_NAME), _a4);
925
922
  UniverFindReplacePlugin = __decorateClass([
@@ -0,0 +1,48 @@
1
+ {
2
+ "find-replace": {
3
+ "toolbar": "یافتن و جایگزینی",
4
+ "shortcut": {
5
+ "open-find-dialog": "باز کردن پنجره گفتگوی یافتن",
6
+ "open-replace-dialog": "باز کردن پنجره گفتگوی جایگزینی",
7
+ "close-dialog": "بستن پنجره گفتگوی یافتن و جایگزینی",
8
+ "go-to-next-match": "رفتن به تطابق بعدی",
9
+ "go-to-previous-match": "رفتن به تطابق قبلی"
10
+ },
11
+ "dialog": {
12
+ "title": "یافتن",
13
+ "find": "یافتن",
14
+ "replace": "جایگزینی",
15
+ "replace-all": "جایگزینی همه",
16
+ "case-sensitive": "حساس به حروف کوچک و بزرگ",
17
+ "find-placeholder": "یافتن در این برگ",
18
+ "advanced-finding": "جستجوی پیشرفته و جایگزینی",
19
+ "replace-placeholder": "ورود رشته جایگزین",
20
+ "match-the-whole-cell": "مطابقت با کل سلول",
21
+ "find-direction": {
22
+ "title": "جهت یافتن",
23
+ "row": "جستجو بر اساس سطر",
24
+ "column": "جستجو بر اساس ستون"
25
+ },
26
+ "find-scope": {
27
+ "title": "محدوده یافتن",
28
+ "current-sheet": "برگ فعلی",
29
+ "workbook": "کتاب کار"
30
+ },
31
+ "find-by": {
32
+ "title": "یافتن بر اساس",
33
+ "value": "یافتن بر اساس مقدار",
34
+ "formula": "یافتن فرمول"
35
+ },
36
+ "no-match": "یافتن تکمیل شد اما هیچ تطابقی یافت نشد.",
37
+ "no-result": "نتیجه‌ای وجود ندارد"
38
+ },
39
+ "replace": {
40
+ "all-success": "همه {0} تطابق جایگزین شد",
41
+ "all-failure": "جایگزینی ناموفق بود",
42
+ "confirm": {
43
+ "title": "آیا مطمئن هستید که همه تطابق‌ها را جایگزین کنید؟"
44
+ }
45
+ }
46
+ },
47
+ "find-replace-shortcuts": "یافتن و جایگزینی"
48
+ }
@@ -0,0 +1,3 @@
1
+ import { default as zhCN } from './zh-CN';
2
+ declare const locale: typeof zhCN;
3
+ export default locale;
@@ -1,5 +1,5 @@
1
- import { IConfigService, Plugin, Injector } from '@univerjs/core';
2
1
  import { IUniverFindReplaceConfig } from './controllers/config.schema';
2
+ import { IConfigService, Plugin, Injector } from '@univerjs/core';
3
3
  export declare class UniverFindReplacePlugin extends Plugin {
4
4
  private readonly _config;
5
5
  readonly _injector: Injector;
@@ -7,4 +7,5 @@ export declare class UniverFindReplacePlugin extends Plugin {
7
7
  static pluginName: string;
8
8
  constructor(_config: Partial<IUniverFindReplaceConfig> | undefined, _injector: Injector, _configService: IConfigService);
9
9
  onStarting(): void;
10
+ onRendered(): void;
10
11
  }
package/lib/umd/index.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(global,factory){typeof exports=="object"&&typeof module<"u"?factory(exports,require("@univerjs/core"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/engine-render"),require("react"),require("@univerjs/design")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/ui","rxjs","@univerjs/engine-render","react","@univerjs/design"],factory):(global=typeof globalThis<"u"?globalThis:global||self,factory(global.UniverFindReplace={},global.UniverCore,global.UniverUi,global.rxjs,global.UniverEngineRender,global.React,global.UniverDesign))})(this,function(exports2,core,ui,rxjs,engineRender,require$$0,design){"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;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(_a2){var key=_a2[0],value=_a2[1];typeof value=="string"&&(attrs[key]=value.replace(/url\(#(.*)\)/,"url(#$1".concat(runtimeProps.idSuffix,")")))})),attrs}__name(replaceRuntimeIdsAndExtInAttrs,"replaceRuntimeIdsAndExtInAttrs");function replaceRuntimeIdsInDefs(node,runtimeProps){var _a2,defIds=runtimeProps.defIds;return!defIds||defIds.length===0?node:node.tag==="defs"&&(!((_a2=node.children)===null||_a2===void 0)&&_a2.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");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 _a2;this._providers.forEach(provider=>provider.terminate()),this._findModels=[],this._matches=[],this._matchingModel=null,(_a2=this._currentSearchingDisposables)==null||_a2.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 _a2;const focusedUnitId=(_a2=this._univerInstanceService.getFocusedUnit())==null?void 0:_a2.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,FindReplaceService=(_b=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 _a2;return(_a2=this._model)==null?void 0:_a2.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 _a2;(_a2=this._model)==null||_a2.start()}terminate(){var _a2;(_a2=this._model)==null||_a2.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(_b,"FindReplaceService"),_b);FindReplaceService=__decorateClass$2([__decorateParam$2(0,core.Inject(core.Injector)),__decorateParam$2(1,core.IContextService)],FindReplaceService);const 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
+ (function(global,factory){typeof exports=="object"&&typeof module<"u"?factory(exports,require("@univerjs/core"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/design"),require("@univerjs/engine-render"),require("react")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/ui","rxjs","@univerjs/design","@univerjs/engine-render","react"],factory):(global=typeof globalThis<"u"?globalThis:global||self,factory(global.UniverFindReplace={},global.UniverCore,global.UniverUi,global.rxjs,global.UniverDesign,global.UniverEngineRender,global.React))})(this,function(exports2,core,ui,rxjs,design,engineRender,require$$0){"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="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(_a2){var key=_a2[0],value=_a2[1];typeof value=="string"&&(attrs[key]=value.replace(/url\(#(.*)\)/,"url(#$1".concat(runtimeProps.idSuffix,")")))})),attrs}__name(replaceRuntimeIdsAndExtInAttrs,"replaceRuntimeIdsAndExtInAttrs");function replaceRuntimeIdsInDefs(node,runtimeProps){var _a2,defIds=runtimeProps.defIds;return!defIds||defIds.length===0?node:node.tag==="defs"&&(!((_a2=node.children)===null||_a2===void 0)&&_a2.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");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 _a2;this._providers.forEach(provider=>provider.terminate()),this._findModels=[],this._matches=[],this._matchingModel=null,(_a2=this._currentSearchingDisposables)==null||_a2.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 _a2;const focusedUnitId=(_a2=this._univerInstanceService.getFocusedUnit())==null?void 0:_a2.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,FindReplaceService=(_b=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 _a2;return(_a2=this._model)==null?void 0:_a2.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 _a2;(_a2=this._model)==null||_a2.start()}terminate(){var _a2;(_a2=this._model)==null||_a2.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(_b,"FindReplaceService"),_b);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={};/**
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;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")};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 styles={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"};function useFindInputFocus(findReplaceService,ref){const focus=require$$0.useCallback(()=>{var _a2;(_a2=document.querySelector(".univer-find-input input"))==null||_a2.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 _a2;const focusSubscription=rxjs.fromEvent(document,"focusin").subscribe(event=>{var _a3;event.target&&((_a3=dialogContainerRef.current)!=null&&_a3.contains(event.target))?setDialogContainerFocus(!0):setDialogContainerFocus(!1),!focusRef.current||!focusRef.current.selectHasFocus()?setDialogInputFocus(!0):setDialogInputFocus(!1)});return(_a2=focusRef.current)==null||_a2.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;exports2.FindReplaceController=(_c=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 _a2;super.dispose(),(_a2=this._closingListenerDisposable)==null||_a2.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(_c,"FindReplaceController"),_c),exports2.FindReplaceController=__decorateClass$1([core.OnLifecycle(core.LifecycleStages.Rendered,exports2.FindReplaceController),__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))],exports2.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");const PLUGIN_CONFIG_KEY="find-replace.config",defaultPluginConfig={};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";exports2.UniverFindReplacePlugin=(_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.FindReplaceController],[IFindReplaceService,{useClass:FindReplaceService}]].forEach(d=>{this._injector.add(d)})}},__name(_d,"UniverFindReplacePlugin"),__publicField(_d,"pluginName",PLUGIN_NAME),_d),exports2.UniverFindReplacePlugin=__decorateClass([__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.IConfigService)],exports2.UniverFindReplacePlugin),exports2.FindBy=FindBy,exports2.FindDirection=FindDirection,exports2.FindModel=FindModel,exports2.FindScope=FindScope,exports2.GoToNextMatchOperation=GoToNextMatchOperation,exports2.GoToPreviousMatchOperation=GoToPreviousMatchOperation,exports2.IFindReplaceService=IFindReplaceService,exports2.OpenFindDialogOperation=OpenFindDialogOperation,exports2.OpenReplaceDialogOperation=OpenReplaceDialogOperation,exports2.ReplaceAllMatchesCommand=ReplaceAllMatchesCommand,exports2.ReplaceCurrentMatchCommand=ReplaceCurrentMatchCommand,Object.defineProperty(exports2,Symbol.toStringTag,{value:"Module"})});
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 styles={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"};function useFindInputFocus(findReplaceService,ref){const focus=require$$0.useCallback(()=>{var _a2;(_a2=document.querySelector(".univer-find-input input"))==null||_a2.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 _a2;const focusSubscription=rxjs.fromEvent(document,"focusin").subscribe(event=>{var _a3;event.target&&((_a3=dialogContainerRef.current)!=null&&_a3.contains(event.target))?setDialogContainerFocus(!0):setDialogContainerFocus(!1),!focusRef.current||!focusRef.current.selectHasFocus()?setDialogInputFocus(!0):setDialogInputFocus(!1)});return(_a2=focusRef.current)==null||_a2.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;exports2.FindReplaceController=(_c=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 _a2;super.dispose(),(_a2=this._closingListenerDisposable)==null||_a2.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(_c,"FindReplaceController"),_c),exports2.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))],exports2.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";exports2.UniverFindReplacePlugin=(_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.FindReplaceController],[IFindReplaceService,{useClass:FindReplaceService}]].forEach(d=>this._injector.add(d))}onRendered(){this._injector.get(exports2.FindReplaceController)}},__name(_d,"UniverFindReplacePlugin"),__publicField(_d,"pluginName",PLUGIN_NAME),_d),exports2.UniverFindReplacePlugin=__decorateClass([__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.IConfigService)],exports2.UniverFindReplacePlugin),exports2.FindBy=FindBy,exports2.FindDirection=FindDirection,exports2.FindModel=FindModel,exports2.FindScope=FindScope,exports2.GoToNextMatchOperation=GoToNextMatchOperation,exports2.GoToPreviousMatchOperation=GoToPreviousMatchOperation,exports2.IFindReplaceService=IFindReplaceService,exports2.OpenFindDialogOperation=OpenFindDialogOperation,exports2.OpenReplaceDialogOperation=OpenReplaceDialogOperation,exports2.ReplaceAllMatchesCommand=ReplaceAllMatchesCommand,exports2.ReplaceCurrentMatchCommand=ReplaceCurrentMatchCommand,Object.defineProperty(exports2,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/find-replace",
3
- "version": "0.3.0-alpha.1",
3
+ "version": "0.3.0-nightly.202410111606",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -49,27 +49,27 @@
49
49
  "peerDependencies": {
50
50
  "react": "^16.9.0 || ^17.0.0 || ^18.0.0",
51
51
  "rxjs": ">=7.0.0",
52
- "@univerjs/core": "0.3.0-alpha.1",
53
- "@univerjs/design": "0.3.0-alpha.1",
54
- "@univerjs/ui": "0.3.0-alpha.1",
55
- "@univerjs/engine-render": "0.3.0-alpha.1"
52
+ "@univerjs/core": "0.3.0-nightly.202410111606",
53
+ "@univerjs/design": "0.3.0-nightly.202410111606",
54
+ "@univerjs/ui": "0.3.0-nightly.202410111606",
55
+ "@univerjs/engine-render": "0.3.0-nightly.202410111606"
56
56
  },
57
57
  "dependencies": {
58
58
  "@univerjs/icons": "^0.1.78",
59
- "@univerjs/core": "0.3.0-alpha.1",
60
- "@univerjs/design": "0.3.0-alpha.1",
61
- "@univerjs/engine-render": "0.3.0-alpha.1",
62
- "@univerjs/ui": "0.3.0-alpha.1",
63
- "@univerjs/engine-formula": "0.3.0-alpha.1"
59
+ "@univerjs/core": "0.3.0-nightly.202410111606",
60
+ "@univerjs/design": "0.3.0-nightly.202410111606",
61
+ "@univerjs/ui": "0.3.0-nightly.202410111606",
62
+ "@univerjs/engine-formula": "0.3.0-nightly.202410111606",
63
+ "@univerjs/engine-render": "0.3.0-nightly.202410111606"
64
64
  },
65
65
  "devDependencies": {
66
66
  "less": "^4.2.0",
67
67
  "react": "18.3.1",
68
68
  "rxjs": "^7.8.1",
69
- "typescript": "^5.6.2",
69
+ "typescript": "^5.6.3",
70
70
  "vite": "^5.4.8",
71
- "vitest": "^2.1.1",
72
- "@univerjs-infra/shared": "0.3.0-alpha.1"
71
+ "vitest": "^2.1.2",
72
+ "@univerjs-infra/shared": "0.3.0"
73
73
  },
74
74
  "univerSpace": {
75
75
  ".": {
@@ -90,7 +90,6 @@
90
90
  "test:watch": "vitest",
91
91
  "coverage": "vitest run --coverage",
92
92
  "lint:types": "tsc --noEmit",
93
- "build": "tsc && vite build",
94
- "sync:cnpm": "cnpm sync"
93
+ "build": "tsc && vite build"
95
94
  }
96
95
  }
package/LICENSE DELETED
@@ -1,176 +0,0 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS