| 123456789 |
- (function(l,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("@univerjs/core"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/design"),require("@univerjs/engine-render"),require("react")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/ui","rxjs","@univerjs/design","@univerjs/engine-render","react"],r):(l=typeof globalThis<"u"?globalThis:l||self,r(l.UniverFindReplace={},l.UniverCore,l.UniverUi,l.rxjs,l.UniverDesign,l.UniverEngineRender,l.React))})(this,function(l,r,h,C,_,de,p){"use strict";var _t=Object.defineProperty;var gt=(l,r,h)=>r in l?_t(l,r,{enumerable:!0,configurable:!0,writable:!0,value:h}):l[r]=h;var f=(l,r,h)=>gt(l,typeof r!="symbol"?r+"":r,h);var K;const ue="find-replace.config",J={};var R=function(){return R=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},R.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 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},z=p.forwardRef(function(n,e){var i=n.icon,t=n.id,s=n.className,a=n.extend,o=he(n,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(t," ").concat(s||"").trim(),u=p.useRef("_".concat(_e()));return Y(i,"".concat(t),{defIds:i.defIds,idSuffix:u.current},R({ref:e,className:c},o),a)});function Y(n,e,i,t,s){return p.createElement(n.tag,R(R({key:e},fe(n,i,s)),t),(pe(n,i).children||[]).map(function(a,o){return Y(a,"".concat(e,"-").concat(n.tag,"-").concat(o),i,void 0,s)}))}function fe(n,e,i){var t=R({},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 o=a[0],c=a[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)?R(R({},n),{children:n.children.map(function(s){return typeof s.attrs.id=="string"&&t&&t.indexOf(s.attrs.id)>-1?R(R({},s),{attrs:R(R({},s.attrs),{id:s.attrs.id+e.idSuffix})}):s})}):n}function _e(){return Math.random().toString(36).substring(2,8)}z.displayName="UniverIcon";var ge={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=p.forwardRef(function(n,e){return p.createElement(z,Object.assign({},n,{id:"search-single-16",ref:e,icon:ge}))});Z.displayName="SearchSingle16";const Q="FIND_REPLACE_INPUT_FOCUS",X="FIND_REPLACE_DIALOG_FOCUS",q="FIND_REPLACE_REPLACE_REVEALED";var me=Object.defineProperty,ve=Object.getOwnPropertyDescriptor,ee=(n,e,i,t)=>{for(var s=t>1?void 0:t?ve(e,i):e,a=n.length-1,o;a>=0;a--)(o=n[a])&&(s=(t?o(e,i,s):o(s))||s);return t&&s&&me(e,i,s),s},A=(n,e)=>(i,t)=>e(i,t,n);class Se extends r.Disposable{}const b=r.createIdentifier("find-replace.service");function Ce(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"}l.FindReplaceModel=class extends r.Disposable{constructor(i,t,s){super();f(this,"currentMatch$",new C.BehaviorSubject(null));f(this,"replaceables$",new C.BehaviorSubject([]));f(this,"_findModels",[]);f(this,"_matchingModel",null);f(this,"_matches",[]);f(this,"_currentSearchingDisposables",null);this._state=i,this._providers=t,this._univerInstanceService=s,this.disposeWithMe(this._state.stateUpdates$.pipe(C.throttleTime(200,void 0,{leading:!0,trailing:!0})).subscribe(async a=>{const o=this._state.state;Ce(a)&&(o.findString!==""&&!o.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({...E(),revealed:!1})}async start(){if(!this._state.findString)return{results:[]};const i=await this._startSearching();return this._state.changeState({findCompleted:!0}),i}async _startSearching(){if(!this._state.findString)return{results:[]};const i=Array.from(this._providers),t=this._findModels=(await Promise.all(i.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(t);const s=this._matches=t.map(a=>a.getMatches()).flat();return this.replaceables$.next(s.filter(a=>a.replaceable)),s.length?(this._moveToInitialMatch(t),this._state.changeState({matchesCount:s.length}),{results:s}):(this._state.changeState({matchesCount:0,matchesPosition:0}),{results:[]})}_stopSearching(){var i;this._providers.forEach(t=>t.terminate()),this._findModels=[],this._matches=[],this._matchingModel=null,(i=this._currentSearchingDisposables)==null||i.dispose(),this._currentSearchingDisposables=null,this.currentMatch$.next(null),this.replaceables$.next([]),this._state.changeState({findCompleted:!1,matchesCount:0,matchesPosition:0})}_subscribeToModelsChanges(i){const t=this._currentSearchingDisposables=new r.DisposableCollection,s=C.combineLatest(i.map(a=>a.matchesUpdate$)).pipe(C.debounceTime(220)).subscribe(([...a])=>{const o=this._matches=a.flat();o.length?(this._moveToInitialMatch(this._findModels,!0),this._state.changeState({matchesCount:o.length}),this.replaceables$.next(o.filter(c=>c.replaceable))):(this._state.changeState({matchesCount:0,matchesPosition:0}),this.replaceables$.next([]))});i.forEach(a=>t.add(r.toDisposable(a.activelyChangingMatch$.subscribe(o=>{const c=this._matches.findIndex(u=>u===o);this._state.changeState({matchesPosition:c+1})})))),t.add(r.toDisposable(s))}async replace(){return this._matchingModel?this._matchingModel.replace(this._state.replaceString):!1}async replaceAll(){const i=await Promise.all(this._findModels.map(t=>t.replaceAll(this._state.replaceString))).then(t=>t.reduce((s,a)=>(s.success+=a.success,s.failure+=a.failure,s),{success:0,failure:0}));return i.failure===0&&this._stopSearching(),i}getCurrentMatch(){return this._state.matchesPosition>0?this._matches[this._state.matchesPosition-1]:null}_markMatch(i){const t=this._matches.findIndex(s=>s===i);this.currentMatch$.next(i),this._state.changeState({matchesPosition:t+1})}moveToNextMatch(){if(!this._matchingModel)return;const i=this._findModels.length===1,t=this._matchingModel.moveToNextMatch({loop:i});if(t)return this._markMatch(t),t;{const s=this._findModels.findIndex(a=>a===this._matchingModel);return this._moveToNextUnitMatch(s)}}_moveToNextUnitMatch(i){const t=this._findModels.length;for(let s=(i+1)%t;s!==i;){const a=this._findModels[s],o=a.moveToNextMatch({ignoreSelection:!0});if(o)return this._matchingModel=a,this._markMatch(o),o;s=(s+1)%t}if(this._matchingModel){const s=this._matchingModel.moveToNextMatch({ignoreSelection:!0});return s&&this._markMatch(s),s}}moveToPreviousMatch(){if(!this._matchingModel)return;const i=this._findModels.length===1,t=this._matchingModel.moveToPreviousMatch({loop:i});if(t){const s=this._matches.findIndex(a=>a===t);return this.currentMatch$.next(t),this._state.changeState({matchesPosition:s+1}),t}else{const s=this._findModels.length,a=this._findModels.findIndex(c=>c===this._matchingModel);for(let c=(a-1+s)%s;c!==a;){const u=this._findModels[c],v=u.moveToPreviousMatch({ignoreSelection:!0});if(v)return this._matchingModel=u,this._markMatch(v),v;c=(c-1)%s}const o=this._matchingModel.moveToPreviousMatch({ignoreSelection:!0});return o&&this._markMatch(o),o}}_moveToInitialMatch(i,t=!1){var o;const s=(o=this._univerInstanceService.getFocusedUnit())==null?void 0:o.getUnitId();if(!s)return-1;const a=i.findIndex(c=>c.unitId===s);if(a!==-1){this._matchingModel=i[a];const c=this._matchingModel.moveToNextMatch({stayIfOnMatch:!0,noFocus:t});if(c)return this._markMatch(c),a}return this._moveToNextUnitMatch(a),0}},l.FindReplaceModel=ee([A(2,r.IUniverInstanceService)],l.FindReplaceModel);var x=(n=>(n.ROW="row",n.COLUMN="column",n))(x||{}),O=(n=>(n.VALUE="value",n.FORMULA="formula",n))(O||{}),P=(n=>(n.SUBUNIT="subunit",n.UNIT="unit",n))(P||{});function E(){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 te{constructor(){f(this,"_stateUpdates$",new C.Subject);f(this,"stateUpdates$",this._stateUpdates$.asObservable());f(this,"_state$",new C.BehaviorSubject(E()));f(this,"state$",this._state$.asObservable());f(this,"_findString","");f(this,"_inputtingFindString","");f(this,"_replaceString","");f(this,"_revealed",!1);f(this,"_replaceRevealed",!1);f(this,"_matchesPosition",0);f(this,"_matchesCount",0);f(this,"_caseSensitive",!0);f(this,"_matchesTheWholeCell",!1);f(this,"_findDirection","row");f(this,"_findScope","subunit");f(this,"_findBy","value");f(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 U=class extends r.Disposable{constructor(e,i){super();f(this,"_providers",new Set);f(this,"_state",new te);f(this,"_model");f(this,"_currentMatch$",new C.BehaviorSubject(null));f(this,"currentMatch$",this._currentMatch$.asObservable());f(this,"_replaceables$",new C.BehaviorSubject([]));f(this,"replaceables$",this._replaceables$.asObservable());f(this,"_focusSignal$",new C.Subject);f(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()}getProviders(){return this._providers}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(l.FindReplaceModel,this._state,this._providers),this._model.currentMatch$.subscribe(t=>this._currentMatch$.next(t)),this._model.replaceables$.subscribe(t=>this._replaceables$.next(t));const i=E();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(q,e)}_toggleDisplayRawFormula(e){this._contextService.setContextValue(de.RENDER_RAW_FORMULA_KEY,e)}};U=ee([A(0,r.Inject(r.Injector)),A(1,r.IContextService)],U);const w={id:"ui.command.replace-current-match",type:r.CommandType.COMMAND,handler:n=>n.get(b).replace()},Re="CONFIRM_REPLACE_ALL",B={id:"ui.command.replace-all-matches",type:r.CommandType.COMMAND,handler:async n=>{const e=n.get(h.IConfirmService),i=n.get(r.LocaleService),t=n.get(h.IMessageService);if(!await e.confirm({id:Re,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(b).replaceAll(),{success:o,failure:c}=a;return c>0?(o===0?t.show({type:_.MessageType.Error,content:i.t("find-replace.replace.all-failure")}):t.show({type:_.MessageType.Warning,content:i.t("find-replace.replace.partial-success",`${o}`,`${c}`)}),!1):(t.show({type:_.MessageType.Success,content:i.t("find-replace.replace.all-success",`${o}`)}),!0)}},F={id:"ui.operation.open-find-dialog",type:r.CommandType.OPERATION,handler:n=>{const e=n.get(b);return e.revealed?e.focusFindInput():e.start(),!0}},N={id:"ui.operation.open-replace-dialog",type:r.CommandType.OPERATION,handler:n=>{const e=n.get(b);return e.revealed?e.replaceRevealed?e.focusFindInput():e.revealReplace():e.start(!0),!0}},k={type:r.CommandType.OPERATION,id:"ui.operation.go-to-next-match",handler:n=>(n.get(b).moveToNextMatch(),!0)},W={type:r.CommandType.OPERATION,id:"ui.operation.go-to-previous-match",handler:n=>(n.get(b).moveToPreviousMatch(),!0)};var G={exports:{}},D={};/**
- * @license React
- * react-jsx-runtime.production.min.js
- *
- * Copyright (c) Facebook, Inc. and its affiliates.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- */var ne;function be(){if(ne)return D;ne=1;var n=p,e=Symbol.for("react.element"),i=Symbol.for("react.fragment"),t=Object.prototype.hasOwnProperty,s=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,a={key:!0,ref:!0,__self:!0,__source:!0};function o(c,u,v){var g,m={},I=null,y=null;v!==void 0&&(I=""+v),u.key!==void 0&&(I=""+u.key),u.ref!==void 0&&(y=u.ref);for(g in u)t.call(u,g)&&!a.hasOwnProperty(g)&&(m[g]=u[g]);if(c&&c.defaultProps)for(g in u=c.defaultProps,u)m[g]===void 0&&(m[g]=u[g]);return{$$typeof:e,type:c,key:I,ref:y,props:m,_owner:s.current}}return D.Fragment=i,D.jsx=o,D.jsxs=o,D}var ie;function Me(){return ie||(ie=1,G.exports=be()),G.exports}var d=Me();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){const{findCompleted:e,localeService:i,matchesCount:t,matchesPosition:s,findString:a,findReplaceService:o,onChange:c,...u}=n,g=e&&t===0?i.t("find-replace.dialog.no-result"):t===0?" ":void 0;return d.jsx(_.InputWithSlot,{autoFocus:!0,placeholder:i.t("find-replace.dialog.find-placeholder"),slot:d.jsx(_.Pager,{loop:!0,text:g,value:s,total:t,onChange:m=>{s===t&&m===1?o.moveToNextMatch():s===1&&m===t||m<s?o.moveToPreviousMatch():o.moveToNextMatch()}}),value:a,onChange:m=>c==null?void 0:c(m),...u})}function ae(n,e){const i=p.useCallback(()=>{var s;(s=document.querySelector(".univer-find-input input"))==null||s.focus()},[]),t=p.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 p.useImperativeHandle(e,()=>({focus:i,selectHasFocus:t})),p.useEffect(()=>{const s=n.focusSignal$.subscribe(()=>i());return()=>s.unsubscribe()},[n,i]),{focus:i,selectHasFocus:t}}const ye=p.forwardRef(function(e,i){const t=r.useDependency(r.LocaleService),s=r.useDependency(b),a=r.useDependency(r.ICommandService),o=h.useObservable(s.state$,void 0,!0),{findCompleted:c,findString:u,matchesCount:v,matchesPosition:g}=o,m=p.useCallback(()=>{a.executeCommand(N.id)},[a]),I=p.useCallback(y=>s.changeFindString(y),[s]);return ae(s,i),d.jsxs(d.Fragment,{children:[d.jsx(se,{findCompleted:c,className:"univer-find-input",matchesCount:v,matchesPosition:g,findReplaceService:s,localeService:t,findString:u,onChange:I}),d.jsx("div",{className:L.findReplaceExpandContainer,children:d.jsx(_.Button,{type:"text",size:"small",onClick:m,children:t.t("find-replace.dialog.advanced-finding")})})]})}),Ie=p.forwardRef(function(e,i){const t=r.useDependency(b),s=r.useDependency(r.LocaleService),a=r.useDependency(r.ICommandService),o=r.useDependency(h.IMessageService),c=h.useObservable(t.currentMatch$,void 0,!0),u=h.useObservable(t.replaceables$,void 0,!0),v=h.useObservable(t.state$,void 0,!0),{matchesCount:g,matchesPosition:m,findString:I,inputtingFindString:y,replaceString:ze,caseSensitive:Ye,matchesTheWholeCell:Ze,findDirection:Qe,findScope:Xe,findBy:qe,findCompleted:$}=v,et=y.length===0,tt=g===0||!(c!=null&&c.replaceable),nt=u.length===0,it=p.useCallback(S=>t.changeInputtingFindString(S),[t]),st=p.useCallback(S=>t.changeReplaceString(S),[t]),{focus:at}=ae(t,i),rt=p.useCallback(()=>{I===y?t.moveToNextMatch():(t.changeFindString(y),t.find())},[I,y,t]),ot=p.useCallback(()=>a.executeCommand(w.id),[a]),ct=p.useCallback(async()=>{await a.executeCommand(B.id),at()},[a]),lt=p.useCallback(S=>{t.changeFindDirection(S)},[t]),dt=p.useCallback(S=>{t.changeFindScope(S)},[t]),ut=p.useCallback(S=>{t.changeFindBy(S)},[t]),ht=De(s),ft=Te(s),pt=xe(s);return p.useEffect(()=>{$&&g===0&&o.show({content:s.t("find-replace.dialog.no-match"),type:_.MessageType.Warning,duration:5e3})},[$,g,o,s]),d.jsxs(d.Fragment,{children:[d.jsx(_.FormLayout,{label:s.t("find-replace.dialog.find"),children:d.jsx(se,{findCompleted:$,className:"univer-find-input",matchesCount:g,matchesPosition:m,findReplaceService:t,localeService:s,findString:y,onChange:it})}),d.jsx(_.FormLayout,{label:s.t("find-replace.dialog.replace"),children:d.jsx(_.Input,{placeholder:s.t("find-replace.dialog.replace-placeholder"),value:ze,onChange:S=>st(S)})}),d.jsx(_.FormLayout,{label:s.t("find-replace.dialog.find-direction.title"),children:d.jsx(_.Select,{value:Qe,options:ft,onChange:lt})}),d.jsx(_.FormDualColumnLayout,{children:d.jsxs(d.Fragment,{children:[d.jsx(_.FormLayout,{label:s.t("find-replace.dialog.find-scope.title"),children:d.jsx(_.Select,{value:Xe,options:ht,onChange:dt})}),d.jsx(_.FormLayout,{label:s.t("find-replace.dialog.find-by.title"),children:d.jsx(_.Select,{value:qe,options:pt,onChange:ut})})]})}),d.jsx(_.FormDualColumnLayout,{children:d.jsxs(d.Fragment,{children:[d.jsx(_.FormLayout,{children:d.jsx(_.Checkbox,{checked:Ye,onChange:S=>{t.changeCaseSensitive(S)},children:s.t("find-replace.dialog.case-sensitive")})}),d.jsx(_.FormLayout,{children:d.jsx(_.Checkbox,{checked:Ze,onChange:S=>{t.changeMatchesTheWholeCell(S)},children:s.t("find-replace.dialog.match-the-whole-cell")})})]})}),d.jsxs("div",{className:L.findReplaceButtonsGroup,children:[d.jsx(_.Button,{type:"primary",onClick:rt,disabled:et,children:s.t("find-replace.dialog.find")}),d.jsxs("span",{className:L.findReplaceButtonsGroupRight,children:[d.jsx(_.Button,{disabled:tt,onClick:ot,children:s.t("find-replace.dialog.replace")}),d.jsx(_.Button,{disabled:nt,onClick:ct,children:s.t("find-replace.dialog.replace-all")})]})]})]})});function Fe(){const n=r.useDependency(b),e=r.useDependency(h.ILayoutService),i=r.useDependency(r.IContextService),t=h.useObservable(n.state$,void 0,!0),s=p.useRef(null);p.useEffect(()=>{let u;return s.current&&(u=e.registerContainerElement(s.current)),()=>u==null?void 0:u.dispose()},[e]);const a=p.useRef(null),o=p.useCallback(u=>i.setContextValue(X,u),[i]),c=p.useCallback(u=>i.setContextValue(Q,u),[i]);return p.useEffect(()=>{var v;const u=C.fromEvent(document,"focusin").subscribe(g=>{var m;g.target&&((m=s.current)!=null&&m.contains(g.target))?o(!0):o(!1),!a.current||!a.current.selectHasFocus()?c(!0):c(!1)});return(v=a.current)==null||v.focus(),o(!0),c(!0),()=>{u.unsubscribe(),o(!1)}},[o,c]),d.jsx("div",{className:L.findReplaceDialogContainer,ref:s,children:t.replaceRevealed?d.jsx(Ie,{ref:a}):d.jsx(ye,{ref:a})})}function De(n){const e=n.getCurrentLocale();return p.useMemo(()=>[{label:n.t("find-replace.dialog.find-scope.current-sheet"),value:P.SUBUNIT},{label:n.t("find-replace.dialog.find-scope.workbook"),value:P.UNIT}],[e])}function Te(n){const e=n.getCurrentLocale();return p.useMemo(()=>[{label:n.t("find-replace.dialog.find-direction.row"),value:x.ROW},{label:n.t("find-replace.dialog.find-direction.column"),value:x.COLUMN}],[e])}function xe(n){const e=n.getCurrentLocale();return p.useMemo(()=>[{label:n.t("find-replace.dialog.find-by.value"),value:O.VALUE},{label:n.t("find-replace.dialog.find-by.formula"),value:O.FORMULA}],[e])}function T(n){return n.getContextValue(X)}function Oe(n){return n.getContextValue(q)}function re(n){return n.getContextValue(Q)}const j="7_find-replace-shortcuts";function V(n){return n.getContextValue(r.FOCUSING_SHEET)}function H(n){return!n.getContextValue(r.EDITOR_ACTIVATED)}const Pe={id:F.id,description:"find-replace.shortcut.open-find-dialog",binding:h.KeyCode.F|h.MetaKeys.CTRL_COMMAND,group:j,preconditions(n){return!T(n)&&V(n)&&H(n)}},Ee={id:F.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(n){return!T(n)&&V(n)&&H(n)}},Ne={id:N.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:j,preconditions(n){return V(n)&&H(n)&&(!T(n)||!Oe(n))}},Le={id:k.id,description:"find-replace.shortcut.go-to-next-match",binding:h.KeyCode.ENTER,group:j,priority:1e3,preconditions(n){return re(n)&&T(n)}},je={id:W.id,description:"find-replace.shortcut.go-to-previous-match",binding:h.KeyCode.ENTER|h.MetaKeys.SHIFT,group:j,priority:1e3,preconditions(n){return re(n)&&T(n)}};function Ae(n){const e=n.get(r.IContextService);return{id:F.id,icon:"SearchIcon",tooltip:"find-replace.toolbar",type:h.MenuItemType.BUTTON,hidden$:h.getMenuHiddenObservable(n,r.UniverInstanceType.UNIVER_SHEET),disabled$:C.combineLatest([e.subscribeContextValue$(r.EDITOR_ACTIVATED),e.subscribeContextValue$(r.FOCUSING_SHEET)]).pipe(C.map(([i,t])=>i||!t))}}const Ue={[h.RibbonStartGroup.OTHERS]:{[F.id]:{order:2,menuItemFactory:Ae}}};var we=Object.defineProperty,Be=Object.getOwnPropertyDescriptor,ke=(n,e,i,t)=>{for(var s=t>1?void 0:t?Be(e,i):e,a=n.length-1,o;a>=0;a--)(o=n[a])&&(s=(t?o(e,i,s):o(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,We=20,Ge=-90;l.FindReplaceController=class extends r.RxDisposable{constructor(i,t,s,a,o,c,u,v,g,m){super();f(this,"_closingListenerDisposable");this._univerInstanceService=i,this._menuManagerService=t,this._shortcutService=s,this._commandService=a,this._findReplaceService=o,this._dialogService=c,this._layoutService=u,this._localeService=v,this._componentManager=g,this._injector=m,this._initCommands(),this._initUI(),this._initShortcuts()}dispose(){var i;super.dispose(),(i=this._closingListenerDisposable)==null||i.dispose(),this._closingListenerDisposable=null}_initCommands(){[F,N,k,W,B,w].forEach(i=>{this.disposeWithMe(this._commandService.registerCommand(i))})}_initShortcuts(){[Ne,Pe,Ee,je,Le].forEach(i=>this.disposeWithMe(this._shortcutService.registerShortcut(i)))}_initUI(){this.disposeWithMe(this._componentManager.register("FindReplaceDialog",Fe)),this.disposeWithMe(this._componentManager.register("SearchIcon",Z)),this._menuManagerService.mergeMenu(Ue),this._findReplaceService.stateUpdates$.pipe(C.takeUntil(this.dispose$)).subscribe(i=>{i.revealed===!0&&this._openPanel()})}_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:Ve(),preservePositionOnDestroy:!0,onClose:()=>this.closePanel()}),this._closingListenerDisposable=r.toDisposable(this._univerInstanceService.focused$.pipe(C.takeUntil(this.dispose$)).subscribe(i=>{(!i||!this._univerInstanceService.getUniverSheetInstance(i))&&this.closePanel()}))}closePanel(){this._closingListenerDisposable&&(this._closingListenerDisposable.dispose(),this._closingListenerDisposable=null,this._dialogService.close(oe),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus()))}},l.FindReplaceController=ke([M(0,r.IUniverInstanceService),M(1,h.IMenuManagerService),M(2,h.IShortcutService),M(3,r.ICommandService),M(4,b),M(5,h.IDialogService),M(6,h.ILayoutService),M(7,r.Inject(r.LocaleService)),M(8,r.Inject(h.ComponentManager)),M(9,r.Inject(r.Injector))],l.FindReplaceController);function Ve(){const{innerWidth:n}=window;return{x:(n-ce)/2-We,y:Ge}}var He=Object.defineProperty,Ke=Object.getOwnPropertyDescriptor,$e=(n,e,i,t)=>{for(var s=t>1?void 0:t?Ke(e,i):e,a=n.length-1,o;a>=0;a--)(o=n[a])&&(s=(t?o(e,i,s):o(s))||s);return t&&s&&He(e,i,s),s},le=(n,e)=>(i,t)=>e(i,t,n);const Je="UNIVER_FIND_REPLACE_PLUGIN";l.UniverFindReplacePlugin=(K=class extends r.Plugin{constructor(e=J,i,t){super(),this._config=e,this._injector=i,this._configService=t;const{...s}=r.merge({},J,this._config);this._configService.setConfig(ue,s)}onStarting(){[[l.FindReplaceController],[b,{useClass:U}]].forEach(e=>this._injector.add(e))}onRendered(){this._injector.get(l.FindReplaceController)}},f(K,"pluginName",Je),K),l.UniverFindReplacePlugin=$e([le(1,r.Inject(r.Injector)),le(2,r.IConfigService)],l.UniverFindReplacePlugin),l.FindBy=O,l.FindDirection=x,l.FindModel=Se,l.FindReplaceState=te,l.FindScope=P,l.GoToNextMatchOperation=k,l.GoToPreviousMatchOperation=W,l.IFindReplaceService=b,l.OpenFindDialogOperation=F,l.OpenReplaceDialogOperation=N,l.ReplaceAllMatchesCommand=B,l.ReplaceCurrentMatchCommand=w,l.createInitFindReplaceState=E,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
|