index.js 30 KB

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