@univerjs/find-replace 0.1.5 → 0.1.6

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 Oe=Object.defineProperty;var Pe=(t,e,n)=>e in t?Oe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var d=(t,e,n)=>(Pe(t,typeof e!="symbol"?e+"":e,n),n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@univerjs/core"),M=require("@wendellhu/redi"),h=require("@univerjs/ui"),S=require("rxjs"),Te=require("@univerjs/engine-render"),l=require("react"),p=require("@univerjs/design"),y=require("@wendellhu/redi/react-bindings");var R=function(){return R=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++){e=arguments[n];for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=e[s])}return t},R.apply(this,arguments)},Ee=function(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,i=Object.getOwnPropertySymbols(t);s<i.length;s++)e.indexOf(i[s])<0&&Object.prototype.propertyIsEnumerable.call(t,i[s])&&(n[i[s]]=t[i[s]]);return n},H=l.forwardRef(function(t,e){var n=t.icon,i=t.id,s=t.className,r=t.extend,a=Ee(t,["icon","id","className","extend"]),o="univerjs-icon univerjs-icon-".concat(i," ").concat(s||"").trim(),f=l.useRef("_".concat(je()));return K(n,"".concat(i),{defIds:n.defIds,idSuffix:f.current},R({ref:e,className:o},a),r)});function K(t,e,n,i,s){return l.createElement(t.tag,R(R({key:e},$e(t,n,s)),i),(Ne(t,n).children||[]).map(function(r,a){return K(r,"".concat(e,"-").concat(t.tag,"-").concat(a),n,void 0,s)}))}function $e(t,e,n){var i=R({},t.attrs);n!=null&&n.colorChannel1&&i.fill==="colorChannel1"&&(i.fill=n.colorChannel1);var s=e.defIds;return!s||s.length===0||(t.tag==="use"&&i["xlink:href"]&&(i["xlink:href"]=i["xlink:href"]+e.idSuffix),Object.entries(i).forEach(function(r){var a=r[0],o=r[1];typeof o=="string"&&(i[a]=o.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),i}function Ne(t,e){var n,i=e.defIds;return!i||i.length===0?t:t.tag==="defs"&&(!((n=t.children)===null||n===void 0)&&n.length)?R(R({},t),{children:t.children.map(function(s){return typeof s.attrs.id=="string"&&i&&i.indexOf(s.attrs.id)>-1?R(R({},s),{attrs:R(R({},s.attrs),{id:s.attrs.id+e.idSuffix})}):s})}):t}function je(){return Math.random().toString(36).substring(2,8)}H.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"}}]}]},q=l.forwardRef(function(t,e){return l.createElement(H,Object.assign({},t,{id:"search-single-16",ref:e,icon:Le}))});q.displayName="SearchSingle16";const z="FIND_REPLACE_INPUT_FOCUS",Y="FIND_REPLACE_DIALOG_FOCUS",Z="FIND_REPLACE_REPLACE_REVEALED";var Ae=Object.defineProperty,we=Object.getOwnPropertyDescriptor,J=(t,e,n,i)=>{for(var s=i>1?void 0:i?we(e,n):e,r=t.length-1,a;r>=0;r--)(a=t[r])&&(s=(i?a(e,n,s):a(s))||s);return i&&s&&Ae(e,n,s),s},O=(t,e)=>(n,i)=>e(n,i,t);class Ue extends c.Disposable{}const b=M.createIdentifier("find-replace.service");function Be(t){return typeof t.findString<"u"||typeof t.inputtingFindString<"u"||typeof t.findDirection<"u"||typeof t.matchesTheWholeCell<"u"||typeof t.caseSensitive<"u"||typeof t.findScope<"u"||typeof t.findBy<"u"}let w=class extends c.Disposable{constructor(e,n,i,s){super();d(this,"currentMatch$",new S.BehaviorSubject(null));d(this,"replaceables$",new S.BehaviorSubject([]));d(this,"_findModels",[]);d(this,"_matchingModel",null);d(this,"_matches",[]);d(this,"_currentSearchingDisposables",null);this._state=e,this._providers=n,this._univerInstanceService=i,this._logService=s,this.disposeWithMe(this._state.stateUpdates$.pipe(S.throttleTime(200,void 0,{leading:!0,trailing:!0})).subscribe(async r=>{const a=this._state.state;Be(r)&&(a.findString!==""&&!a.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 i=this._matches=n.map(r=>r.getMatches()).flat();if(this.replaceables$.next(i.filter(r=>r.replaceable)),!i.length)return this._state.changeState({matchesCount:0,matchesPosition:0}),{results:[]};const s=this._moveToInitialMatch(n,i);return this._state.changeState({matchesCount:i.length,matchesPosition:s+1}),{results:i}}_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 c.DisposableCollection,i=S.combineLatest(e.map(s=>s.matchesUpdate$)).pipe(S.debounceTime(220)).subscribe(([...s])=>{const r=this._matches=s.flat();if(r.length){const a=this._moveToInitialMatch(this._findModels,r,!0);this._state.changeState({matchesCount:r.length,matchesPosition:a+1}),this.replaceables$.next(r.filter(o=>o.replaceable))}else this._state.changeState({matchesCount:0,matchesPosition:0}),this.replaceables$.next([])});e.forEach(s=>n.add(c.toDisposable(s.activelyChangingMatch$.subscribe(r=>{const a=this._matches.findIndex(o=>o===r);this._state.changeState({matchesPosition:a+1})})))),n.add(c.toDisposable(i))}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((i,s)=>(i.success+=s.success,i.failure+=s.failure,i),{success:0,failure:0}));return e.failure===0&&this._stopSearching(),e}getCurrentMatch(){return this._state.matchesPosition>0?this._matches[this._state.matchesPosition-1]:null}moveToNextMatch(){if(!this._matchingModel)return;const e=this._findModels.length===1,n=this._matchingModel.moveToNextMatch({loop:e});if(n){const i=this._matches.findIndex(s=>s===n);this.currentMatch$.next(n),this._state.changeState({matchesPosition:i+1})}else{const i=this._findModels.findIndex(o=>o===this._matchingModel),s=this._findModels[(i+1)%this._findModels.length],r=s.moveToNextMatch(),a=this._matches.findIndex(o=>o===r);this.currentMatch$.next(r),this._matchingModel=s,this._state.changeState({matchesPosition:a+1})}}moveToPreviousMatch(){if(!this._matchingModel)return;const e=this._findModels.length===1,n=this._matchingModel.moveToPreviousMatch({loop:e});if(n){const i=this._matches.findIndex(s=>s===n);this.currentMatch$.next(n),this._state.changeState({matchesPosition:i+1})}else{const i=this._findModels.findIndex(o=>o===this._matchingModel),s=this._findModels[(i-1+this._findModels.length)%this._findModels.length],r=s.moveToPreviousMatch(),a=this._matches.findIndex(o=>o===r);this.currentMatch$.next(r),this._matchingModel=s,this._state.changeState({matchesPosition:a+1})}}_moveToInitialMatch(e,n,i=!1){var f;const s=(f=this._univerInstanceService.getFocusedUniverInstance())==null?void 0:f.getUnitId();if(!s)return-1;const r=e.find(g=>g.unitId===s);if(r){this._matchingModel=r;const g=r.moveToNextMatch({stayIfOnMatch:!0,noFocus:i}),v=n.findIndex(m=>m===g);return this.currentMatch$.next(g),v}this._matchingModel=e[0];const a=this._matchingModel.moveToNextMatch({noFocus:i}),o=this._matches.findIndex(g=>g===a);return this.currentMatch$.next(a),o}};w=J([O(2,c.IUniverInstanceService),O(3,c.ILogService)],w);var P=(t=>(t.ROW="row",t.COLUMN="column",t))(P||{}),T=(t=>(t.VALUE="value",t.FORMULA="formula",t))(T||{}),E=(t=>(t.SUBUNIT="subunit",t.UNIT="unit",t))(E||{});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 We{constructor(){d(this,"_stateUpdates$",new S.Subject);d(this,"stateUpdates$",this._stateUpdates$.asObservable());d(this,"_state$",new S.BehaviorSubject(B()));d(this,"state$",this._state$.asObservable());d(this,"_findString","");d(this,"_inputtingFindString","");d(this,"_replaceString","");d(this,"_revealed",!1);d(this,"_replaceRevealed",!1);d(this,"_matchesPosition",0);d(this,"_matchesCount",0);d(this,"_caseSensitive",!0);d(this,"_matchesTheWholeCell",!1);d(this,"_findDirection","row");d(this,"_findScope","subunit");d(this,"_findBy","value");d(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 i={};typeof e.findString<"u"&&e.findString!==this._findString&&(this._findString=e.findString,i.findString=this._findString,n=!0),typeof e.revealed<"u"&&e.revealed!==this._revealed&&(this._revealed=e.revealed,i.revealed=e.revealed,n=!0),typeof e.replaceRevealed<"u"&&e.replaceRevealed!==this._replaceRevealed&&(this._replaceRevealed=e.replaceRevealed,i.replaceRevealed=e.replaceRevealed,n=!0),typeof e.replaceString<"u"&&e.replaceString!==this._replaceString&&(this._replaceString=e.replaceString,i.replaceString=e.replaceString,n=!0),typeof e.matchesCount<"u"&&e.matchesCount!==this._matchesCount&&(this._matchesCount=e.matchesCount,i.matchesCount=e.matchesCount,n=!0),typeof e.matchesPosition<"u"&&e.matchesPosition!==this._matchesPosition&&(this._matchesPosition=e.matchesPosition,i.matchesPosition=e.matchesPosition,n=!0),typeof e.findBy<"u"&&e.findBy!==this._findBy&&(this._findBy=e.findBy,i.findBy=e.findBy,n=!0),typeof e.findScope<"u"&&e.findScope!==this._findScope&&(this._findScope=e.findScope,i.findScope=e.findScope,n=!0),typeof e.findDirection<"u"&&e.findDirection!==this._findDirection&&(this._findDirection=e.findDirection,i.findDirection=e.findDirection,n=!0),typeof e.caseSensitive<"u"&&e.caseSensitive!==this._caseSensitive&&(this._caseSensitive=e.caseSensitive,i.caseSensitive=e.caseSensitive,n=!0),typeof e.matchesTheWholeCell<"u"&&e.matchesTheWholeCell!==this._matchesTheWholeCell&&(this._matchesTheWholeCell=e.matchesTheWholeCell,i.matchesTheWholeCell=e.matchesTheWholeCell,n=!0),typeof e.inputtingFindString<"u"&&e.inputtingFindString!==this._inputtingFindString&&(this._inputtingFindString=e.inputtingFindString,i.inputtingFindString=e.inputtingFindString,n=!0),typeof e.findCompleted<"u"&&e.findCompleted!==this._findCompleted&&(this._findCompleted=e.findCompleted,i.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(i))}}let U=class extends c.Disposable{constructor(e,n){super();d(this,"_providers",new Set);d(this,"_state",new We);d(this,"_model");d(this,"_currentMatch$",new S.BehaviorSubject(null));d(this,"currentMatch$",this._currentMatch$.asObservable());d(this,"_replaceables$",new S.BehaviorSubject([]));d(this,"replaceables$",this._replaceables$.asObservable());d(this,"_focusSignal$",new S.Subject);d(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(i=>this._currentMatch$.next(i)),this._model.replaceables$.subscribe(i=>this._replaceables$.next(i));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),c.toDisposable(()=>this._providers.delete(e))}_toggleRevealReplace(e){this._contextService.setContextValue(Z,e)}_toggleDisplayRawFormula(e){this._contextService.setContextValue(Te.RENDER_RAW_FORMULA_KEY,e)}};U=J([O(0,M.Inject(M.Injector)),O(1,c.IContextService)],U);const N={id:"ui.operation.open-find-dialog",type:c.CommandType.OPERATION,handler:t=>{const e=t.get(b);return e.revealed?e.focusFindInput():e.start(),!0}},W={id:"ui.operation.open-replace-dialog",type:c.CommandType.OPERATION,handler:t=>{const e=t.get(b);return e.revealed?e.replaceRevealed?e.focusFindInput():e.revealReplace():e.start(!0),!0}},Q={type:c.CommandType.OPERATION,id:"ui.operation.go-to-next-match",handler:t=>(t.get(b).moveToNextMatch(),!0)},X={type:c.CommandType.OPERATION,id:"ui.operation.go-to-previous-match",handler:t=>(t.get(b).moveToPreviousMatch(),!0)};var ee={exports:{}},j={};/**
1
+ "use strict";var Pe=Object.defineProperty;var Te=(t,e,n)=>e in t?Pe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var d=(t,e,n)=>(Te(t,typeof e!="symbol"?e+"":e,n),n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@univerjs/core"),M=require("@wendellhu/redi"),h=require("@univerjs/ui"),S=require("rxjs"),Ee=require("@univerjs/engine-render"),l=require("react"),p=require("@univerjs/design"),y=require("@wendellhu/redi/react-bindings");var R=function(){return R=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++){e=arguments[n];for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=e[s])}return t},R.apply(this,arguments)},$e=function(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,i=Object.getOwnPropertySymbols(t);s<i.length;s++)e.indexOf(i[s])<0&&Object.prototype.propertyIsEnumerable.call(t,i[s])&&(n[i[s]]=t[i[s]]);return n},H=l.forwardRef(function(t,e){var n=t.icon,i=t.id,s=t.className,r=t.extend,a=$e(t,["icon","id","className","extend"]),o="univerjs-icon univerjs-icon-".concat(i," ").concat(s||"").trim(),f=l.useRef("_".concat(Le()));return K(n,"".concat(i),{defIds:n.defIds,idSuffix:f.current},R({ref:e,className:o},a),r)});function K(t,e,n,i,s){return l.createElement(t.tag,R(R({key:e},Ne(t,n,s)),i),(je(t,n).children||[]).map(function(r,a){return K(r,"".concat(e,"-").concat(t.tag,"-").concat(a),n,void 0,s)}))}function Ne(t,e,n){var i=R({},t.attrs);n!=null&&n.colorChannel1&&i.fill==="colorChannel1"&&(i.fill=n.colorChannel1);var s=e.defIds;return!s||s.length===0||(t.tag==="use"&&i["xlink:href"]&&(i["xlink:href"]=i["xlink:href"]+e.idSuffix),Object.entries(i).forEach(function(r){var a=r[0],o=r[1];typeof o=="string"&&(i[a]=o.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),i}function je(t,e){var n,i=e.defIds;return!i||i.length===0?t:t.tag==="defs"&&(!((n=t.children)===null||n===void 0)&&n.length)?R(R({},t),{children:t.children.map(function(s){return typeof s.attrs.id=="string"&&i&&i.indexOf(s.attrs.id)>-1?R(R({},s),{attrs:R(R({},s.attrs),{id:s.attrs.id+e.idSuffix})}):s})}):t}function Le(){return Math.random().toString(36).substring(2,8)}H.displayName="UniverIcon";var Ae={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"}}]}]},q=l.forwardRef(function(t,e){return l.createElement(H,Object.assign({},t,{id:"search-single-16",ref:e,icon:Ae}))});q.displayName="SearchSingle16";const z="FIND_REPLACE_INPUT_FOCUS",Y="FIND_REPLACE_DIALOG_FOCUS",Z="FIND_REPLACE_REPLACE_REVEALED";var we=Object.defineProperty,Ue=Object.getOwnPropertyDescriptor,J=(t,e,n,i)=>{for(var s=i>1?void 0:i?Ue(e,n):e,r=t.length-1,a;r>=0;r--)(a=t[r])&&(s=(i?a(e,n,s):a(s))||s);return i&&s&&we(e,n,s),s},O=(t,e)=>(n,i)=>e(n,i,t);class Be extends c.Disposable{}const b=M.createIdentifier("find-replace.service");function ke(t){return typeof t.findString<"u"||typeof t.inputtingFindString<"u"||typeof t.findDirection<"u"||typeof t.matchesTheWholeCell<"u"||typeof t.caseSensitive<"u"||typeof t.findScope<"u"||typeof t.findBy<"u"}let w=class extends c.Disposable{constructor(e,n,i,s){super();d(this,"currentMatch$",new S.BehaviorSubject(null));d(this,"replaceables$",new S.BehaviorSubject([]));d(this,"_findModels",[]);d(this,"_matchingModel",null);d(this,"_matches",[]);d(this,"_currentSearchingDisposables",null);this._state=e,this._providers=n,this._univerInstanceService=i,this._logService=s,this.disposeWithMe(this._state.stateUpdates$.pipe(S.throttleTime(200,void 0,{leading:!0,trailing:!0})).subscribe(async r=>{const a=this._state.state;ke(r)&&(a.findString!==""&&!a.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 i=this._matches=n.map(r=>r.getMatches()).flat();if(this.replaceables$.next(i.filter(r=>r.replaceable)),!i.length)return this._state.changeState({matchesCount:0,matchesPosition:0}),{results:[]};const s=this._moveToInitialMatch(n,i);return this._state.changeState({matchesCount:i.length,matchesPosition:s+1}),{results:i}}_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 c.DisposableCollection,i=S.combineLatest(e.map(s=>s.matchesUpdate$)).pipe(S.debounceTime(220)).subscribe(([...s])=>{const r=this._matches=s.flat();if(r.length){const a=this._moveToInitialMatch(this._findModels,r,!0);this._state.changeState({matchesCount:r.length,matchesPosition:a+1}),this.replaceables$.next(r.filter(o=>o.replaceable))}else this._state.changeState({matchesCount:0,matchesPosition:0}),this.replaceables$.next([])});e.forEach(s=>n.add(c.toDisposable(s.activelyChangingMatch$.subscribe(r=>{const a=this._matches.findIndex(o=>o===r);this._state.changeState({matchesPosition:a+1})})))),n.add(c.toDisposable(i))}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((i,s)=>(i.success+=s.success,i.failure+=s.failure,i),{success:0,failure:0}));return e.failure===0&&this._stopSearching(),e}getCurrentMatch(){return this._state.matchesPosition>0?this._matches[this._state.matchesPosition-1]:null}moveToNextMatch(){if(!this._matchingModel)return;const e=this._findModels.length===1,n=this._matchingModel.moveToNextMatch({loop:e});if(n){const i=this._matches.findIndex(s=>s===n);this.currentMatch$.next(n),this._state.changeState({matchesPosition:i+1})}else{const i=this._findModels.findIndex(o=>o===this._matchingModel),s=this._findModels[(i+1)%this._findModels.length],r=s.moveToNextMatch(),a=this._matches.findIndex(o=>o===r);this.currentMatch$.next(r),this._matchingModel=s,this._state.changeState({matchesPosition:a+1})}}moveToPreviousMatch(){if(!this._matchingModel)return;const e=this._findModels.length===1,n=this._matchingModel.moveToPreviousMatch({loop:e});if(n){const i=this._matches.findIndex(s=>s===n);this.currentMatch$.next(n),this._state.changeState({matchesPosition:i+1})}else{const i=this._findModels.findIndex(o=>o===this._matchingModel),s=this._findModels[(i-1+this._findModels.length)%this._findModels.length],r=s.moveToPreviousMatch(),a=this._matches.findIndex(o=>o===r);this.currentMatch$.next(r),this._matchingModel=s,this._state.changeState({matchesPosition:a+1})}}_moveToInitialMatch(e,n,i=!1){var f;const s=(f=this._univerInstanceService.getFocusedUniverInstance())==null?void 0:f.getUnitId();if(!s)return-1;const r=e.find(_=>_.unitId===s);if(r){this._matchingModel=r;const _=r.moveToNextMatch({stayIfOnMatch:!0,noFocus:i}),v=n.findIndex(m=>m===_);return this.currentMatch$.next(_),v}this._matchingModel=e[0];const a=this._matchingModel.moveToNextMatch({noFocus:i}),o=this._matches.findIndex(_=>_===a);return this.currentMatch$.next(a),o}};w=J([O(2,c.IUniverInstanceService),O(3,c.ILogService)],w);var P=(t=>(t.ROW="row",t.COLUMN="column",t))(P||{}),T=(t=>(t.VALUE="value",t.FORMULA="formula",t))(T||{}),E=(t=>(t.SUBUNIT="subunit",t.UNIT="unit",t))(E||{});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 We{constructor(){d(this,"_stateUpdates$",new S.Subject);d(this,"stateUpdates$",this._stateUpdates$.asObservable());d(this,"_state$",new S.BehaviorSubject(B()));d(this,"state$",this._state$.asObservable());d(this,"_findString","");d(this,"_inputtingFindString","");d(this,"_replaceString","");d(this,"_revealed",!1);d(this,"_replaceRevealed",!1);d(this,"_matchesPosition",0);d(this,"_matchesCount",0);d(this,"_caseSensitive",!0);d(this,"_matchesTheWholeCell",!1);d(this,"_findDirection","row");d(this,"_findScope","subunit");d(this,"_findBy","value");d(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 i={};typeof e.findString<"u"&&e.findString!==this._findString&&(this._findString=e.findString,i.findString=this._findString,n=!0),typeof e.revealed<"u"&&e.revealed!==this._revealed&&(this._revealed=e.revealed,i.revealed=e.revealed,n=!0),typeof e.replaceRevealed<"u"&&e.replaceRevealed!==this._replaceRevealed&&(this._replaceRevealed=e.replaceRevealed,i.replaceRevealed=e.replaceRevealed,n=!0),typeof e.replaceString<"u"&&e.replaceString!==this._replaceString&&(this._replaceString=e.replaceString,i.replaceString=e.replaceString,n=!0),typeof e.matchesCount<"u"&&e.matchesCount!==this._matchesCount&&(this._matchesCount=e.matchesCount,i.matchesCount=e.matchesCount,n=!0),typeof e.matchesPosition<"u"&&e.matchesPosition!==this._matchesPosition&&(this._matchesPosition=e.matchesPosition,i.matchesPosition=e.matchesPosition,n=!0),typeof e.findBy<"u"&&e.findBy!==this._findBy&&(this._findBy=e.findBy,i.findBy=e.findBy,n=!0),typeof e.findScope<"u"&&e.findScope!==this._findScope&&(this._findScope=e.findScope,i.findScope=e.findScope,n=!0),typeof e.findDirection<"u"&&e.findDirection!==this._findDirection&&(this._findDirection=e.findDirection,i.findDirection=e.findDirection,n=!0),typeof e.caseSensitive<"u"&&e.caseSensitive!==this._caseSensitive&&(this._caseSensitive=e.caseSensitive,i.caseSensitive=e.caseSensitive,n=!0),typeof e.matchesTheWholeCell<"u"&&e.matchesTheWholeCell!==this._matchesTheWholeCell&&(this._matchesTheWholeCell=e.matchesTheWholeCell,i.matchesTheWholeCell=e.matchesTheWholeCell,n=!0),typeof e.inputtingFindString<"u"&&e.inputtingFindString!==this._inputtingFindString&&(this._inputtingFindString=e.inputtingFindString,i.inputtingFindString=e.inputtingFindString,n=!0),typeof e.findCompleted<"u"&&e.findCompleted!==this._findCompleted&&(this._findCompleted=e.findCompleted,i.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(i))}}let U=class extends c.Disposable{constructor(e,n){super();d(this,"_providers",new Set);d(this,"_state",new We);d(this,"_model");d(this,"_currentMatch$",new S.BehaviorSubject(null));d(this,"currentMatch$",this._currentMatch$.asObservable());d(this,"_replaceables$",new S.BehaviorSubject([]));d(this,"replaceables$",this._replaceables$.asObservable());d(this,"_focusSignal$",new S.Subject);d(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(i=>this._currentMatch$.next(i)),this._model.replaceables$.subscribe(i=>this._replaceables$.next(i));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),c.toDisposable(()=>this._providers.delete(e))}_toggleRevealReplace(e){this._contextService.setContextValue(Z,e)}_toggleDisplayRawFormula(e){this._contextService.setContextValue(Ee.RENDER_RAW_FORMULA_KEY,e)}};U=J([O(0,M.Inject(M.Injector)),O(1,c.IContextService)],U);const N={id:"ui.operation.open-find-dialog",type:c.CommandType.OPERATION,handler:t=>{const e=t.get(b);return e.revealed?e.focusFindInput():e.start(),!0}},k={id:"ui.operation.open-replace-dialog",type:c.CommandType.OPERATION,handler:t=>{const e=t.get(b);return e.revealed?e.replaceRevealed?e.focusFindInput():e.revealReplace():e.start(!0),!0}},Q={type:c.CommandType.OPERATION,id:"ui.operation.go-to-next-match",handler:t=>(t.get(b).moveToNextMatch(),!0)},X={type:c.CommandType.OPERATION,id:"ui.operation.go-to-previous-match",handler:t=>(t.get(b).moveToPreviousMatch(),!0)};var ee={exports:{}},j={};/**
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 ke=l,Ge=Symbol.for("react.element"),Ve=Symbol.for("react.fragment"),He=Object.prototype.hasOwnProperty,Ke=ke.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,qe={key:!0,ref:!0,__self:!0,__source:!0};function te(t,e,n){var i,s={},r=null,a=null;n!==void 0&&(r=""+n),e.key!==void 0&&(r=""+e.key),e.ref!==void 0&&(a=e.ref);for(i in e)He.call(e,i)&&!qe.hasOwnProperty(i)&&(s[i]=e[i]);if(t&&t.defaultProps)for(i in e=t.defaultProps,e)s[i]===void 0&&(s[i]=e[i]);return{$$typeof:Ge,type:t,key:r,ref:a,props:s,_owner:Ke.current}}j.Fragment=Ve;j.jsx=te;j.jsxs=te;ee.exports=j;var u=ee.exports;const ie={id:"ui.command.replace-current-match",type:c.CommandType.COMMAND,handler:t=>t.get(b).replace()},ze="CONFIRM_REPLACE_ALL",ne={id:"ui.command.replace-all-matches",type:c.CommandType.COMMAND,handler:async t=>{const e=t.get(h.IConfirmService),n=t.get(c.LocaleService),i=t.get(h.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 r=await t.get(b).replaceAll(),{success:a,failure:o}=r;return o>0?(a===0?i.show({type:p.MessageType.Error,content:n.t("find-replace.replace.all-failure")}):i.show({type:p.MessageType.Warning,content:n.t("find-replace.replace.partial-success",`${a}`,`${o}`)}),!1):(i.show({type:p.MessageType.Success,content:n.t("find-replace.replace.all-success",`${a}`)}),!0)}};function se(t){const{findCompleted:e,localeService:n,matchesCount:i,matchesPosition:s,findString:r,findReplaceService:a,onChange:o,...f}=t,v=e&&i===0?n.t("find-replace.dialog.no-result"):i===0?" ":void 0;return u.jsx(p.InputWithSlot,{autoFocus:!0,placeholder:n.t("find-replace.dialog.find-placeholder"),slot:u.jsx(p.Pager,{loop:!0,text:v,value:s,total:i,onChange:m=>{s===i&&m===1?a.moveToNextMatch():s===1&&m===i||m<s?a.moveToPreviousMatch():a.moveToNextMatch()}}),value:r,onChange:m=>o==null?void 0:o(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",$={findReplaceDialogContainer:Ye,findReplaceExpandContainer:Ze,buttonText:Je,findReplaceButtonsGroup:Qe,findReplaceButtonsGroupRight:Xe};function re(t,e){const n=l.useCallback(()=>{var s;(s=document.querySelector(".univer-find-input input"))==null||s.focus()},[]),i=l.useCallback(()=>{const s=document.querySelectorAll(".univer-find-replace-dialog-container .univer-select-selection-search-input");return Array.from(s).some(r=>r===document.activeElement)},[]);return l.useImperativeHandle(e,()=>({focus:n,selectHasFocus:i})),l.useEffect(()=>{const s=t.focusSignal$.subscribe(()=>n());return()=>s.unsubscribe()},[t,n]),{focus:n,selectHasFocus:i}}const et=l.forwardRef(function(e,n){const i=y.useDependency(c.LocaleService),s=y.useDependency(b),r=y.useDependency(c.ICommandService),a=h.useObservable(s.state$,void 0,!0),{findCompleted:o,findString:f,matchesCount:g,matchesPosition:v}=a,m=l.useCallback(()=>{r.executeCommand(W.id)},[r]),I=l.useCallback(x=>s.changeFindString(x),[s]);return re(s,n),u.jsxs(l.Fragment,{children:[u.jsx(se,{findCompleted:o,className:"univer-find-input",matchesCount:g,matchesPosition:v,findReplaceService:s,localeService:i,findString:f,onChange:I}),u.jsx("div",{className:$.findReplaceExpandContainer,children:u.jsx(p.Button,{type:"text",size:"small",onClick:m,children:i.t("find-replace.dialog.advanced-finding")})})]})}),tt=l.forwardRef(function(e,n){const i=y.useDependency(b),s=y.useDependency(c.LocaleService),r=y.useDependency(c.ICommandService),a=y.useDependency(h.IMessageService),o=h.useObservable(i.currentMatch$,void 0,!0),f=h.useObservable(i.replaceables$,void 0,!0),g=h.useObservable(i.state$,void 0,!0),{matchesCount:v,matchesPosition:m,findString:I,inputtingFindString:x,replaceString:ce,caseSensitive:le,matchesTheWholeCell:de,findDirection:ue,findScope:he,findBy:pe,findCompleted:A}=g,fe=x.length===0,_e=v===0||!(o!=null&&o.replaceable),ge=f.length===0,me=l.useCallback(_=>i.changeInputtingFindString(_),[i]),ve=l.useCallback(_=>i.changeReplaceString(_),[i]),{focus:Se}=re(i,n),Ce=l.useCallback(()=>{I===x?i.moveToNextMatch():(i.changeFindString(x),i.find())},[I,x,i]),Re=l.useCallback(()=>r.executeCommand(ie.id),[r]),be=l.useCallback(async()=>{await r.executeCommand(ne.id),Se()},[r]),ye=l.useCallback(_=>{i.changeFindDirection(_)},[i]),Me=l.useCallback(_=>{i.changeFindScope(_)},[i]),xe=l.useCallback(_=>{i.changeFindBy(_)},[i]),Ie=nt(s),Fe=st(s),De=rt(s);return l.useEffect(()=>{const _=A&&v===0;let D=null;return _&&(D=a.show({content:s.t("find-replace.dialog.no-match"),type:p.MessageType.Warning,delay:5e3})),()=>D==null?void 0:D.dispose()},[A,v,a,s]),u.jsxs(l.Fragment,{children:[u.jsx(p.FormLayout,{label:s.t("find-replace.dialog.find"),children:u.jsx(se,{findCompleted:A,className:"univer-find-input",matchesCount:v,matchesPosition:m,findReplaceService:i,localeService:s,findString:x,onChange:me})}),u.jsx(p.FormLayout,{label:s.t("find-replace.dialog.replace"),children:u.jsx(p.Input,{placeholder:s.t("find-replace.dialog.replace-placeholder"),value:ce,onChange:_=>ve(_)})}),u.jsx(p.FormLayout,{label:s.t("find-replace.dialog.find-direction.title"),children:u.jsx(p.Select,{value:ue,options:Fe,onChange:ye})}),u.jsx(p.FormDualColumnLayout,{children:u.jsxs(l.Fragment,{children:[u.jsx(p.FormLayout,{label:s.t("find-replace.dialog.find-scope.title"),children:u.jsx(p.Select,{value:he,options:Ie,onChange:Me})}),u.jsx(p.FormLayout,{label:s.t("find-replace.dialog.find-by.title"),children:u.jsx(p.Select,{value:pe,options:De,onChange:xe})})]})}),u.jsx(p.FormDualColumnLayout,{children:u.jsxs(l.Fragment,{children:[u.jsx(p.FormLayout,{children:u.jsx(p.Checkbox,{checked:le,onChange:_=>{i.changeCaseSensitive(_)},children:s.t("find-replace.dialog.case-sensitive")})}),u.jsx(p.FormLayout,{children:u.jsx(p.Checkbox,{checked:de,onChange:_=>{i.changeMatchesTheWholeCell(_)},children:s.t("find-replace.dialog.match-the-whole-cell")})})]})}),u.jsxs("div",{className:$.findReplaceButtonsGroup,children:[u.jsx(p.Button,{type:"primary",onClick:Ce,disabled:fe,children:s.t("find-replace.dialog.find")}),u.jsxs("span",{className:$.findReplaceButtonsGroupRight,children:[u.jsx(p.Button,{disabled:_e,onClick:Re,children:s.t("find-replace.dialog.replace")}),u.jsx(p.Button,{disabled:ge,onClick:be,children:s.t("find-replace.dialog.replace-all")})]})]})]})});function it(){const t=y.useDependency(b),e=y.useDependency(h.ILayoutService),n=y.useDependency(c.IContextService),i=h.useObservable(t.state$,void 0,!0),s=l.useRef(null);l.useEffect(()=>{let f;return s.current&&(f=e.registerContainerElement(s.current)),()=>f==null?void 0:f.dispose()},[e]);const r=l.useRef(null),a=l.useCallback(f=>n.setContextValue(Y,f),[n]),o=l.useCallback(f=>n.setContextValue(z,f),[n]);return l.useEffect(()=>{var g;const f=S.fromEvent(document,"focusin").subscribe(v=>{var m;v.target&&((m=s.current)!=null&&m.contains(v.target))?a(!0):a(!1),!r.current||!r.current.selectHasFocus()?o(!0):o(!1)});return(g=r.current)==null||g.focus(),a(!0),o(!0),()=>{f.unsubscribe(),a(!1)}},[a,o]),u.jsx("div",{className:$.findReplaceDialogContainer,ref:s,children:i.replaceRevealed?u.jsx(tt,{ref:r}):u.jsx(et,{ref:r})})}function nt(t){const e=t.getCurrentLocale();return l.useMemo(()=>[{label:t.t("find-replace.dialog.find-scope.current-sheet"),value:E.SUBUNIT},{label:t.t("find-replace.dialog.find-scope.workbook"),value:E.UNIT}],[e])}function st(t){const e=t.getCurrentLocale();return l.useMemo(()=>[{label:t.t("find-replace.dialog.find-direction.row"),value:P.ROW},{label:t.t("find-replace.dialog.find-direction.column"),value:P.COLUMN}],[e])}function rt(t){const e=t.getCurrentLocale();return l.useMemo(()=>[{label:t.t("find-replace.dialog.find-by.value"),value:T.VALUE},{label:t.t("find-replace.dialog.find-by.formula"),value:T.FORMULA}],[e])}function F(t){return t.getContextValue(Y)}function at(t){return t.getContextValue(Z)}function ae(t){return t.getContextValue(z)}const L="7_find-replace-shortcuts";function k(t){return t.getContextValue(c.FOCUSING_SHEET)}function G(t){return!t.getContextValue(c.EDITOR_ACTIVATED)}const ot={id:N.id,description:"find-replace.shortcut.open-find-dialog",binding:h.KeyCode.F|h.MetaKeys.CTRL_COMMAND,group:L,preconditions(t){return!F(t)&&k(t)&&G(t)}},ct={id:N.id,description:"find-replace.shortcut.open-find-dialog",binding:h.KeyCode.F|h.MetaKeys.CTRL_COMMAND,mac:h.KeyCode.F|h.MetaKeys.MAC_CTRL,preconditions(t){return!F(t)&&k(t)&&G(t)}},lt={id:W.id,description:"find-replace.shortcut.open-replace-dialog",binding:h.KeyCode.H|h.MetaKeys.CTRL_COMMAND,mac:h.KeyCode.H|h.MetaKeys.MAC_CTRL,group:L,preconditions(t){return k(t)&&G(t)&&(!F(t)||!at(t))}},dt={id:Q.id,description:"find-replace.shortcut.go-to-next-match",binding:h.KeyCode.ENTER,group:L,priority:1e3,preconditions(t){return ae(t)&&F(t)}},ut={id:X.id,description:"find-replace.shortcut.go-to-previous-match",binding:h.KeyCode.ENTER|h.MetaKeys.SHIFT,group:L,priority:1e3,preconditions(t){return ae(t)&&F(t)}};function ht(t){const e=t.get(c.IContextService);return{id:N.id,icon:"SearchIcon",tooltip:"find-replace.toolbar",group:h.MenuGroup.TOOLBAR_OTHERS,type:h.MenuItemType.BUTTON,positions:[h.MenuPosition.TOOLBAR_START],hidden$:h.getMenuHiddenObservable(t,c.UniverInstanceType.SHEET),disabled$:S.combineLatest([e.subscribeContextValue$(c.EDITOR_ACTIVATED),e.subscribeContextValue$(c.FOCUSING_SHEET)]).pipe(S.map(([n,i])=>n||!i))}}var pt=Object.defineProperty,ft=Object.getOwnPropertyDescriptor,_t=(t,e,n,i)=>{for(var s=i>1?void 0:i?ft(e,n):e,r=t.length-1,a;r>=0;r--)(a=t[r])&&(s=(i?a(e,n,s):a(s))||s);return i&&s&&pt(e,n,s),s},C=(t,e)=>(n,i)=>e(n,i,t);const V="DESKTOP_FIND_REPLACE_DIALOG",oe=350,gt=20,mt=-90;exports.FindReplaceController=class extends c.RxDisposable{constructor(e,n,i,s,r,a,o,f,g,v,m,I){super(),this._univerInstanceService=e,this._menuService=n,this._shortcutService=i,this._commandService=s,this._findReplaceService=r,this._logService=a,this._dialogService=o,this._contextService=f,this._layoutService=g,this._localeService=v,this._componentManager=m,this._injector=I,this._initCommands(),this._initUI(),this._initShortcuts()}_initCommands(){[N,W,Q,X,ne,ie].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initShortcuts(){[lt,ot,ct,ut,dt].forEach(e=>this.disposeWithMe(this._shortcutService.registerShortcut(e)))}_initUI(){this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(ht))),this.disposeWithMe(this._componentManager.register("FindReplaceDialog",it)),this.disposeWithMe(this._componentManager.register("SearchIcon",q)),this._findReplaceService.stateUpdates$.pipe(S.takeUntil(this.dispose$)).subscribe(e=>{e.revealed===!0&&this._openPanel()}),this.disposeWithMe(this._univerInstanceService.focused$.pipe(S.takeUntil(this.dispose$)).subscribe(e=>{(!e||!this._univerInstanceService.getUniverSheetInstance(e))&&this.closePanel()}))}_openPanel(){this._dialogService.open({id:V,draggable:!0,width:oe,title:{title:this._localeService.t("find-replace.dialog.title")},children:{label:"FindReplaceDialog"},destroyOnClose:!0,defaultPosition:vt(),preservePositionOnDestroy:!0,onClose:()=>this.closePanel()})}closePanel(){this._dialogService.close(V),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus())}};exports.FindReplaceController=_t([c.OnLifecycle(c.LifecycleStages.Rendered,exports.FindReplaceController),C(0,c.IUniverInstanceService),C(1,h.IMenuService),C(2,h.IShortcutService),C(3,c.ICommandService),C(4,b),C(5,c.ILogService),C(6,h.IDialogService),C(7,c.IContextService),C(8,h.ILayoutService),C(9,M.Inject(c.LocaleService)),C(10,M.Inject(h.ComponentManager)),C(11,M.Inject(M.Injector))],exports.FindReplaceController);function vt(){const{innerWidth:t}=window;return{x:(t-oe)/2-gt,y:mt}}const St={"find-replace":{toolbar:"查找替换",shortcut:{"open-find-dialog":"打开查找对话框","open-replace-dialog":"打开替换对话框","close-dialog":"关闭查找替换对话框","go-to-next-match":"下一个匹配项","go-to-previous-match":"下一个匹配项"},dialog:{title:"查找",find:"查找",replace:"替换","replace-all":"替换全部","find-placeholder":"输入查找内容","advanced-finding":"替换 / 高级查找","replace-placeholder":"输入替换内容","case-sensitive":"匹配大小写","match-the-whole-cell":"匹配整个单元格","find-scope":{title:"查找范围","current-sheet":"当前子表",workbook:"整个工作簿"},"find-direction":{title:"查找顺序",column:"按列查找",row:"按行查找"},"find-by":{title:"查找方式",formula:"查找公式",value:"查找值"},"no-match":"已完成搜索,但是未找到任何匹配项","no-result":"无结果"},replace:{"all-success":"已全部替换 {0} 个匹配项","all-failure":"替换失败",confirm:{title:"确定要替换所有的匹配项吗?"}}},"find-replace-shortcuts":"查找替换"};var Ct=Object.defineProperty,Rt=Object.getOwnPropertyDescriptor,bt=(t,e,n,i)=>{for(var s=i>1?void 0:i?Rt(e,n):e,r=t.length-1,a;r>=0;r--)(a=t[r])&&(s=(i?a(e,n,s):a(s))||s);return i&&s&&Ct(e,n,s),s},yt=(t,e)=>(n,i)=>e(n,i,t);const Mt="FIND_REPLACE";exports.UniverFindReplacePlugin=class extends c.Plugin{constructor(e,n){super(Mt),this._injector=e,this._localeService=n,this._localeService.load({zhCN:St})}onStarting(e){[[exports.FindReplaceController],[b,{useClass:U}]].forEach(n=>{e.add(n)})}};exports.UniverFindReplacePlugin=bt([yt(1,M.Inject(c.LocaleService))],exports.UniverFindReplacePlugin);exports.FindBy=T;exports.FindDirection=P;exports.FindModel=Ue;exports.FindScope=E;exports.IFindReplaceService=b;
9
+ */var Ge=l,Ve=Symbol.for("react.element"),He=Symbol.for("react.fragment"),Ke=Object.prototype.hasOwnProperty,qe=Ge.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,ze={key:!0,ref:!0,__self:!0,__source:!0};function te(t,e,n){var i,s={},r=null,a=null;n!==void 0&&(r=""+n),e.key!==void 0&&(r=""+e.key),e.ref!==void 0&&(a=e.ref);for(i in e)Ke.call(e,i)&&!ze.hasOwnProperty(i)&&(s[i]=e[i]);if(t&&t.defaultProps)for(i in e=t.defaultProps,e)s[i]===void 0&&(s[i]=e[i]);return{$$typeof:Ve,type:t,key:r,ref:a,props:s,_owner:qe.current}}j.Fragment=He;j.jsx=te;j.jsxs=te;ee.exports=j;var u=ee.exports;const ie={id:"ui.command.replace-current-match",type:c.CommandType.COMMAND,handler:t=>t.get(b).replace()},Ye="CONFIRM_REPLACE_ALL",ne={id:"ui.command.replace-all-matches",type:c.CommandType.COMMAND,handler:async t=>{const e=t.get(h.IConfirmService),n=t.get(c.LocaleService),i=t.get(h.IMessageService);if(!await e.confirm({id:Ye,title:{title:n.t("find-replace.replace.confirm.title")},cancelText:n.t("button.cancel"),confirmText:n.t("button.confirm")}))return!1;const r=await t.get(b).replaceAll(),{success:a,failure:o}=r;return o>0?(a===0?i.show({type:p.MessageType.Error,content:n.t("find-replace.replace.all-failure")}):i.show({type:p.MessageType.Warning,content:n.t("find-replace.replace.partial-success",`${a}`,`${o}`)}),!1):(i.show({type:p.MessageType.Success,content:n.t("find-replace.replace.all-success",`${a}`)}),!0)}};function se(t){const{findCompleted:e,localeService:n,matchesCount:i,matchesPosition:s,findString:r,findReplaceService:a,onChange:o,...f}=t,v=e&&i===0?n.t("find-replace.dialog.no-result"):i===0?" ":void 0;return u.jsx(p.InputWithSlot,{autoFocus:!0,placeholder:n.t("find-replace.dialog.find-placeholder"),slot:u.jsx(p.Pager,{loop:!0,text:v,value:s,total:i,onChange:m=>{s===i&&m===1?a.moveToNextMatch():s===1&&m===i||m<s?a.moveToPreviousMatch():a.moveToNextMatch()}}),value:r,onChange:m=>o==null?void 0:o(m),...f})}const Ze="univer-find-replace-dialog-container",Je="univer-find-replace-expand-container",Qe="univer-button-text",Xe="univer-find-replace-buttons-group",et="univer-find-replace-buttons-group-right",$={findReplaceDialogContainer:Ze,findReplaceExpandContainer:Je,buttonText:Qe,findReplaceButtonsGroup:Xe,findReplaceButtonsGroupRight:et};function re(t,e){const n=l.useCallback(()=>{var s;(s=document.querySelector(".univer-find-input input"))==null||s.focus()},[]),i=l.useCallback(()=>{const s=document.querySelectorAll(".univer-find-replace-dialog-container .univer-select-selection-search-input");return Array.from(s).some(r=>r===document.activeElement)},[]);return l.useImperativeHandle(e,()=>({focus:n,selectHasFocus:i})),l.useEffect(()=>{const s=t.focusSignal$.subscribe(()=>n());return()=>s.unsubscribe()},[t,n]),{focus:n,selectHasFocus:i}}const tt=l.forwardRef(function(e,n){const i=y.useDependency(c.LocaleService),s=y.useDependency(b),r=y.useDependency(c.ICommandService),a=h.useObservable(s.state$,void 0,!0),{findCompleted:o,findString:f,matchesCount:_,matchesPosition:v}=a,m=l.useCallback(()=>{r.executeCommand(k.id)},[r]),F=l.useCallback(x=>s.changeFindString(x),[s]);return re(s,n),u.jsxs(l.Fragment,{children:[u.jsx(se,{findCompleted:o,className:"univer-find-input",matchesCount:_,matchesPosition:v,findReplaceService:s,localeService:i,findString:f,onChange:F}),u.jsx("div",{className:$.findReplaceExpandContainer,children:u.jsx(p.Button,{type:"text",size:"small",onClick:m,children:i.t("find-replace.dialog.advanced-finding")})})]})}),it=l.forwardRef(function(e,n){const i=y.useDependency(b),s=y.useDependency(c.LocaleService),r=y.useDependency(c.ICommandService),a=y.useDependency(h.IMessageService),o=h.useObservable(i.currentMatch$,void 0,!0),f=h.useObservable(i.replaceables$,void 0,!0),_=h.useObservable(i.state$,void 0,!0),{matchesCount:v,matchesPosition:m,findString:F,inputtingFindString:x,replaceString:le,caseSensitive:de,matchesTheWholeCell:ue,findDirection:he,findScope:pe,findBy:fe,findCompleted:A}=_,ge=x.length===0,_e=v===0||!(o!=null&&o.replaceable),me=f.length===0,ve=l.useCallback(g=>i.changeInputtingFindString(g),[i]),Se=l.useCallback(g=>i.changeReplaceString(g),[i]),{focus:Ce}=re(i,n),Re=l.useCallback(()=>{F===x?i.moveToNextMatch():(i.changeFindString(x),i.find())},[F,x,i]),be=l.useCallback(()=>r.executeCommand(ie.id),[r]),ye=l.useCallback(async()=>{await r.executeCommand(ne.id),Ce()},[r]),Me=l.useCallback(g=>{i.changeFindDirection(g)},[i]),xe=l.useCallback(g=>{i.changeFindScope(g)},[i]),Fe=l.useCallback(g=>{i.changeFindBy(g)},[i]),Ie=st(s),De=rt(s),Oe=at(s);return l.useEffect(()=>{const g=A&&v===0;let D=null;return g&&(D=a.show({content:s.t("find-replace.dialog.no-match"),type:p.MessageType.Warning,delay:5e3})),()=>D==null?void 0:D.dispose()},[A,v,a,s]),u.jsxs(l.Fragment,{children:[u.jsx(p.FormLayout,{label:s.t("find-replace.dialog.find"),children:u.jsx(se,{findCompleted:A,className:"univer-find-input",matchesCount:v,matchesPosition:m,findReplaceService:i,localeService:s,findString:x,onChange:ve})}),u.jsx(p.FormLayout,{label:s.t("find-replace.dialog.replace"),children:u.jsx(p.Input,{placeholder:s.t("find-replace.dialog.replace-placeholder"),value:le,onChange:g=>Se(g)})}),u.jsx(p.FormLayout,{label:s.t("find-replace.dialog.find-direction.title"),children:u.jsx(p.Select,{value:he,options:De,onChange:Me})}),u.jsx(p.FormDualColumnLayout,{children:u.jsxs(l.Fragment,{children:[u.jsx(p.FormLayout,{label:s.t("find-replace.dialog.find-scope.title"),children:u.jsx(p.Select,{value:pe,options:Ie,onChange:xe})}),u.jsx(p.FormLayout,{label:s.t("find-replace.dialog.find-by.title"),children:u.jsx(p.Select,{value:fe,options:Oe,onChange:Fe})})]})}),u.jsx(p.FormDualColumnLayout,{children:u.jsxs(l.Fragment,{children:[u.jsx(p.FormLayout,{children:u.jsx(p.Checkbox,{checked:de,onChange:g=>{i.changeCaseSensitive(g)},children:s.t("find-replace.dialog.case-sensitive")})}),u.jsx(p.FormLayout,{children:u.jsx(p.Checkbox,{checked:ue,onChange:g=>{i.changeMatchesTheWholeCell(g)},children:s.t("find-replace.dialog.match-the-whole-cell")})})]})}),u.jsxs("div",{className:$.findReplaceButtonsGroup,children:[u.jsx(p.Button,{type:"primary",onClick:Re,disabled:ge,children:s.t("find-replace.dialog.find")}),u.jsxs("span",{className:$.findReplaceButtonsGroupRight,children:[u.jsx(p.Button,{disabled:_e,onClick:be,children:s.t("find-replace.dialog.replace")}),u.jsx(p.Button,{disabled:me,onClick:ye,children:s.t("find-replace.dialog.replace-all")})]})]})]})});function nt(){const t=y.useDependency(b),e=y.useDependency(h.ILayoutService),n=y.useDependency(c.IContextService),i=h.useObservable(t.state$,void 0,!0),s=l.useRef(null);l.useEffect(()=>{let f;return s.current&&(f=e.registerContainerElement(s.current)),()=>f==null?void 0:f.dispose()},[e]);const r=l.useRef(null),a=l.useCallback(f=>n.setContextValue(Y,f),[n]),o=l.useCallback(f=>n.setContextValue(z,f),[n]);return l.useEffect(()=>{var _;const f=S.fromEvent(document,"focusin").subscribe(v=>{var m;v.target&&((m=s.current)!=null&&m.contains(v.target))?a(!0):a(!1),!r.current||!r.current.selectHasFocus()?o(!0):o(!1)});return(_=r.current)==null||_.focus(),a(!0),o(!0),()=>{f.unsubscribe(),a(!1)}},[a,o]),u.jsx("div",{className:$.findReplaceDialogContainer,ref:s,children:i.replaceRevealed?u.jsx(it,{ref:r}):u.jsx(tt,{ref:r})})}function st(t){const e=t.getCurrentLocale();return l.useMemo(()=>[{label:t.t("find-replace.dialog.find-scope.current-sheet"),value:E.SUBUNIT},{label:t.t("find-replace.dialog.find-scope.workbook"),value:E.UNIT}],[e])}function rt(t){const e=t.getCurrentLocale();return l.useMemo(()=>[{label:t.t("find-replace.dialog.find-direction.row"),value:P.ROW},{label:t.t("find-replace.dialog.find-direction.column"),value:P.COLUMN}],[e])}function at(t){const e=t.getCurrentLocale();return l.useMemo(()=>[{label:t.t("find-replace.dialog.find-by.value"),value:T.VALUE},{label:t.t("find-replace.dialog.find-by.formula"),value:T.FORMULA}],[e])}function I(t){return t.getContextValue(Y)}function ot(t){return t.getContextValue(Z)}function ae(t){return t.getContextValue(z)}const L="7_find-replace-shortcuts";function W(t){return t.getContextValue(c.FOCUSING_SHEET)}function G(t){return!t.getContextValue(c.EDITOR_ACTIVATED)}const ct={id:N.id,description:"find-replace.shortcut.open-find-dialog",binding:h.KeyCode.F|h.MetaKeys.CTRL_COMMAND,group:L,preconditions(t){return!I(t)&&W(t)&&G(t)}},lt={id:N.id,description:"find-replace.shortcut.open-find-dialog",binding:h.KeyCode.F|h.MetaKeys.CTRL_COMMAND,mac:h.KeyCode.F|h.MetaKeys.MAC_CTRL,preconditions(t){return!I(t)&&W(t)&&G(t)}},dt={id:k.id,description:"find-replace.shortcut.open-replace-dialog",binding:h.KeyCode.H|h.MetaKeys.CTRL_COMMAND,mac:h.KeyCode.H|h.MetaKeys.MAC_CTRL,group:L,preconditions(t){return W(t)&&G(t)&&(!I(t)||!ot(t))}},ut={id:Q.id,description:"find-replace.shortcut.go-to-next-match",binding:h.KeyCode.ENTER,group:L,priority:1e3,preconditions(t){return ae(t)&&I(t)}},ht={id:X.id,description:"find-replace.shortcut.go-to-previous-match",binding:h.KeyCode.ENTER|h.MetaKeys.SHIFT,group:L,priority:1e3,preconditions(t){return ae(t)&&I(t)}};function pt(t){const e=t.get(c.IContextService);return{id:N.id,icon:"SearchIcon",tooltip:"find-replace.toolbar",group:h.MenuGroup.TOOLBAR_OTHERS,type:h.MenuItemType.BUTTON,positions:[h.MenuPosition.TOOLBAR_START],hidden$:h.getMenuHiddenObservable(t,c.UniverInstanceType.SHEET),disabled$:S.combineLatest([e.subscribeContextValue$(c.EDITOR_ACTIVATED),e.subscribeContextValue$(c.FOCUSING_SHEET)]).pipe(S.map(([n,i])=>n||!i))}}var ft=Object.defineProperty,gt=Object.getOwnPropertyDescriptor,_t=(t,e,n,i)=>{for(var s=i>1?void 0:i?gt(e,n):e,r=t.length-1,a;r>=0;r--)(a=t[r])&&(s=(i?a(e,n,s):a(s))||s);return i&&s&&ft(e,n,s),s},C=(t,e)=>(n,i)=>e(n,i,t);const V="DESKTOP_FIND_REPLACE_DIALOG",oe=350,mt=20,vt=-90;exports.FindReplaceController=class extends c.RxDisposable{constructor(e,n,i,s,r,a,o,f,_,v,m,F){super(),this._univerInstanceService=e,this._menuService=n,this._shortcutService=i,this._commandService=s,this._findReplaceService=r,this._logService=a,this._dialogService=o,this._contextService=f,this._layoutService=_,this._localeService=v,this._componentManager=m,this._injector=F,this._initCommands(),this._initUI(),this._initShortcuts()}_initCommands(){[N,k,Q,X,ne,ie].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initShortcuts(){[dt,ct,lt,ht,ut].forEach(e=>this.disposeWithMe(this._shortcutService.registerShortcut(e)))}_initUI(){this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(pt))),this.disposeWithMe(this._componentManager.register("FindReplaceDialog",nt)),this.disposeWithMe(this._componentManager.register("SearchIcon",q)),this._findReplaceService.stateUpdates$.pipe(S.takeUntil(this.dispose$)).subscribe(e=>{e.revealed===!0&&this._openPanel()}),this.disposeWithMe(this._univerInstanceService.focused$.pipe(S.takeUntil(this.dispose$)).subscribe(e=>{(!e||!this._univerInstanceService.getUniverSheetInstance(e))&&this.closePanel()}))}_openPanel(){this._dialogService.open({id:V,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(V),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus())}};exports.FindReplaceController=_t([c.OnLifecycle(c.LifecycleStages.Rendered,exports.FindReplaceController),C(0,c.IUniverInstanceService),C(1,h.IMenuService),C(2,h.IShortcutService),C(3,c.ICommandService),C(4,b),C(5,c.ILogService),C(6,h.IDialogService),C(7,c.IContextService),C(8,h.ILayoutService),C(9,M.Inject(c.LocaleService)),C(10,M.Inject(h.ComponentManager)),C(11,M.Inject(M.Injector))],exports.FindReplaceController);function St(){const{innerWidth:t}=window;return{x:(t-oe)/2-mt,y:vt}}const Ct={"find-replace":{toolbar:"Find & Replace",shortcut:{"open-find-dialog":"Open Find Dialog","open-replace-dialog":"Open Replace Dialog","close-dialog":"Close Find & Replace Dialog","go-to-next-match":"Go to Next Match","go-to-previous-match":"Go to Previous Match"},dialog:{title:"Find",find:"Find",replace:"Replace","replace-all":"Replace All","case-sensitive":"Case Sensitive","find-placeholder":"Find in this Sheet","advanced-finding":"Advanced Searching & Replace","replace-placeholder":"Input Replace String","match-the-whole-cell":"Match the Whole Cell","find-direction":{title:"Find Direction",row:"Search by Row",column:"Search by Column"},"find-scope":{title:"Find Range","current-sheet":"Current Sheet",workbook:"Workbook"},"find-by":{title:"Find By",value:"Find by Value",formula:"Find Formula"},"no-match":"Finding completed but no match found.","no-result":"No Result"},replace:{"all-success":"Replaced all {0} matches","all-failure":"Replace failed",confirm:{title:"Are you sure to replace all matches?"}}},"find-replace-shortcuts":"Find & Replace"},Rt=Ct,bt={"find-replace":{toolbar:"查找替换",shortcut:{"open-find-dialog":"打开查找对话框","open-replace-dialog":"打开替换对话框","close-dialog":"关闭查找替换对话框","go-to-next-match":"下一个匹配项","go-to-previous-match":"下一个匹配项"},dialog:{title:"查找",find:"查找",replace:"替换","replace-all":"替换全部","find-placeholder":"输入查找内容","advanced-finding":"替换 / 高级查找","replace-placeholder":"输入替换内容","case-sensitive":"匹配大小写","match-the-whole-cell":"匹配整个单元格","find-scope":{title:"查找范围","current-sheet":"当前子表",workbook:"整个工作簿"},"find-direction":{title:"查找顺序",column:"按列查找",row:"按行查找"},"find-by":{title:"查找方式",formula:"查找公式",value:"查找值"},"no-match":"已完成搜索,但是未找到任何匹配项","no-result":"无结果"},replace:{"all-success":"已全部替换 {0} 个匹配项","all-failure":"替换失败",confirm:{title:"确定要替换所有的匹配项吗?"}}},"find-replace-shortcuts":"查找替换"},ce=bt;var yt=Object.defineProperty,Mt=Object.getOwnPropertyDescriptor,xt=(t,e,n,i)=>{for(var s=i>1?void 0:i?Mt(e,n):e,r=t.length-1,a;r>=0;r--)(a=t[r])&&(s=(i?a(e,n,s):a(s))||s);return i&&s&&yt(e,n,s),s},Ft=(t,e)=>(n,i)=>e(n,i,t);const It="FIND_REPLACE";exports.UniverFindReplacePlugin=class extends c.Plugin{constructor(e,n){super(It),this._injector=e,this._localeService=n,this._localeService.load({zhCN:ce})}onStarting(e){[[exports.FindReplaceController],[b,{useClass:U}]].forEach(n=>{e.add(n)})}};exports.UniverFindReplacePlugin=xt([Ft(1,M.Inject(c.LocaleService))],exports.UniverFindReplacePlugin);exports.FindBy=T;exports.FindDirection=P;exports.FindModel=Be;exports.FindScope=E;exports.IFindReplaceService=b;exports.enUS=Rt;exports.zhCN=ce;
package/lib/es/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  var rt = Object.defineProperty;
2
2
  var at = (t, e, n) => e in t ? rt(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
3
  var c = (t, e, n) => (at(t, typeof e != "symbol" ? e + "" : e, n), n);
4
- import { Disposable as X, IUniverInstanceService as he, ILogService as ue, toDisposable as q, IContextService as U, DisposableCollection as ot, CommandType as b, LocaleService as P, ICommandService as ee, FOCUSING_SHEET as fe, EDITOR_ACTIVATED as pe, UniverInstanceType as ct, RxDisposable as lt, OnLifecycle as dt, LifecycleStages as ht, Plugin as ut } from "@univerjs/core";
5
- import { createIdentifier as ft, Inject as y, Injector as _e } from "@wendellhu/redi";
6
- import { IConfirmService as pt, IMessageService as ge, useObservable as I, ILayoutService as me, KeyCode as x, MetaKeys as M, MenuGroup as _t, MenuItemType as gt, MenuPosition as mt, getMenuHiddenObservable as vt, ComponentManager as St, IMenuService as Ct, IShortcutService as Rt, IDialogService as xt } from "@univerjs/ui";
7
- import { BehaviorSubject as F, Subject as ve, throttleTime as Mt, combineLatest as Se, debounceTime as bt, fromEvent as yt, map as It, takeUntil as ae } from "rxjs";
4
+ import { Disposable as X, IUniverInstanceService as he, ILogService as ue, toDisposable as q, IContextService as U, DisposableCollection as ot, CommandType as M, LocaleService as D, ICommandService as ee, FOCUSING_SHEET as pe, EDITOR_ACTIVATED as fe, UniverInstanceType as ct, RxDisposable as lt, OnLifecycle as dt, LifecycleStages as ht, Plugin as ut } from "@univerjs/core";
5
+ import { createIdentifier as pt, Inject as y, Injector as _e } from "@wendellhu/redi";
6
+ import { IConfirmService as ft, IMessageService as ge, useObservable as I, ILayoutService as me, KeyCode as b, MetaKeys as x, MenuGroup as _t, MenuItemType as gt, MenuPosition as mt, getMenuHiddenObservable as vt, ComponentManager as St, IMenuService as Ct, IShortcutService as Rt, IDialogService as bt } from "@univerjs/ui";
7
+ import { BehaviorSubject as F, Subject as ve, throttleTime as xt, combineLatest as Se, debounceTime as Mt, fromEvent as yt, map as It, takeUntil as ae } from "rxjs";
8
8
  import { RENDER_RAW_FORMULA_KEY as Ft } from "@univerjs/engine-render";
9
- import Pt, { forwardRef as B, useRef as z, createElement as Ce, useCallback as _, Fragment as E, useEffect as j, useMemo as te, useImperativeHandle as Dt } from "react";
9
+ import Dt, { forwardRef as B, useRef as z, createElement as Ce, useCallback as _, Fragment as E, useEffect as w, useMemo as te, useImperativeHandle as Pt } from "react";
10
10
  import { MessageType as $, InputWithSlot as Ot, Pager as Tt, Button as N, FormLayout as R, Input as Et, Select as H, FormDualColumnLayout as oe, Checkbox as ce } from "@univerjs/design";
11
11
  import { useDependency as S } from "@wendellhu/redi/react-bindings";
12
12
  var m = function() {
@@ -27,12 +27,12 @@ var m = function() {
27
27
  e.indexOf(i[s]) < 0 && Object.prototype.propertyIsEnumerable.call(t, i[s]) && (n[i[s]] = t[i[s]]);
28
28
  return n;
29
29
  }, Re = B(function(t, e) {
30
- var n = t.icon, i = t.id, s = t.className, r = t.extend, a = $t(t, ["icon", "id", "className", "extend"]), o = "univerjs-icon univerjs-icon-".concat(i, " ").concat(s || "").trim(), d = z("_".concat(jt()));
31
- return xe(n, "".concat(i), { defIds: n.defIds, idSuffix: d.current }, m({ ref: e, className: o }, a), r);
30
+ var n = t.icon, i = t.id, s = t.className, r = t.extend, a = $t(t, ["icon", "id", "className", "extend"]), o = "univerjs-icon univerjs-icon-".concat(i, " ").concat(s || "").trim(), d = z("_".concat(wt()));
31
+ return be(n, "".concat(i), { defIds: n.defIds, idSuffix: d.current }, m({ ref: e, className: o }, a), r);
32
32
  });
33
- function xe(t, e, n, i, s) {
33
+ function be(t, e, n, i, s) {
34
34
  return Ce(t.tag, m(m({ key: e }, Nt(t, n, s)), i), (At(t, n).children || []).map(function(r, a) {
35
- return xe(r, "".concat(e, "-").concat(t.tag, "-").concat(a), n, void 0, s);
35
+ return be(r, "".concat(e, "-").concat(t.tag, "-").concat(a), n, void 0, s);
36
36
  }));
37
37
  }
38
38
  function Nt(t, e, n) {
@@ -50,27 +50,27 @@ function At(t, e) {
50
50
  return typeof s.attrs.id == "string" && i && i.indexOf(s.attrs.id) > -1 ? m(m({}, s), { attrs: m(m({}, s.attrs), { id: s.attrs.id + e.idSuffix }) }) : s;
51
51
  }) }) : t;
52
52
  }
53
- function jt() {
53
+ function wt() {
54
54
  return Math.random().toString(36).substring(2, 8);
55
55
  }
56
56
  Re.displayName = "UniverIcon";
57
- var wt = { 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" } }] }] }, Me = B(function(t, e) {
57
+ var jt = { 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" } }] }] }, xe = B(function(t, e) {
58
58
  return Ce(Re, Object.assign({}, t, {
59
59
  id: "search-single-16",
60
60
  ref: e,
61
- icon: wt
61
+ icon: jt
62
62
  }));
63
63
  });
64
- Me.displayName = "SearchSingle16";
65
- const be = "FIND_REPLACE_INPUT_FOCUS", ye = "FIND_REPLACE_DIALOG_FOCUS", Ie = "FIND_REPLACE_REPLACE_REVEALED";
64
+ xe.displayName = "SearchSingle16";
65
+ const Me = "FIND_REPLACE_INPUT_FOCUS", ye = "FIND_REPLACE_DIALOG_FOCUS", Ie = "FIND_REPLACE_REPLACE_REVEALED";
66
66
  var Lt = Object.defineProperty, Ut = Object.getOwnPropertyDescriptor, Fe = (t, e, n, i) => {
67
67
  for (var s = i > 1 ? void 0 : i ? Ut(e, n) : e, r = t.length - 1, a; r >= 0; r--)
68
68
  (a = t[r]) && (s = (i ? a(e, n, s) : a(s)) || s);
69
69
  return i && s && Lt(e, n, s), s;
70
- }, w = (t, e) => (n, i) => e(n, i, t);
71
- class Ni extends X {
70
+ }, j = (t, e) => (n, i) => e(n, i, t);
71
+ class wi extends X {
72
72
  }
73
- const v = ft("find-replace.service");
73
+ const v = pt("find-replace.service");
74
74
  function Bt(t) {
75
75
  return typeof t.findString < "u" || typeof t.inputtingFindString < "u" || typeof t.findDirection < "u" || typeof t.matchesTheWholeCell < "u" || typeof t.caseSensitive < "u" || typeof t.findScope < "u" || typeof t.findBy < "u";
76
76
  }
@@ -86,7 +86,7 @@ let K = class extends X {
86
86
  c(this, "_matches", []);
87
87
  c(this, "_currentSearchingDisposables", null);
88
88
  this._state = e, this._providers = n, this._univerInstanceService = i, this._logService = s, this.disposeWithMe(
89
- this._state.stateUpdates$.pipe(Mt(200, void 0, { leading: !0, trailing: !0 })).subscribe(async (r) => {
89
+ this._state.stateUpdates$.pipe(xt(200, void 0, { leading: !0, trailing: !0 })).subscribe(async (r) => {
90
90
  const a = this._state.state;
91
91
  Bt(r) && (a.findString !== "" && !a.replaceRevealed ? (await this._startSearching(), this._state.changeState({ findCompleted: !0 })) : r.replaceRevealed !== !0 && this._stopSearching());
92
92
  })
@@ -139,7 +139,7 @@ let K = class extends X {
139
139
  }
140
140
  // When a document's content changes, we should reset all matches and try to move to the next match.
141
141
  _subscribeToModelsChanges(e) {
142
- const n = this._currentSearchingDisposables = new ot(), i = Se(e.map((s) => s.matchesUpdate$)).pipe(bt(220)).subscribe(([...s]) => {
142
+ const n = this._currentSearchingDisposables = new ot(), i = Se(e.map((s) => s.matchesUpdate$)).pipe(Mt(220)).subscribe(([...s]) => {
143
143
  const r = this._matches = s.flat();
144
144
  if (r.length) {
145
145
  const a = this._moveToInitialMatch(this._findModels, r, !0);
@@ -202,8 +202,8 @@ let K = class extends X {
202
202
  const r = e.find((u) => u.unitId === s);
203
203
  if (r) {
204
204
  this._matchingModel = r;
205
- const u = r.moveToNextMatch({ stayIfOnMatch: !0, noFocus: i }), p = n.findIndex((f) => f === u);
206
- return this.currentMatch$.next(u), p;
205
+ const u = r.moveToNextMatch({ stayIfOnMatch: !0, noFocus: i }), f = n.findIndex((p) => p === u);
206
+ return this.currentMatch$.next(u), f;
207
207
  }
208
208
  this._matchingModel = e[0];
209
209
  const a = this._matchingModel.moveToNextMatch({ noFocus: i }), o = this._matches.findIndex((u) => u === a);
@@ -211,8 +211,8 @@ let K = class extends X {
211
211
  }
212
212
  };
213
213
  K = Fe([
214
- w(2, he),
215
- w(3, ue)
214
+ j(2, he),
215
+ j(3, ue)
216
216
  ], K);
217
217
  var Y = /* @__PURE__ */ ((t) => (t.ROW = "row", t.COLUMN = "column", t))(Y || {}), Z = /* @__PURE__ */ ((t) => (t.VALUE = "value", t.FORMULA = "formula", t))(Z || {}), J = /* @__PURE__ */ ((t) => (t.SUBUNIT = "subunit", t.UNIT = "unit", t))(J || {});
218
218
  function ie() {
@@ -422,33 +422,33 @@ let Q = class extends X {
422
422
  }
423
423
  };
424
424
  Q = Fe([
425
- w(0, y(_e)),
426
- w(1, U)
425
+ j(0, y(_e)),
426
+ j(1, U)
427
427
  ], Q);
428
428
  const W = {
429
429
  id: "ui.operation.open-find-dialog",
430
- type: b.OPERATION,
430
+ type: M.OPERATION,
431
431
  handler: (t) => {
432
432
  const e = t.get(v);
433
433
  return e.revealed ? e.focusFindInput() : e.start(), !0;
434
434
  }
435
435
  }, ne = {
436
436
  id: "ui.operation.open-replace-dialog",
437
- type: b.OPERATION,
437
+ type: M.OPERATION,
438
438
  handler: (t) => {
439
439
  const e = t.get(v);
440
440
  return e.revealed ? e.replaceRevealed ? e.focusFindInput() : e.revealReplace() : e.start(!0), !0;
441
441
  }
442
- }, Pe = {
443
- type: b.OPERATION,
442
+ }, De = {
443
+ type: M.OPERATION,
444
444
  id: "ui.operation.go-to-next-match",
445
445
  handler: (t) => (t.get(v).moveToNextMatch(), !0)
446
- }, De = {
447
- type: b.OPERATION,
446
+ }, Pe = {
447
+ type: M.OPERATION,
448
448
  id: "ui.operation.go-to-previous-match",
449
449
  handler: (t) => (t.get(v).moveToPreviousMatch(), !0)
450
450
  };
451
- var Oe = { exports: {} }, G = {};
451
+ var Oe = { exports: {} }, k = {};
452
452
  /**
453
453
  * @license React
454
454
  * react-jsx-runtime.production.min.js
@@ -458,7 +458,7 @@ var Oe = { exports: {} }, G = {};
458
458
  * This source code is licensed under the MIT license found in the
459
459
  * LICENSE file in the root directory of this source tree.
460
460
  */
461
- var Gt = Pt, kt = Symbol.for("react.element"), Vt = Symbol.for("react.fragment"), Ht = Object.prototype.hasOwnProperty, qt = Gt.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, zt = { key: !0, ref: !0, __self: !0, __source: !0 };
461
+ var kt = Dt, Gt = Symbol.for("react.element"), Vt = Symbol.for("react.fragment"), Ht = Object.prototype.hasOwnProperty, qt = kt.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, zt = { key: !0, ref: !0, __self: !0, __source: !0 };
462
462
  function Te(t, e, n) {
463
463
  var i, s = {}, r = null, a = null;
464
464
  n !== void 0 && (r = "" + n), e.key !== void 0 && (r = "" + e.key), e.ref !== void 0 && (a = e.ref);
@@ -467,22 +467,22 @@ function Te(t, e, n) {
467
467
  if (t && t.defaultProps)
468
468
  for (i in e = t.defaultProps, e)
469
469
  s[i] === void 0 && (s[i] = e[i]);
470
- return { $$typeof: kt, type: t, key: r, ref: a, props: s, _owner: qt.current };
470
+ return { $$typeof: Gt, type: t, key: r, ref: a, props: s, _owner: qt.current };
471
471
  }
472
- G.Fragment = Vt;
473
- G.jsx = Te;
474
- G.jsxs = Te;
475
- Oe.exports = G;
472
+ k.Fragment = Vt;
473
+ k.jsx = Te;
474
+ k.jsxs = Te;
475
+ Oe.exports = k;
476
476
  var l = Oe.exports;
477
477
  const Ee = {
478
478
  id: "ui.command.replace-current-match",
479
- type: b.COMMAND,
479
+ type: M.COMMAND,
480
480
  handler: (t) => t.get(v).replace()
481
481
  }, Kt = "CONFIRM_REPLACE_ALL", $e = {
482
482
  id: "ui.command.replace-all-matches",
483
- type: b.COMMAND,
483
+ type: M.COMMAND,
484
484
  handler: async (t) => {
485
- const e = t.get(pt), n = t.get(P), i = t.get(ge);
485
+ const e = t.get(ft), n = t.get(D), i = t.get(ge);
486
486
  if (!await e.confirm({
487
487
  id: Kt,
488
488
  title: { title: n.t("find-replace.replace.confirm.title") },
@@ -504,7 +504,7 @@ const Ee = {
504
504
  }
505
505
  };
506
506
  function Ne(t) {
507
- const { findCompleted: e, localeService: n, matchesCount: i, matchesPosition: s, findString: r, findReplaceService: a, onChange: o, ...d } = t, p = e && i === 0 ? n.t("find-replace.dialog.no-result") : i === 0 ? " " : void 0;
507
+ const { findCompleted: e, localeService: n, matchesCount: i, matchesPosition: s, findString: r, findReplaceService: a, onChange: o, ...d } = t, f = e && i === 0 ? n.t("find-replace.dialog.no-result") : i === 0 ? " " : void 0;
508
508
  return /* @__PURE__ */ l.jsx(
509
509
  Ot,
510
510
  {
@@ -514,16 +514,16 @@ function Ne(t) {
514
514
  Tt,
515
515
  {
516
516
  loop: !0,
517
- text: p,
517
+ text: f,
518
518
  value: s,
519
519
  total: i,
520
- onChange: (f) => {
521
- s === i && f === 1 ? a.moveToNextMatch() : s === 1 && f === i || f < s ? a.moveToPreviousMatch() : a.moveToNextMatch();
520
+ onChange: (p) => {
521
+ s === i && p === 1 ? a.moveToNextMatch() : s === 1 && p === i || p < s ? a.moveToPreviousMatch() : a.moveToNextMatch();
522
522
  }
523
523
  }
524
524
  ),
525
525
  value: r,
526
- onChange: (f) => o == null ? void 0 : o(f),
526
+ onChange: (p) => o == null ? void 0 : o(p),
527
527
  ...d
528
528
  }
529
529
  );
@@ -543,13 +543,13 @@ function Ae(t, e) {
543
543
  const s = document.querySelectorAll(".univer-find-replace-dialog-container .univer-select-selection-search-input");
544
544
  return Array.from(s).some((r) => r === document.activeElement);
545
545
  }, []);
546
- return Dt(e, () => ({ focus: n, selectHasFocus: i })), j(() => {
546
+ return Pt(e, () => ({ focus: n, selectHasFocus: i })), w(() => {
547
547
  const s = t.focusSignal$.subscribe(() => n());
548
548
  return () => s.unsubscribe();
549
549
  }, [t, n]), { focus: n, selectHasFocus: i };
550
550
  }
551
551
  const ei = B(function(e, n) {
552
- const i = S(P), s = S(v), r = S(ee), a = I(s.state$, void 0, !0), { findCompleted: o, findString: d, matchesCount: u, matchesPosition: p } = a, f = _(() => {
552
+ const i = S(D), s = S(v), r = S(ee), a = I(s.state$, void 0, !0), { findCompleted: o, findString: d, matchesCount: u, matchesPosition: f } = a, p = _(() => {
553
553
  r.executeCommand(ne.id);
554
554
  }, [r]), O = _((C) => s.changeFindString(C), [s]);
555
555
  return Ae(s, n), /* @__PURE__ */ l.jsxs(E, { children: [
@@ -559,29 +559,29 @@ const ei = B(function(e, n) {
559
559
  findCompleted: o,
560
560
  className: "univer-find-input",
561
561
  matchesCount: u,
562
- matchesPosition: p,
562
+ matchesPosition: f,
563
563
  findReplaceService: s,
564
564
  localeService: i,
565
565
  findString: d,
566
566
  onChange: O
567
567
  }
568
568
  ),
569
- /* @__PURE__ */ l.jsx("div", { className: L.findReplaceExpandContainer, children: /* @__PURE__ */ l.jsx(N, { type: "text", size: "small", onClick: f, children: i.t("find-replace.dialog.advanced-finding") }) })
569
+ /* @__PURE__ */ l.jsx("div", { className: L.findReplaceExpandContainer, children: /* @__PURE__ */ l.jsx(N, { type: "text", size: "small", onClick: p, children: i.t("find-replace.dialog.advanced-finding") }) })
570
570
  ] });
571
571
  }), ti = B(function(e, n) {
572
- const i = S(v), s = S(P), r = S(ee), a = S(ge), o = I(i.currentMatch$, void 0, !0), d = I(i.replaceables$, void 0, !0), u = I(i.state$, void 0, !0), {
573
- matchesCount: p,
574
- matchesPosition: f,
572
+ const i = S(v), s = S(D), r = S(ee), a = S(ge), o = I(i.currentMatch$, void 0, !0), d = I(i.replaceables$, void 0, !0), u = I(i.state$, void 0, !0), {
573
+ matchesCount: f,
574
+ matchesPosition: p,
575
575
  findString: O,
576
576
  inputtingFindString: C,
577
577
  replaceString: Le,
578
578
  caseSensitive: Ue,
579
579
  matchesTheWholeCell: Be,
580
580
  findDirection: We,
581
- findScope: Ge,
582
- findBy: ke,
581
+ findScope: ke,
582
+ findBy: Ge,
583
583
  findCompleted: V
584
- } = u, Ve = C.length === 0, He = p === 0 || !(o != null && o.replaceable), qe = d.length === 0, ze = _(
584
+ } = u, Ve = C.length === 0, He = f === 0 || !(o != null && o.replaceable), qe = d.length === 0, ze = _(
585
585
  (h) => i.changeInputtingFindString(h),
586
586
  [i]
587
587
  ), Ke = _(
@@ -598,22 +598,22 @@ const ei = B(function(e, n) {
598
598
  }, [i]), tt = _((h) => {
599
599
  i.changeFindBy(h);
600
600
  }, [i]), it = ni(s), nt = si(s), st = ri(s);
601
- return j(() => {
602
- const h = V && p === 0;
601
+ return w(() => {
602
+ const h = V && f === 0;
603
603
  let T = null;
604
604
  return h && (T = a.show({
605
605
  content: s.t("find-replace.dialog.no-match"),
606
606
  type: $.Warning,
607
607
  delay: 5e3
608
608
  })), () => T == null ? void 0 : T.dispose();
609
- }, [V, p, a, s]), /* @__PURE__ */ l.jsxs(E, { children: [
609
+ }, [V, f, a, s]), /* @__PURE__ */ l.jsxs(E, { children: [
610
610
  /* @__PURE__ */ l.jsx(R, { label: s.t("find-replace.dialog.find"), children: /* @__PURE__ */ l.jsx(
611
611
  Ne,
612
612
  {
613
613
  findCompleted: V,
614
614
  className: "univer-find-input",
615
- matchesCount: p,
616
- matchesPosition: f,
615
+ matchesCount: f,
616
+ matchesPosition: p,
617
617
  findReplaceService: i,
618
618
  localeService: s,
619
619
  findString: C,
@@ -630,8 +630,8 @@ const ei = B(function(e, n) {
630
630
  ) }),
631
631
  /* @__PURE__ */ l.jsx(R, { label: s.t("find-replace.dialog.find-direction.title"), children: /* @__PURE__ */ l.jsx(H, { value: We, options: nt, onChange: Xe }) }),
632
632
  /* @__PURE__ */ l.jsx(oe, { children: /* @__PURE__ */ l.jsxs(E, { children: [
633
- /* @__PURE__ */ l.jsx(R, { label: s.t("find-replace.dialog.find-scope.title"), children: /* @__PURE__ */ l.jsx(H, { value: Ge, options: it, onChange: et }) }),
634
- /* @__PURE__ */ l.jsx(R, { label: s.t("find-replace.dialog.find-by.title"), children: /* @__PURE__ */ l.jsx(H, { value: ke, options: st, onChange: tt }) })
633
+ /* @__PURE__ */ l.jsx(R, { label: s.t("find-replace.dialog.find-scope.title"), children: /* @__PURE__ */ l.jsx(H, { value: ke, options: it, onChange: et }) }),
634
+ /* @__PURE__ */ l.jsx(R, { label: s.t("find-replace.dialog.find-by.title"), children: /* @__PURE__ */ l.jsx(H, { value: Ge, options: st, onChange: tt }) })
635
635
  ] }) }),
636
636
  /* @__PURE__ */ l.jsx(oe, { children: /* @__PURE__ */ l.jsxs(E, { children: [
637
637
  /* @__PURE__ */ l.jsx(R, { children: /* @__PURE__ */ l.jsx(
@@ -666,7 +666,7 @@ const ei = B(function(e, n) {
666
666
  });
667
667
  function ii() {
668
668
  const t = S(v), e = S(me), n = S(U), i = I(t.state$, void 0, !0), s = z(null);
669
- j(() => {
669
+ w(() => {
670
670
  let d;
671
671
  return s.current && (d = e.registerContainerElement(s.current)), () => d == null ? void 0 : d.dispose();
672
672
  }, [e]);
@@ -674,14 +674,14 @@ function ii() {
674
674
  (d) => n.setContextValue(ye, d),
675
675
  [n]
676
676
  ), o = _(
677
- (d) => n.setContextValue(be, d),
677
+ (d) => n.setContextValue(Me, d),
678
678
  [n]
679
679
  );
680
- return j(() => {
680
+ return w(() => {
681
681
  var u;
682
- const d = yt(document, "focusin").subscribe((p) => {
683
- var f;
684
- p.target && ((f = s.current) != null && f.contains(p.target)) ? a(!0) : a(!1), !r.current || !r.current.selectHasFocus() ? o(!0) : o(!1);
682
+ const d = yt(document, "focusin").subscribe((f) => {
683
+ var p;
684
+ f.target && ((p = s.current) != null && p.contains(f.target)) ? a(!0) : a(!1), !r.current || !r.current.selectHasFocus() ? o(!0) : o(!1);
685
685
  });
686
686
  return (u = r.current) == null || u.focus(), a(!0), o(!0), () => {
687
687
  d.unsubscribe(), a(!1);
@@ -709,64 +709,64 @@ function ri(t) {
709
709
  { label: t.t("find-replace.dialog.find-by.formula"), value: Z.FORMULA }
710
710
  ], [e]);
711
711
  }
712
- function D(t) {
712
+ function P(t) {
713
713
  return t.getContextValue(ye);
714
714
  }
715
715
  function ai(t) {
716
716
  return t.getContextValue(Ie);
717
717
  }
718
- function je(t) {
719
- return t.getContextValue(be);
718
+ function we(t) {
719
+ return t.getContextValue(Me);
720
720
  }
721
- const k = "7_find-replace-shortcuts";
721
+ const G = "7_find-replace-shortcuts";
722
722
  function se(t) {
723
- return t.getContextValue(fe);
723
+ return t.getContextValue(pe);
724
724
  }
725
725
  function re(t) {
726
- return !t.getContextValue(pe);
726
+ return !t.getContextValue(fe);
727
727
  }
728
728
  const oi = {
729
729
  id: W.id,
730
730
  description: "find-replace.shortcut.open-find-dialog",
731
- binding: x.F | M.CTRL_COMMAND,
732
- group: k,
731
+ binding: b.F | x.CTRL_COMMAND,
732
+ group: G,
733
733
  preconditions(t) {
734
- return !D(t) && se(t) && re(t);
734
+ return !P(t) && se(t) && re(t);
735
735
  }
736
736
  }, ci = {
737
737
  id: W.id,
738
738
  description: "find-replace.shortcut.open-find-dialog",
739
- binding: x.F | M.CTRL_COMMAND,
740
- mac: x.F | M.MAC_CTRL,
739
+ binding: b.F | x.CTRL_COMMAND,
740
+ mac: b.F | x.MAC_CTRL,
741
741
  preconditions(t) {
742
- return !D(t) && se(t) && re(t);
742
+ return !P(t) && se(t) && re(t);
743
743
  }
744
744
  }, li = {
745
745
  id: ne.id,
746
746
  description: "find-replace.shortcut.open-replace-dialog",
747
- binding: x.H | M.CTRL_COMMAND,
748
- mac: x.H | M.MAC_CTRL,
749
- group: k,
747
+ binding: b.H | x.CTRL_COMMAND,
748
+ mac: b.H | x.MAC_CTRL,
749
+ group: G,
750
750
  preconditions(t) {
751
- return se(t) && re(t) && (!D(t) || !ai(t));
751
+ return se(t) && re(t) && (!P(t) || !ai(t));
752
752
  }
753
753
  }, di = {
754
- id: Pe.id,
754
+ id: De.id,
755
755
  description: "find-replace.shortcut.go-to-next-match",
756
- binding: x.ENTER,
757
- group: k,
756
+ binding: b.ENTER,
757
+ group: G,
758
758
  priority: 1e3,
759
759
  preconditions(t) {
760
- return je(t) && D(t);
760
+ return we(t) && P(t);
761
761
  }
762
762
  }, hi = {
763
- id: De.id,
763
+ id: Pe.id,
764
764
  description: "find-replace.shortcut.go-to-previous-match",
765
- binding: x.ENTER | M.SHIFT,
766
- group: k,
765
+ binding: b.ENTER | x.SHIFT,
766
+ group: G,
767
767
  priority: 1e3,
768
768
  preconditions(t) {
769
- return je(t) && D(t);
769
+ return we(t) && P(t);
770
770
  }
771
771
  };
772
772
  function ui(t) {
@@ -780,27 +780,27 @@ function ui(t) {
780
780
  positions: [mt.TOOLBAR_START],
781
781
  hidden$: vt(t, ct.SHEET),
782
782
  disabled$: Se([
783
- e.subscribeContextValue$(pe),
784
- e.subscribeContextValue$(fe)
783
+ e.subscribeContextValue$(fe),
784
+ e.subscribeContextValue$(pe)
785
785
  ]).pipe(It(([n, i]) => n || !i))
786
786
  };
787
787
  }
788
- var fi = Object.defineProperty, pi = Object.getOwnPropertyDescriptor, _i = (t, e, n, i) => {
789
- for (var s = i > 1 ? void 0 : i ? pi(e, n) : e, r = t.length - 1, a; r >= 0; r--)
788
+ var pi = Object.defineProperty, fi = Object.getOwnPropertyDescriptor, _i = (t, e, n, i) => {
789
+ for (var s = i > 1 ? void 0 : i ? fi(e, n) : e, r = t.length - 1, a; r >= 0; r--)
790
790
  (a = t[r]) && (s = (i ? a(e, n, s) : a(s)) || s);
791
- return i && s && fi(e, n, s), s;
791
+ return i && s && pi(e, n, s), s;
792
792
  }, g = (t, e) => (n, i) => e(n, i, t);
793
- const le = "DESKTOP_FIND_REPLACE_DIALOG", we = 350, gi = 20, mi = -90;
793
+ const le = "DESKTOP_FIND_REPLACE_DIALOG", je = 350, gi = 20, mi = -90;
794
794
  let A = class extends lt {
795
- constructor(t, e, n, i, s, r, a, o, d, u, p, f) {
796
- super(), this._univerInstanceService = t, this._menuService = e, this._shortcutService = n, this._commandService = i, this._findReplaceService = s, this._logService = r, this._dialogService = a, this._contextService = o, this._layoutService = d, this._localeService = u, this._componentManager = p, this._injector = f, this._initCommands(), this._initUI(), this._initShortcuts();
795
+ constructor(t, e, n, i, s, r, a, o, d, u, f, p) {
796
+ super(), this._univerInstanceService = t, this._menuService = e, this._shortcutService = n, this._commandService = i, this._findReplaceService = s, this._logService = r, this._dialogService = a, this._contextService = o, this._layoutService = d, this._localeService = u, this._componentManager = f, this._injector = p, this._initCommands(), this._initUI(), this._initShortcuts();
797
797
  }
798
798
  _initCommands() {
799
799
  [
800
800
  W,
801
801
  ne,
802
- Pe,
803
802
  De,
803
+ Pe,
804
804
  $e,
805
805
  Ee
806
806
  ].forEach((t) => {
@@ -817,7 +817,7 @@ let A = class extends lt {
817
817
  ].forEach((t) => this.disposeWithMe(this._shortcutService.registerShortcut(t)));
818
818
  }
819
819
  _initUI() {
820
- this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(ui))), this.disposeWithMe(this._componentManager.register("FindReplaceDialog", ii)), this.disposeWithMe(this._componentManager.register("SearchIcon", Me)), this._findReplaceService.stateUpdates$.pipe(ae(this.dispose$)).subscribe((t) => {
820
+ this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(ui))), this.disposeWithMe(this._componentManager.register("FindReplaceDialog", ii)), this.disposeWithMe(this._componentManager.register("SearchIcon", xe)), this._findReplaceService.stateUpdates$.pipe(ae(this.dispose$)).subscribe((t) => {
821
821
  t.revealed === !0 && this._openPanel();
822
822
  }), this.disposeWithMe(
823
823
  this._univerInstanceService.focused$.pipe(ae(this.dispose$)).subscribe((t) => {
@@ -829,7 +829,7 @@ let A = class extends lt {
829
829
  this._dialogService.open({
830
830
  id: le,
831
831
  draggable: !0,
832
- width: we,
832
+ width: je,
833
833
  title: { title: this._localeService.t("find-replace.dialog.title") },
834
834
  children: { label: "FindReplaceDialog" },
835
835
  destroyOnClose: !0,
@@ -850,18 +850,65 @@ A = _i([
850
850
  g(3, ee),
851
851
  g(4, v),
852
852
  g(5, ue),
853
- g(6, xt),
853
+ g(6, bt),
854
854
  g(7, U),
855
855
  g(8, me),
856
- g(9, y(P)),
856
+ g(9, y(D)),
857
857
  g(10, y(St)),
858
858
  g(11, y(_e))
859
859
  ], A);
860
860
  function vi() {
861
861
  const { innerWidth: t } = window;
862
- return { x: (t - we) / 2 - gi, y: mi };
862
+ return { x: (t - je) / 2 - gi, y: mi };
863
863
  }
864
864
  const Si = {
865
+ "find-replace": {
866
+ toolbar: "Find & Replace",
867
+ shortcut: {
868
+ "open-find-dialog": "Open Find Dialog",
869
+ "open-replace-dialog": "Open Replace Dialog",
870
+ "close-dialog": "Close Find & Replace Dialog",
871
+ "go-to-next-match": "Go to Next Match",
872
+ "go-to-previous-match": "Go to Previous Match"
873
+ },
874
+ dialog: {
875
+ title: "Find",
876
+ find: "Find",
877
+ replace: "Replace",
878
+ "replace-all": "Replace All",
879
+ "case-sensitive": "Case Sensitive",
880
+ "find-placeholder": "Find in this Sheet",
881
+ "advanced-finding": "Advanced Searching & Replace",
882
+ "replace-placeholder": "Input Replace String",
883
+ "match-the-whole-cell": "Match the Whole Cell",
884
+ "find-direction": {
885
+ title: "Find Direction",
886
+ row: "Search by Row",
887
+ column: "Search by Column"
888
+ },
889
+ "find-scope": {
890
+ title: "Find Range",
891
+ "current-sheet": "Current Sheet",
892
+ workbook: "Workbook"
893
+ },
894
+ "find-by": {
895
+ title: "Find By",
896
+ value: "Find by Value",
897
+ formula: "Find Formula"
898
+ },
899
+ "no-match": "Finding completed but no match found.",
900
+ "no-result": "No Result"
901
+ },
902
+ replace: {
903
+ "all-success": "Replaced all {0} matches",
904
+ "all-failure": "Replace failed",
905
+ confirm: {
906
+ title: "Are you sure to replace all matches?"
907
+ }
908
+ }
909
+ },
910
+ "find-replace-shortcuts": "Find & Replace"
911
+ }, ji = Si, Ci = {
865
912
  "find-replace": {
866
913
  toolbar: "查找替换",
867
914
  shortcut: {
@@ -908,17 +955,17 @@ const Si = {
908
955
  }
909
956
  },
910
957
  "find-replace-shortcuts": "查找替换"
911
- };
912
- var Ci = Object.defineProperty, Ri = Object.getOwnPropertyDescriptor, xi = (t, e, n, i) => {
913
- for (var s = i > 1 ? void 0 : i ? Ri(e, n) : e, r = t.length - 1, a; r >= 0; r--)
958
+ }, Ri = Ci;
959
+ var bi = Object.defineProperty, xi = Object.getOwnPropertyDescriptor, Mi = (t, e, n, i) => {
960
+ for (var s = i > 1 ? void 0 : i ? xi(e, n) : e, r = t.length - 1, a; r >= 0; r--)
914
961
  (a = t[r]) && (s = (i ? a(e, n, s) : a(s)) || s);
915
- return i && s && Ci(e, n, s), s;
916
- }, Mi = (t, e) => (n, i) => e(n, i, t);
917
- const bi = "FIND_REPLACE";
962
+ return i && s && bi(e, n, s), s;
963
+ }, yi = (t, e) => (n, i) => e(n, i, t);
964
+ const Ii = "FIND_REPLACE";
918
965
  let de = class extends ut {
919
966
  constructor(t, e) {
920
- super(bi), this._injector = t, this._localeService = e, this._localeService.load({
921
- zhCN: Si
967
+ super(Ii), this._injector = t, this._localeService = e, this._localeService.load({
968
+ zhCN: Ri
922
969
  });
923
970
  }
924
971
  onStarting(t) {
@@ -929,15 +976,17 @@ let de = class extends ut {
929
976
  );
930
977
  }
931
978
  };
932
- de = xi([
933
- Mi(1, y(P))
979
+ de = Mi([
980
+ yi(1, y(D))
934
981
  ], de);
935
982
  export {
936
983
  Z as FindBy,
937
984
  Y as FindDirection,
938
- Ni as FindModel,
985
+ wi as FindModel,
939
986
  A as FindReplaceController,
940
987
  J as FindScope,
941
988
  v as IFindReplaceService,
942
- de as UniverFindReplacePlugin
989
+ de as UniverFindReplacePlugin,
990
+ ji as enUS,
991
+ Ri as zhCN
943
992
  };
@@ -17,3 +17,4 @@ export { UniverFindReplacePlugin } from './plugin';
17
17
  export { FindReplaceController } from './controllers/find-replace.controller';
18
18
  export type { IFindComplete, IFindMoveParams, IFindMatch, IFindQuery, IFindReplaceProvider, IReplaceAllResult, } from './services/find-replace.service';
19
19
  export { FindModel, IFindReplaceService, FindBy, FindScope, FindDirection } from './services/find-replace.service';
20
+ export { enUS, zhCN } from './locale';
package/lib/umd/index.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(u,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/engine-render"),require("react"),require("@univerjs/design"),require("@wendellhu/redi/react-bindings")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","@univerjs/ui","rxjs","@univerjs/engine-render","react","@univerjs/design","@wendellhu/redi/react-bindings"],o):(u=typeof globalThis<"u"?globalThis:u||self,o(u.UniverFindReplace={},u.UniverCore,u["@wendellhu/redi"],u.UniverUi,u.rxjs,u.UniverEngineRender,u.React,u.UniverDesign,u["@wendellhu/redi/react-bindings"]))})(this,function(u,o,R,f,S,le,l,p,I){"use strict";var St=Object.defineProperty;var Ct=(u,o,R)=>o in u?St(u,o,{enumerable:!0,configurable:!0,writable:!0,value:R}):u[o]=R;var h=(u,o,R)=>(Ct(u,typeof o!="symbol"?o+"":o,R),R);var b=function(){return b=Object.assign||function(n){for(var e,i=1,t=arguments.length;i<t;i++){e=arguments[i];for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&(n[s]=e[s])}return n},b.apply(this,arguments)},de=function(n,e){var i={};for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&e.indexOf(t)<0&&(i[t]=n[t]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,t=Object.getOwnPropertySymbols(n);s<t.length;s++)e.indexOf(t[s])<0&&Object.prototype.propertyIsEnumerable.call(n,t[s])&&(i[t[s]]=n[t[s]]);return i},K=l.forwardRef(function(n,e){var i=n.icon,t=n.id,s=n.className,a=n.extend,r=de(n,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(t," ").concat(s||"").trim(),_=l.useRef("_".concat(fe()));return $(i,"".concat(t),{defIds:i.defIds,idSuffix:_.current},b({ref:e,className:c},r),a)});function $(n,e,i,t,s){return l.createElement(n.tag,b(b({key:e},he(n,i,s)),t),(ue(n,i).children||[]).map(function(a,r){return $(a,"".concat(e,"-").concat(n.tag,"-").concat(r),i,void 0,s)}))}function he(n,e,i){var t=b({},n.attrs);i!=null&&i.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=i.colorChannel1);var s=e.defIds;return!s||s.length===0||(n.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+e.idSuffix),Object.entries(t).forEach(function(a){var r=a[0],c=a[1];typeof c=="string"&&(t[r]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),t}function ue(n,e){var i,t=e.defIds;return!t||t.length===0?n:n.tag==="defs"&&(!((i=n.children)===null||i===void 0)&&i.length)?b(b({},n),{children:n.children.map(function(s){return typeof s.attrs.id=="string"&&t&&t.indexOf(s.attrs.id)>-1?b(b({},s),{attrs:b(b({},s.attrs),{id:s.attrs.id+e.idSuffix})}):s})}):n}function fe(){return Math.random().toString(36).substring(2,8)}K.displayName="UniverIcon";var pe={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"}}]}]},z=l.forwardRef(function(n,e){return l.createElement(K,Object.assign({},n,{id:"search-single-16",ref:e,icon:pe}))});z.displayName="SearchSingle16";const Y="FIND_REPLACE_INPUT_FOCUS",Z="FIND_REPLACE_DIALOG_FOCUS",J="FIND_REPLACE_REPLACE_REVEALED";var _e=Object.defineProperty,ge=Object.getOwnPropertyDescriptor,Q=(n,e,i,t)=>{for(var s=t>1?void 0:t?ge(e,i):e,a=n.length-1,r;a>=0;a--)(r=n[a])&&(s=(t?r(e,i,s):r(s))||s);return t&&s&&_e(e,i,s),s},O=(n,e)=>(i,t)=>e(i,t,n);class me extends o.Disposable{}const y=R.createIdentifier("find-replace.service");function ve(n){return typeof n.findString<"u"||typeof n.inputtingFindString<"u"||typeof n.findDirection<"u"||typeof n.matchesTheWholeCell<"u"||typeof n.caseSensitive<"u"||typeof n.findScope<"u"||typeof n.findBy<"u"}let U=class extends o.Disposable{constructor(e,i,t,s){super();h(this,"currentMatch$",new S.BehaviorSubject(null));h(this,"replaceables$",new S.BehaviorSubject([]));h(this,"_findModels",[]);h(this,"_matchingModel",null);h(this,"_matches",[]);h(this,"_currentSearchingDisposables",null);this._state=e,this._providers=i,this._univerInstanceService=t,this._logService=s,this.disposeWithMe(this._state.stateUpdates$.pipe(S.throttleTime(200,void 0,{leading:!0,trailing:!0})).subscribe(async a=>{const r=this._state.state;ve(a)&&(r.findString!==""&&!r.replaceRevealed?(await this._startSearching(),this._state.changeState({findCompleted:!0})):a.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),i=this._findModels=(await Promise.all(e.map(a=>a.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(i);const t=this._matches=i.map(a=>a.getMatches()).flat();if(this.replaceables$.next(t.filter(a=>a.replaceable)),!t.length)return this._state.changeState({matchesCount:0,matchesPosition:0}),{results:[]};const s=this._moveToInitialMatch(i,t);return this._state.changeState({matchesCount:t.length,matchesPosition:s+1}),{results:t}}_stopSearching(){var e;this._providers.forEach(i=>i.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 i=this._currentSearchingDisposables=new o.DisposableCollection,t=S.combineLatest(e.map(s=>s.matchesUpdate$)).pipe(S.debounceTime(220)).subscribe(([...s])=>{const a=this._matches=s.flat();if(a.length){const r=this._moveToInitialMatch(this._findModels,a,!0);this._state.changeState({matchesCount:a.length,matchesPosition:r+1}),this.replaceables$.next(a.filter(c=>c.replaceable))}else this._state.changeState({matchesCount:0,matchesPosition:0}),this.replaceables$.next([])});e.forEach(s=>i.add(o.toDisposable(s.activelyChangingMatch$.subscribe(a=>{const r=this._matches.findIndex(c=>c===a);this._state.changeState({matchesPosition:r+1})})))),i.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(i=>i.replaceAll(this._state.replaceString))).then(i=>i.reduce((t,s)=>(t.success+=s.success,t.failure+=s.failure,t),{success:0,failure:0}));return e.failure===0&&this._stopSearching(),e}getCurrentMatch(){return this._state.matchesPosition>0?this._matches[this._state.matchesPosition-1]:null}moveToNextMatch(){if(!this._matchingModel)return;const e=this._findModels.length===1,i=this._matchingModel.moveToNextMatch({loop:e});if(i){const t=this._matches.findIndex(s=>s===i);this.currentMatch$.next(i),this._state.changeState({matchesPosition:t+1})}else{const t=this._findModels.findIndex(c=>c===this._matchingModel),s=this._findModels[(t+1)%this._findModels.length],a=s.moveToNextMatch(),r=this._matches.findIndex(c=>c===a);this.currentMatch$.next(a),this._matchingModel=s,this._state.changeState({matchesPosition:r+1})}}moveToPreviousMatch(){if(!this._matchingModel)return;const e=this._findModels.length===1,i=this._matchingModel.moveToPreviousMatch({loop:e});if(i){const t=this._matches.findIndex(s=>s===i);this.currentMatch$.next(i),this._state.changeState({matchesPosition:t+1})}else{const t=this._findModels.findIndex(c=>c===this._matchingModel),s=this._findModels[(t-1+this._findModels.length)%this._findModels.length],a=s.moveToPreviousMatch(),r=this._matches.findIndex(c=>c===a);this.currentMatch$.next(a),this._matchingModel=s,this._state.changeState({matchesPosition:r+1})}}_moveToInitialMatch(e,i,t=!1){var _;const s=(_=this._univerInstanceService.getFocusedUniverInstance())==null?void 0:_.getUnitId();if(!s)return-1;const a=e.find(m=>m.unitId===s);if(a){this._matchingModel=a;const m=a.moveToNextMatch({stayIfOnMatch:!0,noFocus:t}),C=i.findIndex(v=>v===m);return this.currentMatch$.next(m),C}this._matchingModel=e[0];const r=this._matchingModel.moveToNextMatch({noFocus:t}),c=this._matches.findIndex(m=>m===r);return this.currentMatch$.next(r),c}};U=Q([O(2,o.IUniverInstanceService),O(3,o.ILogService)],U);var T=(n=>(n.ROW="row",n.COLUMN="column",n))(T||{}),P=(n=>(n.VALUE="value",n.FORMULA="formula",n))(P||{}),E=(n=>(n.SUBUNIT="subunit",n.UNIT="unit",n))(E||{});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 Se{constructor(){h(this,"_stateUpdates$",new S.Subject);h(this,"stateUpdates$",this._stateUpdates$.asObservable());h(this,"_state$",new S.BehaviorSubject(B()));h(this,"state$",this._state$.asObservable());h(this,"_findString","");h(this,"_inputtingFindString","");h(this,"_replaceString","");h(this,"_revealed",!1);h(this,"_replaceRevealed",!1);h(this,"_matchesPosition",0);h(this,"_matchesCount",0);h(this,"_caseSensitive",!0);h(this,"_matchesTheWholeCell",!1);h(this,"_findDirection","row");h(this,"_findScope","subunit");h(this,"_findBy","value");h(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 i=!1;const t={};typeof e.findString<"u"&&e.findString!==this._findString&&(this._findString=e.findString,t.findString=this._findString,i=!0),typeof e.revealed<"u"&&e.revealed!==this._revealed&&(this._revealed=e.revealed,t.revealed=e.revealed,i=!0),typeof e.replaceRevealed<"u"&&e.replaceRevealed!==this._replaceRevealed&&(this._replaceRevealed=e.replaceRevealed,t.replaceRevealed=e.replaceRevealed,i=!0),typeof e.replaceString<"u"&&e.replaceString!==this._replaceString&&(this._replaceString=e.replaceString,t.replaceString=e.replaceString,i=!0),typeof e.matchesCount<"u"&&e.matchesCount!==this._matchesCount&&(this._matchesCount=e.matchesCount,t.matchesCount=e.matchesCount,i=!0),typeof e.matchesPosition<"u"&&e.matchesPosition!==this._matchesPosition&&(this._matchesPosition=e.matchesPosition,t.matchesPosition=e.matchesPosition,i=!0),typeof e.findBy<"u"&&e.findBy!==this._findBy&&(this._findBy=e.findBy,t.findBy=e.findBy,i=!0),typeof e.findScope<"u"&&e.findScope!==this._findScope&&(this._findScope=e.findScope,t.findScope=e.findScope,i=!0),typeof e.findDirection<"u"&&e.findDirection!==this._findDirection&&(this._findDirection=e.findDirection,t.findDirection=e.findDirection,i=!0),typeof e.caseSensitive<"u"&&e.caseSensitive!==this._caseSensitive&&(this._caseSensitive=e.caseSensitive,t.caseSensitive=e.caseSensitive,i=!0),typeof e.matchesTheWholeCell<"u"&&e.matchesTheWholeCell!==this._matchesTheWholeCell&&(this._matchesTheWholeCell=e.matchesTheWholeCell,t.matchesTheWholeCell=e.matchesTheWholeCell,i=!0),typeof e.inputtingFindString<"u"&&e.inputtingFindString!==this._inputtingFindString&&(this._inputtingFindString=e.inputtingFindString,t.inputtingFindString=e.inputtingFindString,i=!0),typeof e.findCompleted<"u"&&e.findCompleted!==this._findCompleted&&(this._findCompleted=e.findCompleted,t.findCompleted=e.findCompleted,i=!0),i&&(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 W=class extends o.Disposable{constructor(e,i){super();h(this,"_providers",new Set);h(this,"_state",new Se);h(this,"_model");h(this,"_currentMatch$",new S.BehaviorSubject(null));h(this,"currentMatch$",this._currentMatch$.asObservable());h(this,"_replaceables$",new S.BehaviorSubject([]));h(this,"replaceables$",this._replaceables$.asObservable());h(this,"_focusSignal$",new S.Subject);h(this,"focusSignal$",this._focusSignal$.asObservable());this._injector=e,this._contextService=i}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(U,this._state,this._providers),this._model.currentMatch$.subscribe(t=>this._currentMatch$.next(t)),this._model.replaceables$.subscribe(t=>this._replaceables$.next(t));const i=B();return e&&(i.replaceRevealed=!0),this._state.changeState(i),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(J,e)}_toggleDisplayRawFormula(e){this._contextService.setContextValue(le.RENDER_RAW_FORMULA_KEY,e)}};W=Q([O(0,R.Inject(R.Injector)),O(1,o.IContextService)],W);const N={id:"ui.operation.open-find-dialog",type:o.CommandType.OPERATION,handler:n=>{const e=n.get(y);return e.revealed?e.focusFindInput():e.start(),!0}},k={id:"ui.operation.open-replace-dialog",type:o.CommandType.OPERATION,handler:n=>{const e=n.get(y);return e.revealed?e.replaceRevealed?e.focusFindInput():e.revealReplace():e.start(!0),!0}},X={type:o.CommandType.OPERATION,id:"ui.operation.go-to-next-match",handler:n=>(n.get(y).moveToNextMatch(),!0)},q={type:o.CommandType.OPERATION,id:"ui.operation.go-to-previous-match",handler:n=>(n.get(y).moveToPreviousMatch(),!0)};var ee={exports:{}},L={};/**
1
+ (function(d,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/engine-render"),require("react"),require("@univerjs/design"),require("@wendellhu/redi/react-bindings")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","@univerjs/ui","rxjs","@univerjs/engine-render","react","@univerjs/design","@wendellhu/redi/react-bindings"],r):(d=typeof globalThis<"u"?globalThis:d||self,r(d.UniverFindReplace={},d.UniverCore,d["@wendellhu/redi"],d.UniverUi,d.rxjs,d.UniverEngineRender,d.React,d.UniverDesign,d["@wendellhu/redi/react-bindings"]))})(this,function(d,r,R,p,S,de,l,f,F){"use strict";var Ct=Object.defineProperty;var Rt=(d,r,R)=>r in d?Ct(d,r,{enumerable:!0,configurable:!0,writable:!0,value:R}):d[r]=R;var u=(d,r,R)=>(Rt(d,typeof r!="symbol"?r+"":r,R),R);var b=function(){return b=Object.assign||function(n){for(var e,i=1,t=arguments.length;i<t;i++){e=arguments[i];for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&(n[a]=e[a])}return n},b.apply(this,arguments)},he=function(n,e){var i={};for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&e.indexOf(t)<0&&(i[t]=n[t]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var a=0,t=Object.getOwnPropertySymbols(n);a<t.length;a++)e.indexOf(t[a])<0&&Object.prototype.propertyIsEnumerable.call(n,t[a])&&(i[t[a]]=n[t[a]]);return i},K=l.forwardRef(function(n,e){var i=n.icon,t=n.id,a=n.className,s=n.extend,o=he(n,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(t," ").concat(a||"").trim(),_=l.useRef("_".concat(fe()));return $(i,"".concat(t),{defIds:i.defIds,idSuffix:_.current},b({ref:e,className:c},o),s)});function $(n,e,i,t,a){return l.createElement(n.tag,b(b({key:e},ue(n,i,a)),t),(pe(n,i).children||[]).map(function(s,o){return $(s,"".concat(e,"-").concat(n.tag,"-").concat(o),i,void 0,a)}))}function ue(n,e,i){var t=b({},n.attrs);i!=null&&i.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=i.colorChannel1);var a=e.defIds;return!a||a.length===0||(n.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+e.idSuffix),Object.entries(t).forEach(function(s){var o=s[0],c=s[1];typeof c=="string"&&(t[o]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),t}function pe(n,e){var i,t=e.defIds;return!t||t.length===0?n:n.tag==="defs"&&(!((i=n.children)===null||i===void 0)&&i.length)?b(b({},n),{children:n.children.map(function(a){return typeof a.attrs.id=="string"&&t&&t.indexOf(a.attrs.id)>-1?b(b({},a),{attrs:b(b({},a.attrs),{id:a.attrs.id+e.idSuffix})}):a})}):n}function fe(){return Math.random().toString(36).substring(2,8)}K.displayName="UniverIcon";var _e={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"}}]}]},z=l.forwardRef(function(n,e){return l.createElement(K,Object.assign({},n,{id:"search-single-16",ref:e,icon:_e}))});z.displayName="SearchSingle16";const Y="FIND_REPLACE_INPUT_FOCUS",Z="FIND_REPLACE_DIALOG_FOCUS",J="FIND_REPLACE_REPLACE_REVEALED";var ge=Object.defineProperty,me=Object.getOwnPropertyDescriptor,Q=(n,e,i,t)=>{for(var a=t>1?void 0:t?me(e,i):e,s=n.length-1,o;s>=0;s--)(o=n[s])&&(a=(t?o(e,i,a):o(a))||a);return t&&a&&ge(e,i,a),a},O=(n,e)=>(i,t)=>e(i,t,n);class ve extends r.Disposable{}const y=R.createIdentifier("find-replace.service");function Se(n){return typeof n.findString<"u"||typeof n.inputtingFindString<"u"||typeof n.findDirection<"u"||typeof n.matchesTheWholeCell<"u"||typeof n.caseSensitive<"u"||typeof n.findScope<"u"||typeof n.findBy<"u"}let U=class extends r.Disposable{constructor(e,i,t,a){super();u(this,"currentMatch$",new S.BehaviorSubject(null));u(this,"replaceables$",new S.BehaviorSubject([]));u(this,"_findModels",[]);u(this,"_matchingModel",null);u(this,"_matches",[]);u(this,"_currentSearchingDisposables",null);this._state=e,this._providers=i,this._univerInstanceService=t,this._logService=a,this.disposeWithMe(this._state.stateUpdates$.pipe(S.throttleTime(200,void 0,{leading:!0,trailing:!0})).subscribe(async s=>{const o=this._state.state;Se(s)&&(o.findString!==""&&!o.replaceRevealed?(await this._startSearching(),this._state.changeState({findCompleted:!0})):s.replaceRevealed!==!0&&this._stopSearching())}))}get searched(){return this._findModels.length>0}dispose(){super.dispose(),this._stopSearching(),this.currentMatch$.complete(),this.replaceables$.complete(),this._state.changeState({...B(),revealed:!1})}async start(){if(!this._state.findString)return{results:[]};const e=await this._startSearching();return this._state.changeState({findCompleted:!0}),e}async _startSearching(){if(!this._state.findString)return{results:[]};const e=Array.from(this._providers),i=this._findModels=(await Promise.all(e.map(s=>s.find({findString:this._state.findString,findDirection:this._state.findDirection,findScope:this._state.findScope,findBy:this._state.findBy,replaceRevealed:this._state.replaceRevealed,caseSensitive:this._state.caseSensitive,matchesTheWholeCell:this._state.matchesTheWholeCell})))).flat();this._subscribeToModelsChanges(i);const t=this._matches=i.map(s=>s.getMatches()).flat();if(this.replaceables$.next(t.filter(s=>s.replaceable)),!t.length)return this._state.changeState({matchesCount:0,matchesPosition:0}),{results:[]};const a=this._moveToInitialMatch(i,t);return this._state.changeState({matchesCount:t.length,matchesPosition:a+1}),{results:t}}_stopSearching(){var e;this._providers.forEach(i=>i.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 i=this._currentSearchingDisposables=new r.DisposableCollection,t=S.combineLatest(e.map(a=>a.matchesUpdate$)).pipe(S.debounceTime(220)).subscribe(([...a])=>{const s=this._matches=a.flat();if(s.length){const o=this._moveToInitialMatch(this._findModels,s,!0);this._state.changeState({matchesCount:s.length,matchesPosition:o+1}),this.replaceables$.next(s.filter(c=>c.replaceable))}else this._state.changeState({matchesCount:0,matchesPosition:0}),this.replaceables$.next([])});e.forEach(a=>i.add(r.toDisposable(a.activelyChangingMatch$.subscribe(s=>{const o=this._matches.findIndex(c=>c===s);this._state.changeState({matchesPosition:o+1})})))),i.add(r.toDisposable(t))}async replace(){return this._matchingModel?this._matchingModel.replace(this._state.replaceString):!1}async replaceAll(){const e=await Promise.all(this._findModels.map(i=>i.replaceAll(this._state.replaceString))).then(i=>i.reduce((t,a)=>(t.success+=a.success,t.failure+=a.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}moveToNextMatch(){if(!this._matchingModel)return;const e=this._findModels.length===1,i=this._matchingModel.moveToNextMatch({loop:e});if(i){const t=this._matches.findIndex(a=>a===i);this.currentMatch$.next(i),this._state.changeState({matchesPosition:t+1})}else{const t=this._findModels.findIndex(c=>c===this._matchingModel),a=this._findModels[(t+1)%this._findModels.length],s=a.moveToNextMatch(),o=this._matches.findIndex(c=>c===s);this.currentMatch$.next(s),this._matchingModel=a,this._state.changeState({matchesPosition:o+1})}}moveToPreviousMatch(){if(!this._matchingModel)return;const e=this._findModels.length===1,i=this._matchingModel.moveToPreviousMatch({loop:e});if(i){const t=this._matches.findIndex(a=>a===i);this.currentMatch$.next(i),this._state.changeState({matchesPosition:t+1})}else{const t=this._findModels.findIndex(c=>c===this._matchingModel),a=this._findModels[(t-1+this._findModels.length)%this._findModels.length],s=a.moveToPreviousMatch(),o=this._matches.findIndex(c=>c===s);this.currentMatch$.next(s),this._matchingModel=a,this._state.changeState({matchesPosition:o+1})}}_moveToInitialMatch(e,i,t=!1){var _;const a=(_=this._univerInstanceService.getFocusedUniverInstance())==null?void 0:_.getUnitId();if(!a)return-1;const s=e.find(m=>m.unitId===a);if(s){this._matchingModel=s;const m=s.moveToNextMatch({stayIfOnMatch:!0,noFocus:t}),C=i.findIndex(v=>v===m);return this.currentMatch$.next(m),C}this._matchingModel=e[0];const o=this._matchingModel.moveToNextMatch({noFocus:t}),c=this._matches.findIndex(m=>m===o);return this.currentMatch$.next(o),c}};U=Q([O(2,r.IUniverInstanceService),O(3,r.ILogService)],U);var P=(n=>(n.ROW="row",n.COLUMN="column",n))(P||{}),T=(n=>(n.VALUE="value",n.FORMULA="formula",n))(T||{}),E=(n=>(n.SUBUNIT="subunit",n.UNIT="unit",n))(E||{});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 Ce{constructor(){u(this,"_stateUpdates$",new S.Subject);u(this,"stateUpdates$",this._stateUpdates$.asObservable());u(this,"_state$",new S.BehaviorSubject(B()));u(this,"state$",this._state$.asObservable());u(this,"_findString","");u(this,"_inputtingFindString","");u(this,"_replaceString","");u(this,"_revealed",!1);u(this,"_replaceRevealed",!1);u(this,"_matchesPosition",0);u(this,"_matchesCount",0);u(this,"_caseSensitive",!0);u(this,"_matchesTheWholeCell",!1);u(this,"_findDirection","row");u(this,"_findScope","subunit");u(this,"_findBy","value");u(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 i=!1;const t={};typeof e.findString<"u"&&e.findString!==this._findString&&(this._findString=e.findString,t.findString=this._findString,i=!0),typeof e.revealed<"u"&&e.revealed!==this._revealed&&(this._revealed=e.revealed,t.revealed=e.revealed,i=!0),typeof e.replaceRevealed<"u"&&e.replaceRevealed!==this._replaceRevealed&&(this._replaceRevealed=e.replaceRevealed,t.replaceRevealed=e.replaceRevealed,i=!0),typeof e.replaceString<"u"&&e.replaceString!==this._replaceString&&(this._replaceString=e.replaceString,t.replaceString=e.replaceString,i=!0),typeof e.matchesCount<"u"&&e.matchesCount!==this._matchesCount&&(this._matchesCount=e.matchesCount,t.matchesCount=e.matchesCount,i=!0),typeof e.matchesPosition<"u"&&e.matchesPosition!==this._matchesPosition&&(this._matchesPosition=e.matchesPosition,t.matchesPosition=e.matchesPosition,i=!0),typeof e.findBy<"u"&&e.findBy!==this._findBy&&(this._findBy=e.findBy,t.findBy=e.findBy,i=!0),typeof e.findScope<"u"&&e.findScope!==this._findScope&&(this._findScope=e.findScope,t.findScope=e.findScope,i=!0),typeof e.findDirection<"u"&&e.findDirection!==this._findDirection&&(this._findDirection=e.findDirection,t.findDirection=e.findDirection,i=!0),typeof e.caseSensitive<"u"&&e.caseSensitive!==this._caseSensitive&&(this._caseSensitive=e.caseSensitive,t.caseSensitive=e.caseSensitive,i=!0),typeof e.matchesTheWholeCell<"u"&&e.matchesTheWholeCell!==this._matchesTheWholeCell&&(this._matchesTheWholeCell=e.matchesTheWholeCell,t.matchesTheWholeCell=e.matchesTheWholeCell,i=!0),typeof e.inputtingFindString<"u"&&e.inputtingFindString!==this._inputtingFindString&&(this._inputtingFindString=e.inputtingFindString,t.inputtingFindString=e.inputtingFindString,i=!0),typeof e.findCompleted<"u"&&e.findCompleted!==this._findCompleted&&(this._findCompleted=e.findCompleted,t.findCompleted=e.findCompleted,i=!0),i&&(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 k=class extends r.Disposable{constructor(e,i){super();u(this,"_providers",new Set);u(this,"_state",new Ce);u(this,"_model");u(this,"_currentMatch$",new S.BehaviorSubject(null));u(this,"currentMatch$",this._currentMatch$.asObservable());u(this,"_replaceables$",new S.BehaviorSubject([]));u(this,"replaceables$",this._replaceables$.asObservable());u(this,"_focusSignal$",new S.Subject);u(this,"focusSignal$",this._focusSignal$.asObservable());this._injector=e,this._contextService=i}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(U,this._state,this._providers),this._model.currentMatch$.subscribe(t=>this._currentMatch$.next(t)),this._model.replaceables$.subscribe(t=>this._replaceables$.next(t));const i=B();return e&&(i.replaceRevealed=!0),this._state.changeState(i),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),r.toDisposable(()=>this._providers.delete(e))}_toggleRevealReplace(e){this._contextService.setContextValue(J,e)}_toggleDisplayRawFormula(e){this._contextService.setContextValue(de.RENDER_RAW_FORMULA_KEY,e)}};k=Q([O(0,R.Inject(R.Injector)),O(1,r.IContextService)],k);const N={id:"ui.operation.open-find-dialog",type:r.CommandType.OPERATION,handler:n=>{const e=n.get(y);return e.revealed?e.focusFindInput():e.start(),!0}},W={id:"ui.operation.open-replace-dialog",type:r.CommandType.OPERATION,handler:n=>{const e=n.get(y);return e.revealed?e.replaceRevealed?e.focusFindInput():e.revealReplace():e.start(!0),!0}},X={type:r.CommandType.OPERATION,id:"ui.operation.go-to-next-match",handler:n=>(n.get(y).moveToNextMatch(),!0)},q={type:r.CommandType.OPERATION,id:"ui.operation.go-to-previous-match",handler:n=>(n.get(y).moveToPreviousMatch(),!0)};var ee={exports:{}},w={};/**
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 Ce=l,Re=Symbol.for("react.element"),be=Symbol.for("react.fragment"),ye=Object.prototype.hasOwnProperty,Me=Ce.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Ie={key:!0,ref:!0,__self:!0,__source:!0};function te(n,e,i){var t,s={},a=null,r=null;i!==void 0&&(a=""+i),e.key!==void 0&&(a=""+e.key),e.ref!==void 0&&(r=e.ref);for(t in e)ye.call(e,t)&&!Ie.hasOwnProperty(t)&&(s[t]=e[t]);if(n&&n.defaultProps)for(t in e=n.defaultProps,e)s[t]===void 0&&(s[t]=e[t]);return{$$typeof:Re,type:n,key:a,ref:r,props:s,_owner:Me.current}}L.Fragment=be,L.jsx=te,L.jsxs=te,ee.exports=L;var d=ee.exports;const ne={id:"ui.command.replace-current-match",type:o.CommandType.COMMAND,handler:n=>n.get(y).replace()},Fe="CONFIRM_REPLACE_ALL",ie={id:"ui.command.replace-all-matches",type:o.CommandType.COMMAND,handler:async n=>{const e=n.get(f.IConfirmService),i=n.get(o.LocaleService),t=n.get(f.IMessageService);if(!await e.confirm({id:Fe,title:{title:i.t("find-replace.replace.confirm.title")},cancelText:i.t("button.cancel"),confirmText:i.t("button.confirm")}))return!1;const a=await n.get(y).replaceAll(),{success:r,failure:c}=a;return c>0?(r===0?t.show({type:p.MessageType.Error,content:i.t("find-replace.replace.all-failure")}):t.show({type:p.MessageType.Warning,content:i.t("find-replace.replace.partial-success",`${r}`,`${c}`)}),!1):(t.show({type:p.MessageType.Success,content:i.t("find-replace.replace.all-success",`${r}`)}),!0)}};function se(n){const{findCompleted:e,localeService:i,matchesCount:t,matchesPosition:s,findString:a,findReplaceService:r,onChange:c,..._}=n,C=e&&t===0?i.t("find-replace.dialog.no-result"):t===0?" ":void 0;return d.jsx(p.InputWithSlot,{autoFocus:!0,placeholder:i.t("find-replace.dialog.find-placeholder"),slot:d.jsx(p.Pager,{loop:!0,text:C,value:s,total:t,onChange:v=>{s===t&&v===1?r.moveToNextMatch():s===1&&v===t||v<s?r.moveToPreviousMatch():r.moveToNextMatch()}}),value:a,onChange:v=>c==null?void 0:c(v),..._})}const j={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 ae(n,e){const i=l.useCallback(()=>{var s;(s=document.querySelector(".univer-find-input input"))==null||s.focus()},[]),t=l.useCallback(()=>{const s=document.querySelectorAll(".univer-find-replace-dialog-container .univer-select-selection-search-input");return Array.from(s).some(a=>a===document.activeElement)},[]);return l.useImperativeHandle(e,()=>({focus:i,selectHasFocus:t})),l.useEffect(()=>{const s=n.focusSignal$.subscribe(()=>i());return()=>s.unsubscribe()},[n,i]),{focus:i,selectHasFocus:t}}const xe=l.forwardRef(function(e,i){const t=I.useDependency(o.LocaleService),s=I.useDependency(y),a=I.useDependency(o.ICommandService),r=f.useObservable(s.state$,void 0,!0),{findCompleted:c,findString:_,matchesCount:m,matchesPosition:C}=r,v=l.useCallback(()=>{a.executeCommand(k.id)},[a]),x=l.useCallback(F=>s.changeFindString(F),[s]);return ae(s,i),d.jsxs(l.Fragment,{children:[d.jsx(se,{findCompleted:c,className:"univer-find-input",matchesCount:m,matchesPosition:C,findReplaceService:s,localeService:t,findString:_,onChange:x}),d.jsx("div",{className:j.findReplaceExpandContainer,children:d.jsx(p.Button,{type:"text",size:"small",onClick:v,children:t.t("find-replace.dialog.advanced-finding")})})]})}),De=l.forwardRef(function(e,i){const t=I.useDependency(y),s=I.useDependency(o.LocaleService),a=I.useDependency(o.ICommandService),r=I.useDependency(f.IMessageService),c=f.useObservable(t.currentMatch$,void 0,!0),_=f.useObservable(t.replaceables$,void 0,!0),m=f.useObservable(t.state$,void 0,!0),{matchesCount:C,matchesPosition:v,findString:x,inputtingFindString:F,replaceString:Xe,caseSensitive:qe,matchesTheWholeCell:et,findDirection:tt,findScope:nt,findBy:it,findCompleted:H}=m,st=F.length===0,at=C===0||!(c!=null&&c.replaceable),rt=_.length===0,ot=l.useCallback(g=>t.changeInputtingFindString(g),[t]),ct=l.useCallback(g=>t.changeReplaceString(g),[t]),{focus:lt}=ae(t,i),dt=l.useCallback(()=>{x===F?t.moveToNextMatch():(t.changeFindString(F),t.find())},[x,F,t]),ht=l.useCallback(()=>a.executeCommand(ne.id),[a]),ut=l.useCallback(async()=>{await a.executeCommand(ie.id),lt()},[a]),ft=l.useCallback(g=>{t.changeFindDirection(g)},[t]),pt=l.useCallback(g=>{t.changeFindScope(g)},[t]),_t=l.useCallback(g=>{t.changeFindBy(g)},[t]),gt=Te(s),mt=Pe(s),vt=Ee(s);return l.useEffect(()=>{const g=H&&C===0;let A=null;return g&&(A=r.show({content:s.t("find-replace.dialog.no-match"),type:p.MessageType.Warning,delay:5e3})),()=>A==null?void 0:A.dispose()},[H,C,r,s]),d.jsxs(l.Fragment,{children:[d.jsx(p.FormLayout,{label:s.t("find-replace.dialog.find"),children:d.jsx(se,{findCompleted:H,className:"univer-find-input",matchesCount:C,matchesPosition:v,findReplaceService:t,localeService:s,findString:F,onChange:ot})}),d.jsx(p.FormLayout,{label:s.t("find-replace.dialog.replace"),children:d.jsx(p.Input,{placeholder:s.t("find-replace.dialog.replace-placeholder"),value:Xe,onChange:g=>ct(g)})}),d.jsx(p.FormLayout,{label:s.t("find-replace.dialog.find-direction.title"),children:d.jsx(p.Select,{value:tt,options:mt,onChange:ft})}),d.jsx(p.FormDualColumnLayout,{children:d.jsxs(l.Fragment,{children:[d.jsx(p.FormLayout,{label:s.t("find-replace.dialog.find-scope.title"),children:d.jsx(p.Select,{value:nt,options:gt,onChange:pt})}),d.jsx(p.FormLayout,{label:s.t("find-replace.dialog.find-by.title"),children:d.jsx(p.Select,{value:it,options:vt,onChange:_t})})]})}),d.jsx(p.FormDualColumnLayout,{children:d.jsxs(l.Fragment,{children:[d.jsx(p.FormLayout,{children:d.jsx(p.Checkbox,{checked:qe,onChange:g=>{t.changeCaseSensitive(g)},children:s.t("find-replace.dialog.case-sensitive")})}),d.jsx(p.FormLayout,{children:d.jsx(p.Checkbox,{checked:et,onChange:g=>{t.changeMatchesTheWholeCell(g)},children:s.t("find-replace.dialog.match-the-whole-cell")})})]})}),d.jsxs("div",{className:j.findReplaceButtonsGroup,children:[d.jsx(p.Button,{type:"primary",onClick:dt,disabled:st,children:s.t("find-replace.dialog.find")}),d.jsxs("span",{className:j.findReplaceButtonsGroupRight,children:[d.jsx(p.Button,{disabled:at,onClick:ht,children:s.t("find-replace.dialog.replace")}),d.jsx(p.Button,{disabled:rt,onClick:ut,children:s.t("find-replace.dialog.replace-all")})]})]})]})});function Oe(){const n=I.useDependency(y),e=I.useDependency(f.ILayoutService),i=I.useDependency(o.IContextService),t=f.useObservable(n.state$,void 0,!0),s=l.useRef(null);l.useEffect(()=>{let _;return s.current&&(_=e.registerContainerElement(s.current)),()=>_==null?void 0:_.dispose()},[e]);const a=l.useRef(null),r=l.useCallback(_=>i.setContextValue(Z,_),[i]),c=l.useCallback(_=>i.setContextValue(Y,_),[i]);return l.useEffect(()=>{var m;const _=S.fromEvent(document,"focusin").subscribe(C=>{var v;C.target&&((v=s.current)!=null&&v.contains(C.target))?r(!0):r(!1),!a.current||!a.current.selectHasFocus()?c(!0):c(!1)});return(m=a.current)==null||m.focus(),r(!0),c(!0),()=>{_.unsubscribe(),r(!1)}},[r,c]),d.jsx("div",{className:j.findReplaceDialogContainer,ref:s,children:t.replaceRevealed?d.jsx(De,{ref:a}):d.jsx(xe,{ref:a})})}function Te(n){const e=n.getCurrentLocale();return l.useMemo(()=>[{label:n.t("find-replace.dialog.find-scope.current-sheet"),value:E.SUBUNIT},{label:n.t("find-replace.dialog.find-scope.workbook"),value:E.UNIT}],[e])}function Pe(n){const e=n.getCurrentLocale();return l.useMemo(()=>[{label:n.t("find-replace.dialog.find-direction.row"),value:T.ROW},{label:n.t("find-replace.dialog.find-direction.column"),value:T.COLUMN}],[e])}function Ee(n){const e=n.getCurrentLocale();return l.useMemo(()=>[{label:n.t("find-replace.dialog.find-by.value"),value:P.VALUE},{label:n.t("find-replace.dialog.find-by.formula"),value:P.FORMULA}],[e])}function D(n){return n.getContextValue(Z)}function Ne(n){return n.getContextValue(J)}function re(n){return n.getContextValue(Y)}const w="7_find-replace-shortcuts";function G(n){return n.getContextValue(o.FOCUSING_SHEET)}function V(n){return!n.getContextValue(o.EDITOR_ACTIVATED)}const Le={id:N.id,description:"find-replace.shortcut.open-find-dialog",binding:f.KeyCode.F|f.MetaKeys.CTRL_COMMAND,group:w,preconditions(n){return!D(n)&&G(n)&&V(n)}},je={id:N.id,description:"find-replace.shortcut.open-find-dialog",binding:f.KeyCode.F|f.MetaKeys.CTRL_COMMAND,mac:f.KeyCode.F|f.MetaKeys.MAC_CTRL,preconditions(n){return!D(n)&&G(n)&&V(n)}},we={id:k.id,description:"find-replace.shortcut.open-replace-dialog",binding:f.KeyCode.H|f.MetaKeys.CTRL_COMMAND,mac:f.KeyCode.H|f.MetaKeys.MAC_CTRL,group:w,preconditions(n){return G(n)&&V(n)&&(!D(n)||!Ne(n))}},Ae={id:X.id,description:"find-replace.shortcut.go-to-next-match",binding:f.KeyCode.ENTER,group:w,priority:1e3,preconditions(n){return re(n)&&D(n)}},Ue={id:q.id,description:"find-replace.shortcut.go-to-previous-match",binding:f.KeyCode.ENTER|f.MetaKeys.SHIFT,group:w,priority:1e3,preconditions(n){return re(n)&&D(n)}};function Be(n){const e=n.get(o.IContextService);return{id:N.id,icon:"SearchIcon",tooltip:"find-replace.toolbar",group:f.MenuGroup.TOOLBAR_OTHERS,type:f.MenuItemType.BUTTON,positions:[f.MenuPosition.TOOLBAR_START],hidden$:f.getMenuHiddenObservable(n,o.UniverInstanceType.SHEET),disabled$:S.combineLatest([e.subscribeContextValue$(o.EDITOR_ACTIVATED),e.subscribeContextValue$(o.FOCUSING_SHEET)]).pipe(S.map(([i,t])=>i||!t))}}var We=Object.defineProperty,ke=Object.getOwnPropertyDescriptor,Ge=(n,e,i,t)=>{for(var s=t>1?void 0:t?ke(e,i):e,a=n.length-1,r;a>=0;a--)(r=n[a])&&(s=(t?r(e,i,s):r(s))||s);return t&&s&&We(e,i,s),s},M=(n,e)=>(i,t)=>e(i,t,n);const oe="DESKTOP_FIND_REPLACE_DIALOG",ce=350,Ve=20,He=-90;u.FindReplaceController=class extends o.RxDisposable{constructor(e,i,t,s,a,r,c,_,m,C,v,x){super(),this._univerInstanceService=e,this._menuService=i,this._shortcutService=t,this._commandService=s,this._findReplaceService=a,this._logService=r,this._dialogService=c,this._contextService=_,this._layoutService=m,this._localeService=C,this._componentManager=v,this._injector=x,this._initCommands(),this._initUI(),this._initShortcuts()}_initCommands(){[N,k,X,q,ie,ne].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initShortcuts(){[we,Le,je,Ue,Ae].forEach(e=>this.disposeWithMe(this._shortcutService.registerShortcut(e)))}_initUI(){this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(Be))),this.disposeWithMe(this._componentManager.register("FindReplaceDialog",Oe)),this.disposeWithMe(this._componentManager.register("SearchIcon",z)),this._findReplaceService.stateUpdates$.pipe(S.takeUntil(this.dispose$)).subscribe(e=>{e.revealed===!0&&this._openPanel()}),this.disposeWithMe(this._univerInstanceService.focused$.pipe(S.takeUntil(this.dispose$)).subscribe(e=>{(!e||!this._univerInstanceService.getUniverSheetInstance(e))&&this.closePanel()}))}_openPanel(){this._dialogService.open({id:oe,draggable:!0,width:ce,title:{title:this._localeService.t("find-replace.dialog.title")},children:{label:"FindReplaceDialog"},destroyOnClose:!0,defaultPosition:Ke(),preservePositionOnDestroy:!0,onClose:()=>this.closePanel()})}closePanel(){this._dialogService.close(oe),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus())}},u.FindReplaceController=Ge([o.OnLifecycle(o.LifecycleStages.Rendered,u.FindReplaceController),M(0,o.IUniverInstanceService),M(1,f.IMenuService),M(2,f.IShortcutService),M(3,o.ICommandService),M(4,y),M(5,o.ILogService),M(6,f.IDialogService),M(7,o.IContextService),M(8,f.ILayoutService),M(9,R.Inject(o.LocaleService)),M(10,R.Inject(f.ComponentManager)),M(11,R.Inject(R.Injector))],u.FindReplaceController);function Ke(){const{innerWidth:n}=window;return{x:(n-ce)/2-Ve,y:He}}const $e={"find-replace":{toolbar:"查找替换",shortcut:{"open-find-dialog":"打开查找对话框","open-replace-dialog":"打开替换对话框","close-dialog":"关闭查找替换对话框","go-to-next-match":"下一个匹配项","go-to-previous-match":"下一个匹配项"},dialog:{title:"查找",find:"查找",replace:"替换","replace-all":"替换全部","find-placeholder":"输入查找内容","advanced-finding":"替换 / 高级查找","replace-placeholder":"输入替换内容","case-sensitive":"匹配大小写","match-the-whole-cell":"匹配整个单元格","find-scope":{title:"查找范围","current-sheet":"当前子表",workbook:"整个工作簿"},"find-direction":{title:"查找顺序",column:"按列查找",row:"按行查找"},"find-by":{title:"查找方式",formula:"查找公式",value:"查找值"},"no-match":"已完成搜索,但是未找到任何匹配项","no-result":"无结果"},replace:{"all-success":"已全部替换 {0} 个匹配项","all-failure":"替换失败",confirm:{title:"确定要替换所有的匹配项吗?"}}},"find-replace-shortcuts":"查找替换"};var ze=Object.defineProperty,Ye=Object.getOwnPropertyDescriptor,Ze=(n,e,i,t)=>{for(var s=t>1?void 0:t?Ye(e,i):e,a=n.length-1,r;a>=0;a--)(r=n[a])&&(s=(t?r(e,i,s):r(s))||s);return t&&s&&ze(e,i,s),s},Je=(n,e)=>(i,t)=>e(i,t,n);const Qe="FIND_REPLACE";u.UniverFindReplacePlugin=class extends o.Plugin{constructor(e,i){super(Qe),this._injector=e,this._localeService=i,this._localeService.load({zhCN:$e})}onStarting(e){[[u.FindReplaceController],[y,{useClass:W}]].forEach(i=>{e.add(i)})}},u.UniverFindReplacePlugin=Ze([Je(1,R.Inject(o.LocaleService))],u.UniverFindReplacePlugin),u.FindBy=P,u.FindDirection=T,u.FindModel=me,u.FindScope=E,u.IFindReplaceService=y,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
9
+ */var Re=l,be=Symbol.for("react.element"),ye=Symbol.for("react.fragment"),Me=Object.prototype.hasOwnProperty,Fe=Re.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Ie={key:!0,ref:!0,__self:!0,__source:!0};function te(n,e,i){var t,a={},s=null,o=null;i!==void 0&&(s=""+i),e.key!==void 0&&(s=""+e.key),e.ref!==void 0&&(o=e.ref);for(t in e)Me.call(e,t)&&!Ie.hasOwnProperty(t)&&(a[t]=e[t]);if(n&&n.defaultProps)for(t in e=n.defaultProps,e)a[t]===void 0&&(a[t]=e[t]);return{$$typeof:be,type:n,key:s,ref:o,props:a,_owner:Fe.current}}w.Fragment=ye,w.jsx=te,w.jsxs=te,ee.exports=w;var h=ee.exports;const ne={id:"ui.command.replace-current-match",type:r.CommandType.COMMAND,handler:n=>n.get(y).replace()},xe="CONFIRM_REPLACE_ALL",ie={id:"ui.command.replace-all-matches",type:r.CommandType.COMMAND,handler:async n=>{const e=n.get(p.IConfirmService),i=n.get(r.LocaleService),t=n.get(p.IMessageService);if(!await e.confirm({id:xe,title:{title:i.t("find-replace.replace.confirm.title")},cancelText:i.t("button.cancel"),confirmText:i.t("button.confirm")}))return!1;const s=await n.get(y).replaceAll(),{success:o,failure:c}=s;return c>0?(o===0?t.show({type:f.MessageType.Error,content:i.t("find-replace.replace.all-failure")}):t.show({type:f.MessageType.Warning,content:i.t("find-replace.replace.partial-success",`${o}`,`${c}`)}),!1):(t.show({type:f.MessageType.Success,content:i.t("find-replace.replace.all-success",`${o}`)}),!0)}};function ae(n){const{findCompleted:e,localeService:i,matchesCount:t,matchesPosition:a,findString:s,findReplaceService:o,onChange:c,..._}=n,C=e&&t===0?i.t("find-replace.dialog.no-result"):t===0?" ":void 0;return h.jsx(f.InputWithSlot,{autoFocus:!0,placeholder:i.t("find-replace.dialog.find-placeholder"),slot:h.jsx(f.Pager,{loop:!0,text:C,value:a,total:t,onChange:v=>{a===t&&v===1?o.moveToNextMatch():a===1&&v===t||v<a?o.moveToPreviousMatch():o.moveToNextMatch()}}),value:s,onChange:v=>c==null?void 0:c(v),..._})}const L={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 se(n,e){const i=l.useCallback(()=>{var a;(a=document.querySelector(".univer-find-input input"))==null||a.focus()},[]),t=l.useCallback(()=>{const a=document.querySelectorAll(".univer-find-replace-dialog-container .univer-select-selection-search-input");return Array.from(a).some(s=>s===document.activeElement)},[]);return l.useImperativeHandle(e,()=>({focus:i,selectHasFocus:t})),l.useEffect(()=>{const a=n.focusSignal$.subscribe(()=>i());return()=>a.unsubscribe()},[n,i]),{focus:i,selectHasFocus:t}}const De=l.forwardRef(function(e,i){const t=F.useDependency(r.LocaleService),a=F.useDependency(y),s=F.useDependency(r.ICommandService),o=p.useObservable(a.state$,void 0,!0),{findCompleted:c,findString:_,matchesCount:m,matchesPosition:C}=o,v=l.useCallback(()=>{s.executeCommand(W.id)},[s]),x=l.useCallback(I=>a.changeFindString(I),[a]);return se(a,i),h.jsxs(l.Fragment,{children:[h.jsx(ae,{findCompleted:c,className:"univer-find-input",matchesCount:m,matchesPosition:C,findReplaceService:a,localeService:t,findString:_,onChange:x}),h.jsx("div",{className:L.findReplaceExpandContainer,children:h.jsx(f.Button,{type:"text",size:"small",onClick:v,children:t.t("find-replace.dialog.advanced-finding")})})]})}),Oe=l.forwardRef(function(e,i){const t=F.useDependency(y),a=F.useDependency(r.LocaleService),s=F.useDependency(r.ICommandService),o=F.useDependency(p.IMessageService),c=p.useObservable(t.currentMatch$,void 0,!0),_=p.useObservable(t.replaceables$,void 0,!0),m=p.useObservable(t.state$,void 0,!0),{matchesCount:C,matchesPosition:v,findString:x,inputtingFindString:I,replaceString:qe,caseSensitive:et,matchesTheWholeCell:tt,findDirection:nt,findScope:it,findBy:at,findCompleted:H}=m,st=I.length===0,ot=C===0||!(c!=null&&c.replaceable),rt=_.length===0,ct=l.useCallback(g=>t.changeInputtingFindString(g),[t]),lt=l.useCallback(g=>t.changeReplaceString(g),[t]),{focus:dt}=se(t,i),ht=l.useCallback(()=>{x===I?t.moveToNextMatch():(t.changeFindString(I),t.find())},[x,I,t]),ut=l.useCallback(()=>s.executeCommand(ne.id),[s]),pt=l.useCallback(async()=>{await s.executeCommand(ie.id),dt()},[s]),ft=l.useCallback(g=>{t.changeFindDirection(g)},[t]),_t=l.useCallback(g=>{t.changeFindScope(g)},[t]),gt=l.useCallback(g=>{t.changeFindBy(g)},[t]),mt=Te(a),vt=Ee(a),St=Ne(a);return l.useEffect(()=>{const g=H&&C===0;let j=null;return g&&(j=o.show({content:a.t("find-replace.dialog.no-match"),type:f.MessageType.Warning,delay:5e3})),()=>j==null?void 0:j.dispose()},[H,C,o,a]),h.jsxs(l.Fragment,{children:[h.jsx(f.FormLayout,{label:a.t("find-replace.dialog.find"),children:h.jsx(ae,{findCompleted:H,className:"univer-find-input",matchesCount:C,matchesPosition:v,findReplaceService:t,localeService:a,findString:I,onChange:ct})}),h.jsx(f.FormLayout,{label:a.t("find-replace.dialog.replace"),children:h.jsx(f.Input,{placeholder:a.t("find-replace.dialog.replace-placeholder"),value:qe,onChange:g=>lt(g)})}),h.jsx(f.FormLayout,{label:a.t("find-replace.dialog.find-direction.title"),children:h.jsx(f.Select,{value:nt,options:vt,onChange:ft})}),h.jsx(f.FormDualColumnLayout,{children:h.jsxs(l.Fragment,{children:[h.jsx(f.FormLayout,{label:a.t("find-replace.dialog.find-scope.title"),children:h.jsx(f.Select,{value:it,options:mt,onChange:_t})}),h.jsx(f.FormLayout,{label:a.t("find-replace.dialog.find-by.title"),children:h.jsx(f.Select,{value:at,options:St,onChange:gt})})]})}),h.jsx(f.FormDualColumnLayout,{children:h.jsxs(l.Fragment,{children:[h.jsx(f.FormLayout,{children:h.jsx(f.Checkbox,{checked:et,onChange:g=>{t.changeCaseSensitive(g)},children:a.t("find-replace.dialog.case-sensitive")})}),h.jsx(f.FormLayout,{children:h.jsx(f.Checkbox,{checked:tt,onChange:g=>{t.changeMatchesTheWholeCell(g)},children:a.t("find-replace.dialog.match-the-whole-cell")})})]})}),h.jsxs("div",{className:L.findReplaceButtonsGroup,children:[h.jsx(f.Button,{type:"primary",onClick:ht,disabled:st,children:a.t("find-replace.dialog.find")}),h.jsxs("span",{className:L.findReplaceButtonsGroupRight,children:[h.jsx(f.Button,{disabled:ot,onClick:ut,children:a.t("find-replace.dialog.replace")}),h.jsx(f.Button,{disabled:rt,onClick:pt,children:a.t("find-replace.dialog.replace-all")})]})]})]})});function Pe(){const n=F.useDependency(y),e=F.useDependency(p.ILayoutService),i=F.useDependency(r.IContextService),t=p.useObservable(n.state$,void 0,!0),a=l.useRef(null);l.useEffect(()=>{let _;return a.current&&(_=e.registerContainerElement(a.current)),()=>_==null?void 0:_.dispose()},[e]);const s=l.useRef(null),o=l.useCallback(_=>i.setContextValue(Z,_),[i]),c=l.useCallback(_=>i.setContextValue(Y,_),[i]);return l.useEffect(()=>{var m;const _=S.fromEvent(document,"focusin").subscribe(C=>{var v;C.target&&((v=a.current)!=null&&v.contains(C.target))?o(!0):o(!1),!s.current||!s.current.selectHasFocus()?c(!0):c(!1)});return(m=s.current)==null||m.focus(),o(!0),c(!0),()=>{_.unsubscribe(),o(!1)}},[o,c]),h.jsx("div",{className:L.findReplaceDialogContainer,ref:a,children:t.replaceRevealed?h.jsx(Oe,{ref:s}):h.jsx(De,{ref:s})})}function Te(n){const e=n.getCurrentLocale();return l.useMemo(()=>[{label:n.t("find-replace.dialog.find-scope.current-sheet"),value:E.SUBUNIT},{label:n.t("find-replace.dialog.find-scope.workbook"),value:E.UNIT}],[e])}function Ee(n){const e=n.getCurrentLocale();return l.useMemo(()=>[{label:n.t("find-replace.dialog.find-direction.row"),value:P.ROW},{label:n.t("find-replace.dialog.find-direction.column"),value:P.COLUMN}],[e])}function Ne(n){const e=n.getCurrentLocale();return l.useMemo(()=>[{label:n.t("find-replace.dialog.find-by.value"),value:T.VALUE},{label:n.t("find-replace.dialog.find-by.formula"),value:T.FORMULA}],[e])}function D(n){return n.getContextValue(Z)}function we(n){return n.getContextValue(J)}function oe(n){return n.getContextValue(Y)}const A="7_find-replace-shortcuts";function G(n){return n.getContextValue(r.FOCUSING_SHEET)}function V(n){return!n.getContextValue(r.EDITOR_ACTIVATED)}const Le={id:N.id,description:"find-replace.shortcut.open-find-dialog",binding:p.KeyCode.F|p.MetaKeys.CTRL_COMMAND,group:A,preconditions(n){return!D(n)&&G(n)&&V(n)}},Ae={id:N.id,description:"find-replace.shortcut.open-find-dialog",binding:p.KeyCode.F|p.MetaKeys.CTRL_COMMAND,mac:p.KeyCode.F|p.MetaKeys.MAC_CTRL,preconditions(n){return!D(n)&&G(n)&&V(n)}},je={id:W.id,description:"find-replace.shortcut.open-replace-dialog",binding:p.KeyCode.H|p.MetaKeys.CTRL_COMMAND,mac:p.KeyCode.H|p.MetaKeys.MAC_CTRL,group:A,preconditions(n){return G(n)&&V(n)&&(!D(n)||!we(n))}},Ue={id:X.id,description:"find-replace.shortcut.go-to-next-match",binding:p.KeyCode.ENTER,group:A,priority:1e3,preconditions(n){return oe(n)&&D(n)}},Be={id:q.id,description:"find-replace.shortcut.go-to-previous-match",binding:p.KeyCode.ENTER|p.MetaKeys.SHIFT,group:A,priority:1e3,preconditions(n){return oe(n)&&D(n)}};function ke(n){const e=n.get(r.IContextService);return{id:N.id,icon:"SearchIcon",tooltip:"find-replace.toolbar",group:p.MenuGroup.TOOLBAR_OTHERS,type:p.MenuItemType.BUTTON,positions:[p.MenuPosition.TOOLBAR_START],hidden$:p.getMenuHiddenObservable(n,r.UniverInstanceType.SHEET),disabled$:S.combineLatest([e.subscribeContextValue$(r.EDITOR_ACTIVATED),e.subscribeContextValue$(r.FOCUSING_SHEET)]).pipe(S.map(([i,t])=>i||!t))}}var We=Object.defineProperty,Ge=Object.getOwnPropertyDescriptor,Ve=(n,e,i,t)=>{for(var a=t>1?void 0:t?Ge(e,i):e,s=n.length-1,o;s>=0;s--)(o=n[s])&&(a=(t?o(e,i,a):o(a))||a);return t&&a&&We(e,i,a),a},M=(n,e)=>(i,t)=>e(i,t,n);const re="DESKTOP_FIND_REPLACE_DIALOG",ce=350,He=20,Ke=-90;d.FindReplaceController=class extends r.RxDisposable{constructor(e,i,t,a,s,o,c,_,m,C,v,x){super(),this._univerInstanceService=e,this._menuService=i,this._shortcutService=t,this._commandService=a,this._findReplaceService=s,this._logService=o,this._dialogService=c,this._contextService=_,this._layoutService=m,this._localeService=C,this._componentManager=v,this._injector=x,this._initCommands(),this._initUI(),this._initShortcuts()}_initCommands(){[N,W,X,q,ie,ne].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initShortcuts(){[je,Le,Ae,Be,Ue].forEach(e=>this.disposeWithMe(this._shortcutService.registerShortcut(e)))}_initUI(){this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(ke))),this.disposeWithMe(this._componentManager.register("FindReplaceDialog",Pe)),this.disposeWithMe(this._componentManager.register("SearchIcon",z)),this._findReplaceService.stateUpdates$.pipe(S.takeUntil(this.dispose$)).subscribe(e=>{e.revealed===!0&&this._openPanel()}),this.disposeWithMe(this._univerInstanceService.focused$.pipe(S.takeUntil(this.dispose$)).subscribe(e=>{(!e||!this._univerInstanceService.getUniverSheetInstance(e))&&this.closePanel()}))}_openPanel(){this._dialogService.open({id:re,draggable:!0,width:ce,title:{title:this._localeService.t("find-replace.dialog.title")},children:{label:"FindReplaceDialog"},destroyOnClose:!0,defaultPosition:$e(),preservePositionOnDestroy:!0,onClose:()=>this.closePanel()})}closePanel(){this._dialogService.close(re),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus())}},d.FindReplaceController=Ve([r.OnLifecycle(r.LifecycleStages.Rendered,d.FindReplaceController),M(0,r.IUniverInstanceService),M(1,p.IMenuService),M(2,p.IShortcutService),M(3,r.ICommandService),M(4,y),M(5,r.ILogService),M(6,p.IDialogService),M(7,r.IContextService),M(8,p.ILayoutService),M(9,R.Inject(r.LocaleService)),M(10,R.Inject(p.ComponentManager)),M(11,R.Inject(R.Injector))],d.FindReplaceController);function $e(){const{innerWidth:n}=window;return{x:(n-ce)/2-He,y:Ke}}const ze={"find-replace":{toolbar:"Find & Replace",shortcut:{"open-find-dialog":"Open Find Dialog","open-replace-dialog":"Open Replace Dialog","close-dialog":"Close Find & Replace Dialog","go-to-next-match":"Go to Next Match","go-to-previous-match":"Go to Previous Match"},dialog:{title:"Find",find:"Find",replace:"Replace","replace-all":"Replace All","case-sensitive":"Case Sensitive","find-placeholder":"Find in this Sheet","advanced-finding":"Advanced Searching & Replace","replace-placeholder":"Input Replace String","match-the-whole-cell":"Match the Whole Cell","find-direction":{title:"Find Direction",row:"Search by Row",column:"Search by Column"},"find-scope":{title:"Find Range","current-sheet":"Current Sheet",workbook:"Workbook"},"find-by":{title:"Find By",value:"Find by Value",formula:"Find Formula"},"no-match":"Finding completed but no match found.","no-result":"No Result"},replace:{"all-success":"Replaced all {0} matches","all-failure":"Replace failed",confirm:{title:"Are you sure to replace all matches?"}}},"find-replace-shortcuts":"Find & Replace"},le={"find-replace":{toolbar:"查找替换",shortcut:{"open-find-dialog":"打开查找对话框","open-replace-dialog":"打开替换对话框","close-dialog":"关闭查找替换对话框","go-to-next-match":"下一个匹配项","go-to-previous-match":"下一个匹配项"},dialog:{title:"查找",find:"查找",replace:"替换","replace-all":"替换全部","find-placeholder":"输入查找内容","advanced-finding":"替换 / 高级查找","replace-placeholder":"输入替换内容","case-sensitive":"匹配大小写","match-the-whole-cell":"匹配整个单元格","find-scope":{title:"查找范围","current-sheet":"当前子表",workbook:"整个工作簿"},"find-direction":{title:"查找顺序",column:"按列查找",row:"按行查找"},"find-by":{title:"查找方式",formula:"查找公式",value:"查找值"},"no-match":"已完成搜索,但是未找到任何匹配项","no-result":"无结果"},replace:{"all-success":"已全部替换 {0} 个匹配项","all-failure":"替换失败",confirm:{title:"确定要替换所有的匹配项吗?"}}},"find-replace-shortcuts":"查找替换"};var Ye=Object.defineProperty,Ze=Object.getOwnPropertyDescriptor,Je=(n,e,i,t)=>{for(var a=t>1?void 0:t?Ze(e,i):e,s=n.length-1,o;s>=0;s--)(o=n[s])&&(a=(t?o(e,i,a):o(a))||a);return t&&a&&Ye(e,i,a),a},Qe=(n,e)=>(i,t)=>e(i,t,n);const Xe="FIND_REPLACE";d.UniverFindReplacePlugin=class extends r.Plugin{constructor(e,i){super(Xe),this._injector=e,this._localeService=i,this._localeService.load({zhCN:le})}onStarting(e){[[d.FindReplaceController],[y,{useClass:k}]].forEach(i=>{e.add(i)})}},d.UniverFindReplacePlugin=Je([Qe(1,R.Inject(r.LocaleService))],d.UniverFindReplacePlugin),d.FindBy=T,d.FindDirection=P,d.FindModel=ve,d.FindScope=E,d.IFindReplaceService=y,d.enUS=ze,d.zhCN=le,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/find-replace",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -56,29 +56,29 @@
56
56
  "@wendellhu/redi": "0.13.0",
57
57
  "react": ">=16.9.0",
58
58
  "rxjs": ">=7.0.0",
59
- "@univerjs/core": "0.1.5",
60
- "@univerjs/design": "0.1.5",
61
- "@univerjs/engine-render": "0.1.5",
62
- "@univerjs/ui": "0.1.5"
59
+ "@univerjs/engine-render": "0.1.6",
60
+ "@univerjs/design": "0.1.6",
61
+ "@univerjs/core": "0.1.6",
62
+ "@univerjs/ui": "0.1.6"
63
63
  },
64
64
  "dependencies": {
65
- "@univerjs/icons": "^0.1.42"
65
+ "@univerjs/icons": "^0.1.43"
66
66
  },
67
67
  "devDependencies": {
68
- "@types/react": "^18.2.72",
68
+ "@types/react": "^18.2.73",
69
69
  "@wendellhu/redi": "^0.13.0",
70
70
  "less": "^4.2.0",
71
71
  "react": "^18.2.0",
72
72
  "rxjs": "^7.8.1",
73
73
  "typescript": "^5.4.3",
74
- "vite": "^5.2.6",
74
+ "vite": "^5.2.7",
75
75
  "vitest": "^1.4.0",
76
- "@univerjs/core": "0.1.5",
77
- "@univerjs/shared": "0.1.5",
78
- "@univerjs/engine-formula": "0.1.5",
79
- "@univerjs/design": "0.1.5",
80
- "@univerjs/engine-render": "0.1.5",
81
- "@univerjs/ui": "0.1.5"
76
+ "@univerjs/core": "0.1.6",
77
+ "@univerjs/design": "0.1.6",
78
+ "@univerjs/engine-formula": "0.1.6",
79
+ "@univerjs/engine-render": "0.1.6",
80
+ "@univerjs/shared": "0.1.6",
81
+ "@univerjs/ui": "0.1.6"
82
82
  },
83
83
  "scripts": {
84
84
  "test": "vitest run",