@univerjs/find-replace 0.2.5 → 0.2.7

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 Te=Object.defineProperty;var Oe=(i,e,n)=>e in i?Te(i,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[e]=n;var l=(i,e,n)=>Oe(i,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),u=require("@univerjs/ui"),g=require("rxjs"),Pe=require("@univerjs/engine-render"),c=require("react"),p=require("@univerjs/design");var S=function(){return S=Object.assign||function(i){for(var e,n=1,t=arguments.length;n<t;n++){e=arguments[n];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(i[r]=e[r])}return i},S.apply(this,arguments)},Ee=function(i,e){var n={};for(var t in i)Object.prototype.hasOwnProperty.call(i,t)&&e.indexOf(t)<0&&(n[t]=i[t]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,t=Object.getOwnPropertySymbols(i);r<t.length;r++)e.indexOf(t[r])<0&&Object.prototype.propertyIsEnumerable.call(i,t[r])&&(n[t[r]]=i[t[r]]);return n},Y=c.forwardRef(function(i,e){var n=i.icon,t=i.id,r=i.className,s=i.extend,a=Ee(i,["icon","id","className","extend"]),h="univerjs-icon univerjs-icon-".concat(t," ").concat(r||"").trim(),f=c.useRef("_".concat($e()));return Z(n,"".concat(t),{defIds:n.defIds,idSuffix:f.current},S({ref:e,className:h},a),s)});function Z(i,e,n,t,r){return c.createElement(i.tag,S(S({key:e},Ne(i,n,r)),t),(je(i,n).children||[]).map(function(s,a){return Z(s,"".concat(e,"-").concat(i.tag,"-").concat(a),n,void 0,r)}))}function Ne(i,e,n){var t=S({},i.attrs);n!=null&&n.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=n.colorChannel1);var r=e.defIds;return!r||r.length===0||(i.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+e.idSuffix),Object.entries(t).forEach(function(s){var a=s[0],h=s[1];typeof h=="string"&&(t[a]=h.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),t}function je(i,e){var n,t=e.defIds;return!t||t.length===0?i:i.tag==="defs"&&(!((n=i.children)===null||n===void 0)&&n.length)?S(S({},i),{children:i.children.map(function(r){return typeof r.attrs.id=="string"&&t&&t.indexOf(r.attrs.id)>-1?S(S({},r),{attrs:S(S({},r.attrs),{id:r.attrs.id+e.idSuffix})}):r})}):i}function $e(){return Math.random().toString(36).substring(2,8)}Y.displayName="UniverIcon";var Le={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_217_40",style:{maskType:"alpha"},width:17,height:17,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#D9D9D9",d:"M0.9 0.09H16.9V16.09H0.9z"}}]},{tag:"g",attrs:{mask:"url(#mask0_217_40)"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.39551 7.37266C2.39551 4.18105 4.98281 1.59375 8.17441 1.59375C11.366 1.59375 13.9533 4.18105 13.9533 7.37266C13.9533 8.72342 13.4898 9.96603 12.7133 10.95L15.1964 13.4331C15.4619 13.6986 15.4619 14.1291 15.1964 14.3946C14.9309 14.6601 14.5004 14.6601 14.2349 14.3946L11.7518 11.9115C10.7678 12.6881 9.52525 13.1516 8.17441 13.1516C4.98281 13.1516 2.39551 10.5642 2.39551 7.37266ZM8.17441 2.95349C5.73378 2.95349 3.75525 4.93202 3.75525 7.37266C3.75525 9.81333 5.73378 11.7918 8.17441 11.7918C10.6151 11.7918 12.5936 9.81333 12.5936 7.37266C12.5936 4.93202 10.6151 2.95349 8.17441 2.95349Z",fillRule:"evenodd",clipRule:"evenodd"}}]}]},J=c.forwardRef(function(i,e){return c.createElement(Y,Object.assign({},i,{id:"search-single-16",ref:e,icon:Le}))});J.displayName="SearchSingle16";const Q="FIND_REPLACE_INPUT_FOCUS",X="FIND_REPLACE_DIALOG_FOCUS",ee="FIND_REPLACE_REPLACE_REVEALED";var Ae=Object.defineProperty,we=Object.getOwnPropertyDescriptor,te=(i,e,n,t)=>{for(var r=t>1?void 0:t?we(e,n):e,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(t?a(e,n,r):a(r))||r);return t&&r&&Ae(e,n,r),r},A=(i,e)=>(n,t)=>e(n,t,i);class Ue extends o.Disposable{}const C=o.createIdentifier("find-replace.service");function Be(i){return typeof i.findString<"u"||typeof i.inputtingFindString<"u"||typeof i.findDirection<"u"||typeof i.matchesTheWholeCell<"u"||typeof i.caseSensitive<"u"||typeof i.findScope<"u"||typeof i.findBy<"u"}let w=class extends o.Disposable{constructor(e,n,t){super();l(this,"currentMatch$",new g.BehaviorSubject(null));l(this,"replaceables$",new g.BehaviorSubject([]));l(this,"_findModels",[]);l(this,"_matchingModel",null);l(this,"_matches",[]);l(this,"_currentSearchingDisposables",null);this._state=e,this._providers=n,this._univerInstanceService=t,this.disposeWithMe(this._state.stateUpdates$.pipe(g.throttleTime(200,void 0,{leading:!0,trailing:!0})).subscribe(async r=>{const s=this._state.state;Be(r)&&(s.findString!==""&&!s.replaceRevealed?(await this._startSearching(),this._state.changeState({findCompleted:!0})):r.replaceRevealed!==!0&&this._stopSearching())}))}get searched(){return this._findModels.length>0}dispose(){super.dispose(),this._stopSearching(),this.currentMatch$.complete(),this.replaceables$.complete(),this._state.changeState({...B(),revealed:!1})}async start(){if(!this._state.findString)return{results:[]};const e=await this._startSearching();return this._state.changeState({findCompleted:!0}),e}async _startSearching(){if(!this._state.findString)return{results:[]};const e=Array.from(this._providers),n=this._findModels=(await Promise.all(e.map(r=>r.find({findString:this._state.findString,findDirection:this._state.findDirection,findScope:this._state.findScope,findBy:this._state.findBy,replaceRevealed:this._state.replaceRevealed,caseSensitive:this._state.caseSensitive,matchesTheWholeCell:this._state.matchesTheWholeCell})))).flat();this._subscribeToModelsChanges(n);const t=this._matches=n.map(r=>r.getMatches()).flat();return this.replaceables$.next(t.filter(r=>r.replaceable)),t.length?(this._moveToInitialMatch(n),this._state.changeState({matchesCount:t.length}),{results:t}):(this._state.changeState({matchesCount:0,matchesPosition:0}),{results:[]})}_stopSearching(){var e;this._providers.forEach(n=>n.terminate()),this._findModels=[],this._matches=[],this._matchingModel=null,(e=this._currentSearchingDisposables)==null||e.dispose(),this._currentSearchingDisposables=null,this.currentMatch$.next(null),this.replaceables$.next([]),this._state.changeState({findCompleted:!1,matchesCount:0,matchesPosition:0})}_subscribeToModelsChanges(e){const n=this._currentSearchingDisposables=new o.DisposableCollection,t=g.combineLatest(e.map(r=>r.matchesUpdate$)).pipe(g.debounceTime(220)).subscribe(([...r])=>{const s=this._matches=r.flat();s.length?(this._moveToInitialMatch(this._findModels,!0),this._state.changeState({matchesCount:s.length}),this.replaceables$.next(s.filter(a=>a.replaceable))):(this._state.changeState({matchesCount:0,matchesPosition:0}),this.replaceables$.next([]))});e.forEach(r=>n.add(o.toDisposable(r.activelyChangingMatch$.subscribe(s=>{const a=this._matches.findIndex(h=>h===s);this._state.changeState({matchesPosition:a+1})})))),n.add(o.toDisposable(t))}async replace(){return this._matchingModel?this._matchingModel.replace(this._state.replaceString):!1}async replaceAll(){const e=await Promise.all(this._findModels.map(n=>n.replaceAll(this._state.replaceString))).then(n=>n.reduce((t,r)=>(t.success+=r.success,t.failure+=r.failure,t),{success:0,failure:0}));return e.failure===0&&this._stopSearching(),e}getCurrentMatch(){return this._state.matchesPosition>0?this._matches[this._state.matchesPosition-1]:null}_markMatch(e){const n=this._matches.findIndex(t=>t===e);this.currentMatch$.next(e),this._state.changeState({matchesPosition:n+1})}moveToNextMatch(){if(!this._matchingModel)return;const e=this._findModels.length===1,n=this._matchingModel.moveToNextMatch({loop:e});if(n)this._markMatch(n);else{const t=this._findModels.findIndex(r=>r===this._matchingModel);this._moveToNextUnitMatch(t)}}_moveToNextUnitMatch(e){const n=this._findModels.length;for(let t=(e+1)%n;t!==e;){const r=this._findModels[t],s=r.moveToNextMatch({ignoreSelection:!0});if(s){this._matchingModel=r,this._markMatch(s);return}t=(t+1)%n}if(this._matchingModel){const t=this._matchingModel.moveToNextMatch({ignoreSelection:!0});t&&this._markMatch(t)}}moveToPreviousMatch(){if(!this._matchingModel)return;const e=this._findModels.length===1,n=this._matchingModel.moveToPreviousMatch({loop:e});if(n){const t=this._matches.findIndex(r=>r===n);this.currentMatch$.next(n),this._state.changeState({matchesPosition:t+1})}else{const t=this._findModels.length,r=this._findModels.findIndex(a=>a===this._matchingModel);for(let a=(r-1+t)%t;a!==r;){const h=this._findModels[a],f=h.moveToPreviousMatch({ignoreSelection:!0});if(f){this._matchingModel=h,this._markMatch(f);return}a=(a-1)%t}const s=this._matchingModel.moveToPreviousMatch({ignoreSelection:!0});s&&this._markMatch(s)}}_moveToInitialMatch(e,n=!1){var s;const t=(s=this._univerInstanceService.getFocusedUnit())==null?void 0:s.getUnitId();if(!t)return-1;const r=e.findIndex(a=>a.unitId===t);if(r!==-1){this._matchingModel=e[r];const a=this._matchingModel.moveToNextMatch({stayIfOnMatch:!0,noFocus:n});if(a)return this._markMatch(a),r}return this._moveToNextUnitMatch(r),0}};w=te([A(2,o.IUniverInstanceService)],w);var D=(i=>(i.ROW="row",i.COLUMN="column",i))(D||{}),T=(i=>(i.VALUE="value",i.FORMULA="formula",i))(T||{}),O=(i=>(i.SUBUNIT="subunit",i.UNIT="unit",i))(O||{});function B(){return{caseSensitive:!1,findBy:"value",findCompleted:!1,findDirection:"row",findScope:"subunit",findString:"",inputtingFindString:"",matchesCount:0,matchesPosition:0,matchesTheWholeCell:!1,replaceRevealed:!1,replaceString:"",revealed:!0}}class ke{constructor(){l(this,"_stateUpdates$",new g.Subject);l(this,"stateUpdates$",this._stateUpdates$.asObservable());l(this,"_state$",new g.BehaviorSubject(B()));l(this,"state$",this._state$.asObservable());l(this,"_findString","");l(this,"_inputtingFindString","");l(this,"_replaceString","");l(this,"_revealed",!1);l(this,"_replaceRevealed",!1);l(this,"_matchesPosition",0);l(this,"_matchesCount",0);l(this,"_caseSensitive",!0);l(this,"_matchesTheWholeCell",!1);l(this,"_findDirection","row");l(this,"_findScope","subunit");l(this,"_findBy","value");l(this,"_findCompleted",!1)}get state(){return this._state$.getValue()}get inputtingFindString(){return this._inputtingFindString}get findString(){return this._findString}get revealed(){return this._revealed}get replaceRevealed(){return this._replaceRevealed}get matchesPosition(){return this._matchesPosition}get matchesCount(){return this._matchesCount}get replaceString(){return this._replaceString}get caseSensitive(){return this._caseSensitive}get matchesTheWholeCell(){return this._matchesTheWholeCell}get findDirection(){return this._findDirection}get findScope(){return this._findScope}get findBy(){return this._findBy}get findCompleted(){return this._findCompleted}changeState(e){let n=!1;const t={};typeof e.findString<"u"&&e.findString!==this._findString&&(this._findString=e.findString,t.findString=this._findString,n=!0),typeof e.revealed<"u"&&e.revealed!==this._revealed&&(this._revealed=e.revealed,t.revealed=e.revealed,n=!0),typeof e.replaceRevealed<"u"&&e.replaceRevealed!==this._replaceRevealed&&(this._replaceRevealed=e.replaceRevealed,t.replaceRevealed=e.replaceRevealed,n=!0),typeof e.replaceString<"u"&&e.replaceString!==this._replaceString&&(this._replaceString=e.replaceString,t.replaceString=e.replaceString,n=!0),typeof e.matchesCount<"u"&&e.matchesCount!==this._matchesCount&&(this._matchesCount=e.matchesCount,t.matchesCount=e.matchesCount,n=!0),typeof e.matchesPosition<"u"&&e.matchesPosition!==this._matchesPosition&&(this._matchesPosition=e.matchesPosition,t.matchesPosition=e.matchesPosition,n=!0),typeof e.findBy<"u"&&e.findBy!==this._findBy&&(this._findBy=e.findBy,t.findBy=e.findBy,n=!0),typeof e.findScope<"u"&&e.findScope!==this._findScope&&(this._findScope=e.findScope,t.findScope=e.findScope,n=!0),typeof e.findDirection<"u"&&e.findDirection!==this._findDirection&&(this._findDirection=e.findDirection,t.findDirection=e.findDirection,n=!0),typeof e.caseSensitive<"u"&&e.caseSensitive!==this._caseSensitive&&(this._caseSensitive=e.caseSensitive,t.caseSensitive=e.caseSensitive,n=!0),typeof e.matchesTheWholeCell<"u"&&e.matchesTheWholeCell!==this._matchesTheWholeCell&&(this._matchesTheWholeCell=e.matchesTheWholeCell,t.matchesTheWholeCell=e.matchesTheWholeCell,n=!0),typeof e.inputtingFindString<"u"&&e.inputtingFindString!==this._inputtingFindString&&(this._inputtingFindString=e.inputtingFindString,t.inputtingFindString=e.inputtingFindString,n=!0),typeof e.findCompleted<"u"&&e.findCompleted!==this._findCompleted&&(this._findCompleted=e.findCompleted,t.findCompleted=e.findCompleted,n=!0),n&&(this._state$.next({caseSensitive:this._caseSensitive,findBy:this._findBy,findCompleted:this._findCompleted,findDirection:this._findDirection,findScope:this._findScope,findString:this._findString,inputtingFindString:this._inputtingFindString,matchesCount:this._matchesCount,matchesPosition:this._matchesPosition,matchesTheWholeCell:this._matchesTheWholeCell,replaceRevealed:this._replaceRevealed,revealed:this._revealed}),this._stateUpdates$.next(t))}}let U=class extends o.Disposable{constructor(e,n){super();l(this,"_providers",new Set);l(this,"_state",new ke);l(this,"_model");l(this,"_currentMatch$",new g.BehaviorSubject(null));l(this,"currentMatch$",this._currentMatch$.asObservable());l(this,"_replaceables$",new g.BehaviorSubject([]));l(this,"replaceables$",this._replaceables$.asObservable());l(this,"_focusSignal$",new g.Subject);l(this,"focusSignal$",this._focusSignal$.asObservable());this._injector=e,this._contextService=n}get stateUpdates$(){return this._state.stateUpdates$}get state$(){return this._state.state$}get revealed(){return this._state.revealed}get replaceRevealed(){return this._state.replaceRevealed}dispose(){super.dispose(),this._currentMatch$.next(null),this._currentMatch$.complete(),this._replaceables$.next([]),this._replaceables$.complete(),this._focusSignal$.complete()}getCurrentMatch(){var e;return(e=this._model)==null?void 0:e.getCurrentMatch()}getFindString(){return this._state.findString}changeFindString(e){this._state.changeState({findString:e})}focusFindInput(){this._focusSignal$.next()}changeInputtingFindString(e){e?this._state.changeState({inputtingFindString:e}):this._state.changeState({inputtingFindString:"",findString:""})}changeReplaceString(e){this._state.changeState({replaceString:e})}changeMatchesTheWholeCell(e){this._state.changeState({matchesTheWholeCell:e})}changeCaseSensitive(e){this._state.changeState({caseSensitive:e})}changeFindBy(e){this._state.changeState({findBy:e}),this._toggleDisplayRawFormula(e==="formula")}changeFindScope(e){this._state.changeState({findScope:e})}changeFindDirection(e){this._state.changeState({findDirection:e})}moveToNextMatch(){this._model&&(this._state.replaceRevealed&&!this._model.searched?(this._state.changeState({findString:this._state.inputtingFindString}),this._model.start()):this._model.moveToNextMatch(),this._focusSignal$.next())}moveToPreviousMatch(){this._model&&(this._state.replaceRevealed&&!this._model.searched?(this._state.changeState({findString:this._state.inputtingFindString}),this._model.start()):this._model.moveToPreviousMatch(),this._focusSignal$.next())}async replace(){return this._model?this._model.replace():!1}async replaceAll(){if(!this._model)throw new Error("[FindReplaceService] replaceAll: model is not initialized!");return this._model.replaceAll()}revealReplace(){this._state.changeState({replaceRevealed:!0,inputtingFindString:this._state.findString}),this._toggleRevealReplace(!0)}start(e=!1){if(this._providers.size===0)return!1;this._model=this._injector.createInstance(w,this._state,this._providers),this._model.currentMatch$.subscribe(t=>this._currentMatch$.next(t)),this._model.replaceables$.subscribe(t=>this._replaceables$.next(t));const n=B();return e&&(n.replaceRevealed=!0),this._state.changeState(n),this._toggleRevealReplace(e),!0}find(){var e;(e=this._model)==null||e.start()}terminate(){var e;(e=this._model)==null||e.dispose(),this._model=null,this._toggleDisplayRawFormula(!1),this._toggleRevealReplace(!1)}registerFindReplaceProvider(e){return this._providers.add(e),o.toDisposable(()=>this._providers.delete(e))}_toggleRevealReplace(e){this._contextService.setContextValue(ee,e)}_toggleDisplayRawFormula(e){this._contextService.setContextValue(Pe.RENDER_RAW_FORMULA_KEY,e)}};U=te([A(0,o.Inject(o.Injector)),A(1,o.IContextService)],U);const y={id:"ui.operation.open-find-dialog",type:o.CommandType.OPERATION,handler:i=>{const e=i.get(C);return e.revealed?e.focusFindInput():e.start(),!0}},E={id:"ui.operation.open-replace-dialog",type:o.CommandType.OPERATION,handler:i=>{const e=i.get(C);return e.revealed?e.replaceRevealed?e.focusFindInput():e.revealReplace():e.start(!0),!0}},k={type:o.CommandType.OPERATION,id:"ui.operation.go-to-next-match",handler:i=>(i.get(C).moveToNextMatch(),!0)},W={type:o.CommandType.OPERATION,id:"ui.operation.go-to-previous-match",handler:i=>(i.get(C).moveToPreviousMatch(),!0)};var ie={exports:{}},N={};/**
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={};/**
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 We=c,Ge=Symbol.for("react.element"),Ve=Symbol.for("react.fragment"),He=Object.prototype.hasOwnProperty,Ke=We.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,qe={key:!0,ref:!0,__self:!0,__source:!0};function ne(i,e,n){var t,r={},s=null,a=null;n!==void 0&&(s=""+n),e.key!==void 0&&(s=""+e.key),e.ref!==void 0&&(a=e.ref);for(t in e)He.call(e,t)&&!qe.hasOwnProperty(t)&&(r[t]=e[t]);if(i&&i.defaultProps)for(t in e=i.defaultProps,e)r[t]===void 0&&(r[t]=e[t]);return{$$typeof:Ge,type:i,key:s,ref:a,props:r,_owner:Ke.current}}N.Fragment=Ve;N.jsx=ne;N.jsxs=ne;ie.exports=N;var d=ie.exports;const G={id:"ui.command.replace-current-match",type:o.CommandType.COMMAND,handler:i=>i.get(C).replace()},ze="CONFIRM_REPLACE_ALL",V={id:"ui.command.replace-all-matches",type:o.CommandType.COMMAND,handler:async i=>{const e=i.get(u.IConfirmService),n=i.get(o.LocaleService),t=i.get(u.IMessageService);if(!await e.confirm({id:ze,title:{title:n.t("find-replace.replace.confirm.title")},cancelText:n.t("button.cancel"),confirmText:n.t("button.confirm")}))return!1;const s=await i.get(C).replaceAll(),{success:a,failure:h}=s;return h>0?(a===0?t.show({type:p.MessageType.Error,content:n.t("find-replace.replace.all-failure")}):t.show({type:p.MessageType.Warning,content:n.t("find-replace.replace.partial-success",`${a}`,`${h}`)}),!1):(t.show({type:p.MessageType.Success,content:n.t("find-replace.replace.all-success",`${a}`)}),!0)}};function re(i){const{findCompleted:e,localeService:n,matchesCount:t,matchesPosition:r,findString:s,findReplaceService:a,onChange:h,...f}=i,v=e&&t===0?n.t("find-replace.dialog.no-result"):t===0?" ":void 0;return d.jsx(p.InputWithSlot,{autoFocus:!0,placeholder:n.t("find-replace.dialog.find-placeholder"),slot:d.jsx(p.Pager,{loop:!0,text:v,value:r,total:t,onChange:m=>{r===t&&m===1?a.moveToNextMatch():r===1&&m===t||m<r?a.moveToPreviousMatch():a.moveToNextMatch()}}),value:s,onChange:m=>h==null?void 0:h(m),...f})}const Ye="univer-find-replace-dialog-container",Ze="univer-find-replace-expand-container",Je="univer-button-text",Qe="univer-find-replace-buttons-group",Xe="univer-find-replace-buttons-group-right",P={findReplaceDialogContainer:Ye,findReplaceExpandContainer:Ze,buttonText:Je,findReplaceButtonsGroup:Qe,findReplaceButtonsGroupRight:Xe};function se(i,e){const n=c.useCallback(()=>{var r;(r=document.querySelector(".univer-find-input input"))==null||r.focus()},[]),t=c.useCallback(()=>{const r=document.querySelectorAll(".univer-find-replace-dialog-container .univer-select-selection-search-input");return Array.from(r).some(s=>s===document.activeElement)},[]);return c.useImperativeHandle(e,()=>({focus:n,selectHasFocus:t})),c.useEffect(()=>{const r=i.focusSignal$.subscribe(()=>n());return()=>r.unsubscribe()},[i,n]),{focus:n,selectHasFocus:t}}const et=c.forwardRef(function(e,n){const t=o.useDependency(o.LocaleService),r=o.useDependency(C),s=o.useDependency(o.ICommandService),a=u.useObservable(r.state$,void 0,!0),{findCompleted:h,findString:f,matchesCount:b,matchesPosition:v}=a,m=c.useCallback(()=>{s.executeCommand(E.id)},[s]),x=c.useCallback(M=>r.changeFindString(M),[r]);return se(r,n),d.jsxs(c.Fragment,{children:[d.jsx(re,{findCompleted:h,className:"univer-find-input",matchesCount:b,matchesPosition:v,findReplaceService:r,localeService:t,findString:f,onChange:x}),d.jsx("div",{className:P.findReplaceExpandContainer,children:d.jsx(p.Button,{type:"text",size:"small",onClick:m,children:t.t("find-replace.dialog.advanced-finding")})})]})}),tt=c.forwardRef(function(e,n){const t=o.useDependency(C),r=o.useDependency(o.LocaleService),s=o.useDependency(o.ICommandService),a=o.useDependency(u.IMessageService),h=u.useObservable(t.currentMatch$,void 0,!0),f=u.useObservable(t.replaceables$,void 0,!0),b=u.useObservable(t.state$,void 0,!0),{matchesCount:v,matchesPosition:m,findString:x,inputtingFindString:M,replaceString:ce,caseSensitive:le,matchesTheWholeCell:de,findDirection:ue,findScope:he,findBy:pe,findCompleted:$}=b,fe=M.length===0,_e=v===0||!(h!=null&&h.replaceable),ge=f.length===0,me=c.useCallback(_=>t.changeInputtingFindString(_),[t]),ve=c.useCallback(_=>t.changeReplaceString(_),[t]),{focus:Se}=se(t,n),Ce=c.useCallback(()=>{x===M?t.moveToNextMatch():(t.changeFindString(M),t.find())},[x,M,t]),Re=c.useCallback(()=>s.executeCommand(G.id),[s]),be=c.useCallback(async()=>{await s.executeCommand(V.id),Se()},[s]),Me=c.useCallback(_=>{t.changeFindDirection(_)},[t]),ye=c.useCallback(_=>{t.changeFindScope(_)},[t]),Ie=c.useCallback(_=>{t.changeFindBy(_)},[t]),xe=nt(r),Fe=rt(r),De=st(r);return c.useEffect(()=>{const _=$&&v===0;let F=null;return _&&(F=a.show({content:r.t("find-replace.dialog.no-match"),type:p.MessageType.Warning,duration:5e3})),()=>F==null?void 0:F.dispose()},[$,v,a,r]),d.jsxs(c.Fragment,{children:[d.jsx(p.FormLayout,{label:r.t("find-replace.dialog.find"),children:d.jsx(re,{findCompleted:$,className:"univer-find-input",matchesCount:v,matchesPosition:m,findReplaceService:t,localeService:r,findString:M,onChange:me})}),d.jsx(p.FormLayout,{label:r.t("find-replace.dialog.replace"),children:d.jsx(p.Input,{placeholder:r.t("find-replace.dialog.replace-placeholder"),value:ce,onChange:_=>ve(_)})}),d.jsx(p.FormLayout,{label:r.t("find-replace.dialog.find-direction.title"),children:d.jsx(p.Select,{value:ue,options:Fe,onChange:Me})}),d.jsx(p.FormDualColumnLayout,{children:d.jsxs(c.Fragment,{children:[d.jsx(p.FormLayout,{label:r.t("find-replace.dialog.find-scope.title"),children:d.jsx(p.Select,{value:he,options:xe,onChange:ye})}),d.jsx(p.FormLayout,{label:r.t("find-replace.dialog.find-by.title"),children:d.jsx(p.Select,{value:pe,options:De,onChange:Ie})})]})}),d.jsx(p.FormDualColumnLayout,{children:d.jsxs(c.Fragment,{children:[d.jsx(p.FormLayout,{children:d.jsx(p.Checkbox,{checked:le,onChange:_=>{t.changeCaseSensitive(_)},children:r.t("find-replace.dialog.case-sensitive")})}),d.jsx(p.FormLayout,{children:d.jsx(p.Checkbox,{checked:de,onChange:_=>{t.changeMatchesTheWholeCell(_)},children:r.t("find-replace.dialog.match-the-whole-cell")})})]})}),d.jsxs("div",{className:P.findReplaceButtonsGroup,children:[d.jsx(p.Button,{type:"primary",onClick:Ce,disabled:fe,children:r.t("find-replace.dialog.find")}),d.jsxs("span",{className:P.findReplaceButtonsGroupRight,children:[d.jsx(p.Button,{disabled:_e,onClick:Re,children:r.t("find-replace.dialog.replace")}),d.jsx(p.Button,{disabled:ge,onClick:be,children:r.t("find-replace.dialog.replace-all")})]})]})]})});function it(){const i=o.useDependency(C),e=o.useDependency(u.ILayoutService),n=o.useDependency(o.IContextService),t=u.useObservable(i.state$,void 0,!0),r=c.useRef(null);c.useEffect(()=>{let f;return r.current&&(f=e.registerContainerElement(r.current)),()=>f==null?void 0:f.dispose()},[e]);const s=c.useRef(null),a=c.useCallback(f=>n.setContextValue(X,f),[n]),h=c.useCallback(f=>n.setContextValue(Q,f),[n]);return c.useEffect(()=>{var b;const f=g.fromEvent(document,"focusin").subscribe(v=>{var m;v.target&&((m=r.current)!=null&&m.contains(v.target))?a(!0):a(!1),!s.current||!s.current.selectHasFocus()?h(!0):h(!1)});return(b=s.current)==null||b.focus(),a(!0),h(!0),()=>{f.unsubscribe(),a(!1)}},[a,h]),d.jsx("div",{className:P.findReplaceDialogContainer,ref:r,children:t.replaceRevealed?d.jsx(tt,{ref:s}):d.jsx(et,{ref:s})})}function nt(i){const e=i.getCurrentLocale();return c.useMemo(()=>[{label:i.t("find-replace.dialog.find-scope.current-sheet"),value:O.SUBUNIT},{label:i.t("find-replace.dialog.find-scope.workbook"),value:O.UNIT}],[e])}function rt(i){const e=i.getCurrentLocale();return c.useMemo(()=>[{label:i.t("find-replace.dialog.find-direction.row"),value:D.ROW},{label:i.t("find-replace.dialog.find-direction.column"),value:D.COLUMN}],[e])}function st(i){const e=i.getCurrentLocale();return c.useMemo(()=>[{label:i.t("find-replace.dialog.find-by.value"),value:T.VALUE},{label:i.t("find-replace.dialog.find-by.formula"),value:T.FORMULA}],[e])}function I(i){return i.getContextValue(X)}function at(i){return i.getContextValue(ee)}function ae(i){return i.getContextValue(Q)}const j="7_find-replace-shortcuts";function H(i){return i.getContextValue(o.FOCUSING_SHEET)}function K(i){return!i.getContextValue(o.EDITOR_ACTIVATED)}const ot={id:y.id,description:"find-replace.shortcut.open-find-dialog",binding:u.KeyCode.F|u.MetaKeys.CTRL_COMMAND,group:j,preconditions(i){return!I(i)&&H(i)&&K(i)}},ct={id:y.id,description:"find-replace.shortcut.open-find-dialog",binding:u.KeyCode.F|u.MetaKeys.CTRL_COMMAND,mac:u.KeyCode.F|u.MetaKeys.MAC_CTRL,preconditions(i){return!I(i)&&H(i)&&K(i)}},lt={id:E.id,description:"find-replace.shortcut.open-replace-dialog",binding:u.KeyCode.H|u.MetaKeys.CTRL_COMMAND,mac:u.KeyCode.H|u.MetaKeys.MAC_CTRL,group:j,preconditions(i){return H(i)&&K(i)&&(!I(i)||!at(i))}},dt={id:k.id,description:"find-replace.shortcut.go-to-next-match",binding:u.KeyCode.ENTER,group:j,priority:1e3,preconditions(i){return ae(i)&&I(i)}},ut={id:W.id,description:"find-replace.shortcut.go-to-previous-match",binding:u.KeyCode.ENTER|u.MetaKeys.SHIFT,group:j,priority:1e3,preconditions(i){return ae(i)&&I(i)}};function ht(i){const e=i.get(o.IContextService);return{id:y.id,icon:"SearchIcon",tooltip:"find-replace.toolbar",group:u.MenuGroup.TOOLBAR_OTHERS,type:u.MenuItemType.BUTTON,positions:[u.MenuPosition.TOOLBAR_START],hidden$:u.getMenuHiddenObservable(i,o.UniverInstanceType.UNIVER_SHEET),disabled$:g.combineLatest([e.subscribeContextValue$(o.EDITOR_ACTIVATED),e.subscribeContextValue$(o.FOCUSING_SHEET)]).pipe(g.map(([n,t])=>n||!t))}}var pt=Object.defineProperty,ft=Object.getOwnPropertyDescriptor,_t=(i,e,n,t)=>{for(var r=t>1?void 0:t?ft(e,n):e,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(t?a(e,n,r):a(r))||r);return t&&r&&pt(e,n,r),r},R=(i,e)=>(n,t)=>e(n,t,i);const gt={},q="DESKTOP_FIND_REPLACE_DIALOG",oe=350,mt=20,vt=-90;exports.FindReplaceController=class extends o.RxDisposable{constructor(e,n,t,r,s,a,h,f,b,v,m){super(),this._config=e,this._univerInstanceService=n,this._menuService=t,this._shortcutService=r,this._commandService=s,this._findReplaceService=a,this._dialogService=h,this._layoutService=f,this._localeService=b,this._componentManager=v,this._injector=m,this._initCommands(),this._initUI(),this._initShortcuts()}_initCommands(){[y,E,k,W,V,G].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initShortcuts(){[lt,ot,ct,ut,dt].forEach(e=>this.disposeWithMe(this._shortcutService.registerShortcut(e)))}_initUI(){const{menu:e={}}=this._config;this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(ht),e)),this.disposeWithMe(this._componentManager.register("FindReplaceDialog",it)),this.disposeWithMe(this._componentManager.register("SearchIcon",J)),this._findReplaceService.stateUpdates$.pipe(g.takeUntil(this.dispose$)).subscribe(n=>{n.revealed===!0&&this._openPanel()}),this.disposeWithMe(this._univerInstanceService.focused$.pipe(g.takeUntil(this.dispose$)).subscribe(n=>{(!n||!this._univerInstanceService.getUniverSheetInstance(n))&&this.closePanel()}))}_openPanel(){this._dialogService.open({id:q,draggable:!0,width:oe,title:{title:this._localeService.t("find-replace.dialog.title")},children:{label:"FindReplaceDialog"},destroyOnClose:!0,defaultPosition:St(),preservePositionOnDestroy:!0,onClose:()=>this.closePanel()})}closePanel(){this._dialogService.close(q),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus())}};exports.FindReplaceController=_t([o.OnLifecycle(o.LifecycleStages.Rendered,exports.FindReplaceController),R(1,o.IUniverInstanceService),R(2,u.IMenuService),R(3,u.IShortcutService),R(4,o.ICommandService),R(5,C),R(6,u.IDialogService),R(7,u.ILayoutService),R(8,o.Inject(o.LocaleService)),R(9,o.Inject(u.ComponentManager)),R(10,o.Inject(o.Injector))],exports.FindReplaceController);function St(){const{innerWidth:i}=window;return{x:(i-oe)/2-mt,y:vt}}var Ct=Object.defineProperty,Rt=Object.getOwnPropertyDescriptor,bt=(i,e,n,t)=>{for(var r=t>1?void 0:t?Rt(e,n):e,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(t?a(e,n,r):a(r))||r);return t&&r&&Ct(e,n,r),r},z=(i,e)=>(n,t)=>e(n,t,i);const Mt="FIND_REPLACE_PLUGIN";var L;exports.UniverFindReplacePlugin=(L=class extends o.Plugin{constructor(e={},n,t){super(),this._config=e,this._injector=n,this._localeService=t,this._config=o.Tools.deepMerge({},gt,this._config)}onStarting(e){[[exports.FindReplaceController,{useFactory:()=>this._injector.createInstance(exports.FindReplaceController,this._config)}],[C,{useClass:U}]].forEach(n=>{e.add(n)})}},l(L,"pluginName",Mt),L);exports.UniverFindReplacePlugin=bt([z(1,o.Inject(o.Injector)),z(2,o.Inject(o.LocaleService))],exports.UniverFindReplacePlugin);exports.FindBy=T;exports.FindDirection=D;exports.FindModel=Ue;exports.FindScope=O;exports.GoToNextMatchOperation=k;exports.GoToPreviousMatchOperation=W;exports.IFindReplaceService=C;exports.OpenFindDialogOperation=y;exports.OpenReplaceDialogOperation=E;exports.ReplaceAllMatchesCommand=V;exports.ReplaceCurrentMatchCommand=G;
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",group:ui.MenuGroup.TOOLBAR_OTHERS,type:ui.MenuItemType.BUTTON,positions:[ui.MenuPosition.TOOLBAR_START],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");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 DefaultFindReplaceConfig={},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(_config,_univerInstanceService,_menuService,_shortcutService,_commandService,_findReplaceService,_dialogService,_layoutService,_localeService,_componentManager,_injector){super();__publicField(this,"_closingListenerDisposable");this._config=_config,this._univerInstanceService=_univerInstanceService,this._menuService=_menuService,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(){const{menu={}}=this._config;this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(FindReplaceMenuItemFactory),menu)),this.disposeWithMe(this._componentManager.register("FindReplaceDialog",FindReplaceDialog)),this.disposeWithMe(this._componentManager.register("SearchIcon",SearchSingle16)),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(1,core.IUniverInstanceService),__decorateParam$1(2,ui.IMenuService),__decorateParam$1(3,ui.IShortcutService),__decorateParam$1(4,core.ICommandService),__decorateParam$1(5,IFindReplaceService),__decorateParam$1(6,ui.IDialogService),__decorateParam$1(7,ui.ILayoutService),__decorateParam$1(8,core.Inject(core.LocaleService)),__decorateParam$1(9,core.Inject(ui.ComponentManager)),__decorateParam$1(10,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="FIND_REPLACE_PLUGIN";var _a4;exports.UniverFindReplacePlugin=(_a4=class extends core.Plugin{constructor(_config={},_injector,_localeService){super(),this._config=_config,this._injector=_injector,this._localeService=_localeService,this._config=core.Tools.deepMerge({},DefaultFindReplaceConfig,this._config)}onStarting(){[[exports.FindReplaceController,{useFactory:__name(()=>this._injector.createInstance(exports.FindReplaceController,this._config),"useFactory")}],[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.Inject(core.LocaleService))],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;