@univerjs/find-replace 0.6.10-experimental.20250419-8f302dd → 0.6.10-experimental.20250421-e4eb9bc

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 Fe=Object.defineProperty;var xe=(t,e,n)=>e in t?Fe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var u=(t,e,n)=>xe(t,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@univerjs/core"),l=require("@univerjs/ui"),m=require("rxjs"),f=require("@univerjs/design"),De=require("@univerjs/engine-render"),d=require("react/jsx-runtime"),h=require("react"),Te="find-replace.config",G={};var M=function(){return M=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},M.apply(this,arguments)},Oe=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=h.forwardRef(function(t,e){var n=t.icon,i=t.id,s=t.className,r=t.extend,a=Oe(t,["icon","id","className","extend"]),o="univerjs-icon univerjs-icon-".concat(i," ").concat(s||"").trim(),p=h.useRef("_".concat(Ne()));return q(n,"".concat(i),{defIds:n.defIds,idSuffix:p.current},M({ref:e,className:o},a),r)});function q(t,e,n,i,s){return h.createElement(t.tag,M(M({key:e},Pe(t,n,s)),i),(Ee(t,n).children||[]).map(function(r,a){return q(r,"".concat(e,"-").concat(t.tag,"-").concat(a),n,void 0,s)}))}function Pe(t,e,n){var i=M({},t.attrs);n!=null&&n.colorChannel1&&i.fill==="colorChannel1"&&(i.fill=n.colorChannel1),t.tag==="mask"&&i.id&&(i.id=i.id+e.idSuffix),Object.entries(i).forEach(function(r){var a=r[0],o=r[1];a==="mask"&&typeof o=="string"&&(i[a]=o.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))});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 Ee(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)?M(M({},t),{children:t.children.map(function(s){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})}):t}function Ne(){return Math.random().toString(36).substring(2,8)}H.displayName="UniverIcon";var Le={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M7.71899 1.36938C4.37604 1.36938 1.66602 4.07941 1.66602 7.42236C1.66602 10.7653 4.37604 13.4753 7.71899 13.4753C9.16744 13.4753 10.4971 12.9666 11.5389 12.118L13.6598 14.4109C13.8848 14.6542 14.2644 14.669 14.5077 14.444C14.7509 14.219 14.7657 13.8393 14.5407 13.5961L12.3906 11.2716C13.2536 10.2254 13.772 8.88442 13.772 7.42236C13.772 4.07941 11.0619 1.36938 7.71899 1.36938ZM2.86602 7.42236C2.86602 4.74215 5.03878 2.56938 7.71899 2.56938C10.3992 2.56938 12.572 4.74215 12.572 7.42236C12.572 10.1026 10.3992 12.2753 7.71899 12.2753C5.03878 12.2753 2.86602 10.1026 2.86602 7.42236Z",fillRule:"evenodd",clipRule:"evenodd"}}]},z=h.forwardRef(function(t,e){return h.createElement(H,Object.assign({},t,{id:"search-single",ref:e,icon:Le}))});z.displayName="SearchSingle";const Y="FIND_REPLACE_INPUT_FOCUS",Z="FIND_REPLACE_DIALOG_FOCUS",J="FIND_REPLACE_REPLACE_REVEALED";var je=Object.getOwnPropertyDescriptor,Q=(t,e,n,i)=>{for(var s=i>1?void 0:i?je(e,n):e,r=t.length-1,a;r>=0;r--)(a=t[r])&&(s=a(s)||s);return s},D=(t,e)=>(n,i)=>e(n,i,t);class $e extends c.Disposable{}const C=c.createIdentifier("find-replace.service");function Ae(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 c.Disposable{constructor(n,i,s,r){super();u(this,"currentMatch$",new m.BehaviorSubject(null));u(this,"replaceables$",new m.BehaviorSubject([]));u(this,"_findModels",[]);u(this,"_matchingModel",null);u(this,"_matches",[]);u(this,"_currentSearchingDisposables",null);this._state=n,this._providers=i,this._univerInstanceService=s,this._commandService=r,this.disposeWithMe(this._state.stateUpdates$.pipe(m.throttleTime(200,void 0,{leading:!0,trailing:!0})).subscribe(async a=>{const o=this._state.state;Ae(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 n=await this._startSearching();return this._state.changeState({findCompleted:!0}),n}focusSelection(){var n;(n=this._matchingModel)==null||n.focusSelection()}async _startSearching(){if(!this._state.findString)return{results:[]};const n=Array.from(this._providers),i=this._findModels=(await Promise.all(n.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(i);const s=this._matches=i.map(r=>r.getMatches()).flat();return this.replaceables$.next(s.filter(r=>r.replaceable)),s.length?(this._moveToInitialMatch(i),this._state.changeState({matchesCount:s.length}),{results:s}):(this._state.changeState({matchesCount:0,matchesPosition:0}),{results:[]})}_stopSearching(){var n;this._providers.forEach(i=>i.terminate()),this._findModels=[],this._matches=[],this._matchingModel=null,(n=this._currentSearchingDisposables)==null||n.dispose(),this._currentSearchingDisposables=null,this.currentMatch$.next(null),this.replaceables$.next([]),this._state.changeState({findCompleted:!1,matchesCount:0,matchesPosition:0})}_subscribeToModelsChanges(n){const i=this._currentSearchingDisposables=new c.DisposableCollection,s=m.combineLatest(n.map(r=>r.matchesUpdate$)).pipe(m.debounceTime(220)).subscribe(([...r])=>{const a=this._matches=r.flat();a.length?(this._moveToInitialMatch(this._findModels,!0),this._state.changeState({matchesCount:a.length}),this.replaceables$.next(a.filter(o=>o.replaceable))):(this._state.changeState({matchesCount:0,matchesPosition:0}),this.replaceables$.next([]))});n.forEach(r=>i.add(c.toDisposable(r.activelyChangingMatch$.subscribe(a=>{const o=this._matches.findIndex(p=>p===a);this._state.changeState({matchesPosition:o+1})})))),i.add(c.toDisposable(s))}async replace(){return this._matchingModel?this._matchingModel.replace(this._state.replaceString):!1}async replaceAll(){const n=await Promise.all(this._findModels.map(i=>i.replaceAll(this._state.replaceString))).then(i=>i.reduce((s,r)=>(s.success+=r.success,s.failure+=r.failure,s),{success:0,failure:0}));return n.failure===0&&this._stopSearching(),n}getCurrentMatch(){return this._state.matchesPosition>0?this._matches[this._state.matchesPosition-1]:null}_markMatch(n){const i=this._matches.findIndex(s=>s===n);this.currentMatch$.next(n),this._state.changeState({matchesPosition:i+1})}moveToNextMatch(){if(!this._matchingModel)return;const n=this._findModels.length===1,i=this._matchingModel.moveToNextMatch({loop:n});if(i)return this._markMatch(i),i;{const s=this._findModels.findIndex(r=>r===this._matchingModel);return this._moveToNextUnitMatch(s)}}_moveToNextUnitMatch(n){const i=this._findModels.length;for(let s=(n+1)%i;s!==n;){const r=this._findModels[s],a=r.moveToNextMatch({ignoreSelection:!0});if(a)return this._matchingModel=r,this._markMatch(a),a;s=(s+1)%i}if(this._matchingModel){const s=this._matchingModel.moveToNextMatch({ignoreSelection:!0});return s&&this._markMatch(s),s}}moveToPreviousMatch(){if(!this._matchingModel)return;const n=this._findModels.length===1,i=this._matchingModel.moveToPreviousMatch({loop:n});if(i){const s=this._matches.findIndex(r=>r===i);return this.currentMatch$.next(i),this._state.changeState({matchesPosition:s+1}),i}else{const s=this._findModels.length,r=this._findModels.findIndex(o=>o===this._matchingModel);for(let o=(r-1+s)%s;o!==r;){const p=this._findModels[o],v=p.moveToPreviousMatch({ignoreSelection:!0});if(v)return this._matchingModel=p,this._markMatch(v),v;o=(o-1)%s}const a=this._matchingModel.moveToPreviousMatch({ignoreSelection:!0});return a&&this._markMatch(a),a}}_moveToInitialMatch(n,i=!1){var a;const s=(a=this._univerInstanceService.getFocusedUnit())==null?void 0:a.getUnitId();if(!s)return-1;const r=n.findIndex(o=>o.unitId===s);if(r!==-1){this._matchingModel=n[r];const o=this._matchingModel.moveToNextMatch({stayIfOnMatch:!0,noFocus:i});if(o)return this._markMatch(o),r}return this._moveToNextUnitMatch(r),0}};exports.FindReplaceModel=Q([D(2,c.IUniverInstanceService),D(3,c.ICommandService)],exports.FindReplaceModel);var T=(t=>(t.ROW="row",t.COLUMN="column",t))(T||{}),O=(t=>(t.VALUE="value",t.FORMULA="formula",t))(O||{}),P=(t=>(t.SUBUNIT="subunit",t.UNIT="unit",t))(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 X{constructor(){u(this,"_stateUpdates$",new m.Subject);u(this,"stateUpdates$",this._stateUpdates$.asObservable());u(this,"_state$",new m.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 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 $=class extends c.Disposable{constructor(e,n){super();u(this,"_providers",new Set);u(this,"_state",new X);u(this,"_model");u(this,"_currentMatch$",new m.BehaviorSubject(null));u(this,"currentMatch$",this._currentMatch$.asObservable());u(this,"_replaceables$",new m.BehaviorSubject([]));u(this,"replaceables$",this._replaceables$.asObservable());u(this,"_focusSignal$",new m.Subject);u(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()}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)}focusSelection(){var e;(e=this._model)==null||e.focusSelection()}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(i=>this._currentMatch$.next(i)),this._model.replaceables$.subscribe(i=>this._replaceables$.next(i));const n=E();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(J,e)}_toggleDisplayRawFormula(e){this._contextService.setContextValue(De.RENDER_RAW_FORMULA_KEY,e)}};$=Q([D(0,c.Inject(c.Injector)),D(1,c.IContextService)],$);const A={id:"ui.command.replace-current-match",type:c.CommandType.COMMAND,handler:t=>t.get(C).replace()},we="CONFIRM_REPLACE_ALL",w={id:"ui.command.replace-all-matches",type:c.CommandType.COMMAND,handler:async t=>{const e=t.get(l.IConfirmService),n=t.get(c.LocaleService),i=t.get(l.IMessageService);if(!await e.confirm({id:we,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(C).replaceAll(),{success:a,failure:o}=r;return o>0?(a===0?i.show({type:f.MessageType.Error,content:n.t("find-replace.replace.all-failure")}):i.show({type:f.MessageType.Warning,content:n.t("find-replace.replace.partial-success",`${a}`,`${o}`)}),!1):(i.show({type:f.MessageType.Success,content:n.t("find-replace.replace.all-success",`${a}`)}),!0)}},y={id:"ui.operation.open-find-dialog",type:c.CommandType.OPERATION,handler:t=>{const e=t.get(C);return e.revealed?e.focusFindInput():e.start(),!0}},N={id:"ui.operation.open-replace-dialog",type:c.CommandType.OPERATION,handler:t=>{const e=t.get(C);return e.revealed?e.replaceRevealed?e.focusFindInput():e.revealReplace():e.start(!0),!0}},U={type:c.CommandType.OPERATION,id:"ui.operation.go-to-next-match",handler:t=>(t.get(C).moveToNextMatch(),!0)},k={type:c.CommandType.OPERATION,id:"ui.operation.go-to-previous-match",handler:t=>(t.get(C).moveToPreviousMatch(),!0)},ee={type:c.CommandType.OPERATION,id:"ui.operation.focus-selection",handler:t=>(t.get(C).focusSelection(),!0)};function te(t){const{findCompleted:e,localeService:n,matchesCount:i,matchesPosition:s,findString:r,findReplaceService:a,onChange:o,...p}=t,S=e&&i===0?n.t("find-replace.dialog.no-result"):i===0?" ":void 0;return d.jsxs("div",{className:"univer-relative univer-flex univer-items-center univer-gap-2",onDrag:g=>g.stopPropagation(),children:[d.jsx(f.Input,{autoFocus:!0,placeholder:n.t("find-replace.dialog.find-placeholder"),value:r,onChange:g=>o==null?void 0:o(g),...p}),d.jsx(f.Pager,{loop:!0,text:S,value:s,total:i,onChange:g=>{s===i&&g===1?a.moveToNextMatch():s===1&&g===i||g<s?a.moveToPreviousMatch():a.moveToNextMatch()}})]})}function ie(t,e){const n=h.useCallback(()=>{var s;(s=document.querySelector(".univer-find-input input"))==null||s.focus()},[]),i=h.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 h.useImperativeHandle(e,()=>({focus:n,selectHasFocus:i})),h.useEffect(()=>{const s=t.focusSignal$.subscribe(()=>n());return()=>s.unsubscribe()},[t,n]),{focus:n,selectHasFocus:i}}const Ue=h.forwardRef(function(e,n){const i=l.useDependency(c.LocaleService),s=l.useDependency(C),r=l.useDependency(c.ICommandService),a=l.useObservable(s.state$,void 0,!0),{findCompleted:o,findString:p,matchesCount:v,matchesPosition:S}=a,g=h.useCallback(()=>{r.executeCommand(N.id)},[r]),x=h.useCallback(R=>s.changeFindString(R),[s]);return ie(s,n),d.jsxs(d.Fragment,{children:[d.jsx(te,{findCompleted:o,className:"univer-find-input",matchesCount:v,matchesPosition:S,findReplaceService:s,localeService:i,findString:p,onChange:x}),d.jsx("div",{className:"univer-mt-4 univer-text-center",children:d.jsx("a",{className:`
1
+ "use strict";var Fe=Object.defineProperty;var xe=(t,e,n)=>e in t?Fe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var u=(t,e,n)=>xe(t,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@univerjs/core"),l=require("@univerjs/ui"),m=require("rxjs"),f=require("@univerjs/design"),De=require("@univerjs/engine-render"),d=require("react/jsx-runtime"),h=require("react"),Te="find-replace.config",G={};var b=function(){return b=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},b.apply(this,arguments)},Oe=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=h.forwardRef(function(t,e){var n=t.icon,i=t.id,s=t.className,r=t.extend,a=Oe(t,["icon","id","className","extend"]),o="univerjs-icon univerjs-icon-".concat(i," ").concat(s||"").trim(),p=h.useRef("_".concat(Ne()));return q(n,"".concat(i),{defIds:n.defIds,idSuffix:p.current},b({ref:e,className:o},a),r)});function q(t,e,n,i,s){return h.createElement(t.tag,b(b({key:e},Pe(t,n,s)),i),(Ee(t,n).children||[]).map(function(r,a){return q(r,"".concat(e,"-").concat(t.tag,"-").concat(a),n,void 0,s)}))}function Pe(t,e,n){var i=b({},t.attrs);n!=null&&n.colorChannel1&&i.fill==="colorChannel1"&&(i.fill=n.colorChannel1),t.tag==="mask"&&i.id&&(i.id=i.id+e.idSuffix),Object.entries(i).forEach(function(r){var a=r[0],o=r[1];a==="mask"&&typeof o=="string"&&(i[a]=o.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))});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 Ee(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)?b(b({},t),{children:t.children.map(function(s){return typeof s.attrs.id=="string"&&i&&i.indexOf(s.attrs.id)>-1?b(b({},s),{attrs:b(b({},s.attrs),{id:s.attrs.id+e.idSuffix})}):s})}):t}function Ne(){return Math.random().toString(36).substring(2,8)}H.displayName="UniverIcon";var Le={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M7.71899 1.36938C4.37604 1.36938 1.66602 4.07941 1.66602 7.42236C1.66602 10.7653 4.37604 13.4753 7.71899 13.4753C9.16744 13.4753 10.4971 12.9666 11.5389 12.118L13.6598 14.4109C13.8848 14.6542 14.2644 14.669 14.5077 14.444C14.7509 14.219 14.7657 13.8393 14.5407 13.5961L12.3906 11.2716C13.2536 10.2254 13.772 8.88442 13.772 7.42236C13.772 4.07941 11.0619 1.36938 7.71899 1.36938ZM2.86602 7.42236C2.86602 4.74215 5.03878 2.56938 7.71899 2.56938C10.3992 2.56938 12.572 4.74215 12.572 7.42236C12.572 10.1026 10.3992 12.2753 7.71899 12.2753C5.03878 12.2753 2.86602 10.1026 2.86602 7.42236Z",fillRule:"evenodd",clipRule:"evenodd"}}]},z=h.forwardRef(function(t,e){return h.createElement(H,Object.assign({},t,{id:"search-single",ref:e,icon:Le}))});z.displayName="SearchSingle";const Y="FIND_REPLACE_INPUT_FOCUS",Z="FIND_REPLACE_DIALOG_FOCUS",J="FIND_REPLACE_REPLACE_REVEALED";var je=Object.getOwnPropertyDescriptor,Q=(t,e,n,i)=>{for(var s=i>1?void 0:i?je(e,n):e,r=t.length-1,a;r>=0;r--)(a=t[r])&&(s=a(s)||s);return s},D=(t,e)=>(n,i)=>e(n,i,t);class $e extends c.Disposable{}const C=c.createIdentifier("find-replace.service");function Ae(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 c.Disposable{constructor(n,i,s,r){super();u(this,"currentMatch$",new m.BehaviorSubject(null));u(this,"replaceables$",new m.BehaviorSubject([]));u(this,"_findModels",[]);u(this,"_matchingModel",null);u(this,"_matches",[]);u(this,"_currentSearchingDisposables",null);this._state=n,this._providers=i,this._univerInstanceService=s,this._commandService=r,this.disposeWithMe(this._state.stateUpdates$.pipe(m.throttleTime(200,void 0,{leading:!0,trailing:!0})).subscribe(async a=>{const o=this._state.state;Ae(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 n=await this._startSearching();return this._state.changeState({findCompleted:!0}),n}focusSelection(){var n;(n=this._matchingModel)==null||n.focusSelection()}async _startSearching(){if(!this._state.findString)return{results:[]};const n=Array.from(this._providers),i=this._findModels=(await Promise.all(n.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(i);const s=this._matches=i.map(r=>r.getMatches()).flat();return this.replaceables$.next(s.filter(r=>r.replaceable)),s.length?(this._moveToInitialMatch(i),this._state.changeState({matchesCount:s.length}),{results:s}):(this._state.changeState({matchesCount:0,matchesPosition:0}),{results:[]})}_stopSearching(){var n;this._providers.forEach(i=>i.terminate()),this._findModels=[],this._matches=[],this._matchingModel=null,(n=this._currentSearchingDisposables)==null||n.dispose(),this._currentSearchingDisposables=null,this.currentMatch$.next(null),this.replaceables$.next([]),this._state.changeState({findCompleted:!1,matchesCount:0,matchesPosition:0})}_subscribeToModelsChanges(n){const i=this._currentSearchingDisposables=new c.DisposableCollection,s=m.combineLatest(n.map(r=>r.matchesUpdate$)).pipe(m.debounceTime(220)).subscribe(([...r])=>{const a=this._matches=r.flat();a.length?(this._moveToInitialMatch(this._findModels,!0),this._state.changeState({matchesCount:a.length}),this.replaceables$.next(a.filter(o=>o.replaceable))):(this._state.changeState({matchesCount:0,matchesPosition:0}),this.replaceables$.next([]))});n.forEach(r=>i.add(c.toDisposable(r.activelyChangingMatch$.subscribe(a=>{const o=this._matches.findIndex(p=>p===a);this._state.changeState({matchesPosition:o+1})})))),i.add(c.toDisposable(s))}async replace(){return this._matchingModel?this._matchingModel.replace(this._state.replaceString):!1}async replaceAll(){const n=await Promise.all(this._findModels.map(i=>i.replaceAll(this._state.replaceString))).then(i=>i.reduce((s,r)=>(s.success+=r.success,s.failure+=r.failure,s),{success:0,failure:0}));return n.failure===0&&this._stopSearching(),n}getCurrentMatch(){return this._state.matchesPosition>0?this._matches[this._state.matchesPosition-1]:null}_markMatch(n){const i=this._matches.findIndex(s=>s===n);this.currentMatch$.next(n),this._state.changeState({matchesPosition:i+1})}moveToNextMatch(){if(!this._matchingModel)return;const n=this._findModels.length===1,i=this._matchingModel.moveToNextMatch({loop:n});if(i)return this._markMatch(i),i;{const s=this._findModels.findIndex(r=>r===this._matchingModel);return this._moveToNextUnitMatch(s)}}_moveToNextUnitMatch(n){const i=this._findModels.length;for(let s=(n+1)%i;s!==n;){const r=this._findModels[s],a=r.moveToNextMatch({ignoreSelection:!0});if(a)return this._matchingModel=r,this._markMatch(a),a;s=(s+1)%i}if(this._matchingModel){const s=this._matchingModel.moveToNextMatch({ignoreSelection:!0});return s&&this._markMatch(s),s}}moveToPreviousMatch(){if(!this._matchingModel)return;const n=this._findModels.length===1,i=this._matchingModel.moveToPreviousMatch({loop:n});if(i){const s=this._matches.findIndex(r=>r===i);return this.currentMatch$.next(i),this._state.changeState({matchesPosition:s+1}),i}else{const s=this._findModels.length,r=this._findModels.findIndex(o=>o===this._matchingModel);for(let o=(r-1+s)%s;o!==r;){const p=this._findModels[o],v=p.moveToPreviousMatch({ignoreSelection:!0});if(v)return this._matchingModel=p,this._markMatch(v),v;o=(o-1)%s}const a=this._matchingModel.moveToPreviousMatch({ignoreSelection:!0});return a&&this._markMatch(a),a}}_moveToInitialMatch(n,i=!1){var a;const s=(a=this._univerInstanceService.getFocusedUnit())==null?void 0:a.getUnitId();if(!s)return-1;const r=n.findIndex(o=>o.unitId===s);if(r!==-1){this._matchingModel=n[r];const o=this._matchingModel.moveToNextMatch({stayIfOnMatch:!0,noFocus:i});if(o)return this._markMatch(o),r}return this._moveToNextUnitMatch(r),0}};exports.FindReplaceModel=Q([D(2,c.IUniverInstanceService),D(3,c.ICommandService)],exports.FindReplaceModel);var T=(t=>(t.ROW="row",t.COLUMN="column",t))(T||{}),O=(t=>(t.VALUE="value",t.FORMULA="formula",t))(O||{}),P=(t=>(t.SUBUNIT="subunit",t.UNIT="unit",t))(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 X{constructor(){u(this,"_stateUpdates$",new m.Subject);u(this,"stateUpdates$",this._stateUpdates$.asObservable());u(this,"_state$",new m.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 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 $=class extends c.Disposable{constructor(e,n){super();u(this,"_providers",new Set);u(this,"_state",new X);u(this,"_model");u(this,"_currentMatch$",new m.BehaviorSubject(null));u(this,"currentMatch$",this._currentMatch$.asObservable());u(this,"_replaceables$",new m.BehaviorSubject([]));u(this,"replaceables$",this._replaceables$.asObservable());u(this,"_focusSignal$",new m.Subject);u(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()}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)}focusSelection(){var e;(e=this._model)==null||e.focusSelection()}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(i=>this._currentMatch$.next(i)),this._model.replaceables$.subscribe(i=>this._replaceables$.next(i));const n=E();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(J,e)}_toggleDisplayRawFormula(e){this._contextService.setContextValue(De.RENDER_RAW_FORMULA_KEY,e)}};$=Q([D(0,c.Inject(c.Injector)),D(1,c.IContextService)],$);const A={id:"ui.command.replace-current-match",type:c.CommandType.COMMAND,handler:t=>t.get(C).replace()},we="CONFIRM_REPLACE_ALL",w={id:"ui.command.replace-all-matches",type:c.CommandType.COMMAND,handler:async t=>{const e=t.get(l.IConfirmService),n=t.get(c.LocaleService),i=t.get(l.IMessageService);if(!await e.confirm({id:we,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(C).replaceAll(),{success:a,failure:o}=r;return o>0?(a===0?i.show({type:f.MessageType.Error,content:n.t("find-replace.replace.all-failure")}):i.show({type:f.MessageType.Warning,content:n.t("find-replace.replace.partial-success",`${a}`,`${o}`)}),!1):(i.show({type:f.MessageType.Success,content:n.t("find-replace.replace.all-success",`${a}`)}),!0)}},y={id:"ui.operation.open-find-dialog",type:c.CommandType.OPERATION,handler:t=>{const e=t.get(C);return e.revealed?e.focusFindInput():e.start(),!0}},N={id:"ui.operation.open-replace-dialog",type:c.CommandType.OPERATION,handler:t=>{const e=t.get(C);return e.revealed?e.replaceRevealed?e.focusFindInput():e.revealReplace():e.start(!0),!0}},U={type:c.CommandType.OPERATION,id:"ui.operation.go-to-next-match",handler:t=>(t.get(C).moveToNextMatch(),!0)},k={type:c.CommandType.OPERATION,id:"ui.operation.go-to-previous-match",handler:t=>(t.get(C).moveToPreviousMatch(),!0)},ee={type:c.CommandType.OPERATION,id:"ui.operation.focus-selection",handler:t=>(t.get(C).focusSelection(),!0)};function te(t){const{findCompleted:e,localeService:n,matchesCount:i,matchesPosition:s,findString:r,findReplaceService:a,onChange:o,...p}=t,S=e&&i===0?n.t("find-replace.dialog.no-result"):i===0?" ":void 0;return d.jsxs("div",{className:"univer-relative univer-flex univer-items-center univer-gap-2",onDrag:g=>g.stopPropagation(),children:[d.jsx(f.Input,{autoFocus:!0,placeholder:n.t("find-replace.dialog.find-placeholder"),value:r,onChange:g=>o==null?void 0:o(g),...p}),d.jsx(f.Pager,{loop:!0,text:S,value:s,total:i,onChange:g=>{s===i&&g===1?a.moveToNextMatch():s===1&&g===i||g<s?a.moveToPreviousMatch():a.moveToNextMatch()}})]})}function ie(t,e){const n=h.useCallback(()=>{var s;(s=document.querySelector(".univer-find-input input"))==null||s.focus()},[]),i=h.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 h.useImperativeHandle(e,()=>({focus:n,selectHasFocus:i})),h.useEffect(()=>{const s=t.focusSignal$.subscribe(()=>n());return()=>s.unsubscribe()},[t,n]),{focus:n,selectHasFocus:i}}const Ue=h.forwardRef(function(e,n){const i=l.useDependency(c.LocaleService),s=l.useDependency(C),r=l.useDependency(c.ICommandService),a=l.useObservable(s.state$,void 0,!0),{findCompleted:o,findString:p,matchesCount:v,matchesPosition:S}=a,g=h.useCallback(()=>{r.executeCommand(N.id)},[r]),x=h.useCallback(R=>s.changeFindString(R),[s]);return ie(s,n),d.jsxs(d.Fragment,{children:[d.jsx(te,{findCompleted:o,className:"univer-find-input",matchesCount:v,matchesPosition:S,findReplaceService:s,localeService:i,findString:p,onChange:x}),d.jsx("div",{className:"univer-mt-4 univer-text-center",children:d.jsx("a",{className:`
2
2
  univer-cursor-pointer univer-text-sm univer-text-primary-500 univer-transition-colors
3
3
  hover:univer-text-primary-500/80
4
- `,onClick:g,children:i.t("find-replace.dialog.advanced-finding")})})]})}),ke=h.forwardRef(function(e,n){const i=l.useDependency(C),s=l.useDependency(c.LocaleService),r=l.useDependency(c.ICommandService),a=l.useDependency(l.IMessageService),o=l.useObservable(i.currentMatch$,void 0,!0),p=l.useObservable(i.replaceables$,void 0,!0),v=l.useObservable(i.state$,void 0,!0),{matchesCount:S,matchesPosition:g,findString:x,inputtingFindString:R,replaceString:re,caseSensitive:ae,matchesTheWholeCell:oe,findDirection:ce,findScope:le,findBy:de,findCompleted:L}=v,ue=R.length===0,he=S===0||!(o!=null&&o.replaceable),pe=p.length===0,fe=h.useCallback(_=>i.changeInputtingFindString(_),[i]),ge=h.useCallback(_=>i.changeReplaceString(_),[i]),{focus:_e}=ie(i,n),me=h.useCallback(()=>{x===R?i.moveToNextMatch():(i.changeFindString(R),i.find())},[x,R,i]),ve=h.useCallback(()=>r.executeCommand(A.id),[r]),Se=h.useCallback(async()=>{await r.executeCommand(w.id),_e()},[r]),Ce=h.useCallback(_=>{i.changeFindDirection(_)},[i]),Me=h.useCallback(_=>{i.changeFindScope(_)},[i]),be=h.useCallback(_=>{i.changeFindBy(_)},[i]),Re=We(s),ye=Ge(s),Ie=Ve(s);return h.useEffect(()=>{L&&S===0&&a.show({content:s.t("find-replace.dialog.no-match"),type:f.MessageType.Warning,duration:5e3})},[L,S,a,s]),d.jsxs(d.Fragment,{children:[d.jsx(f.FormLayout,{label:s.t("find-replace.dialog.find"),children:d.jsx(te,{findCompleted:L,className:"univer-find-input",matchesCount:S,matchesPosition:g,findReplaceService:i,localeService:s,findString:R,onChange:fe})}),d.jsx(f.FormLayout,{label:s.t("find-replace.dialog.replace"),children:d.jsx(f.Input,{placeholder:s.t("find-replace.dialog.replace-placeholder"),value:re,onChange:_=>ge(_)})}),d.jsx(f.FormLayout,{label:s.t("find-replace.dialog.find-direction.title"),children:d.jsx(f.Select,{value:ce,options:ye,onChange:Ce})}),d.jsx(f.FormDualColumnLayout,{children:d.jsxs(d.Fragment,{children:[d.jsx(f.FormLayout,{label:s.t("find-replace.dialog.find-scope.title"),children:d.jsx(f.Select,{value:le,options:Re,onChange:Me})}),d.jsx(f.FormLayout,{label:s.t("find-replace.dialog.find-by.title"),children:d.jsx(f.Select,{value:de,options:Ie,onChange:be})})]})}),d.jsx(f.FormDualColumnLayout,{children:d.jsxs(d.Fragment,{children:[d.jsx(f.FormLayout,{children:d.jsx(f.Checkbox,{checked:ae,onChange:_=>{i.changeCaseSensitive(_)},children:s.t("find-replace.dialog.case-sensitive")})}),d.jsx(f.FormLayout,{children:d.jsx(f.Checkbox,{checked:oe,onChange:_=>{i.changeMatchesTheWholeCell(_)},children:s.t("find-replace.dialog.match-the-whole-cell")})})]})}),d.jsxs("div",{className:"univer-mt-6 univer-flex univer-justify-between",children:[d.jsx(f.Button,{variant:"primary",onClick:me,disabled:ue,children:s.t("find-replace.dialog.find")}),d.jsxs("span",{className:"univer-inline-flex univer-gap-2",children:[d.jsx(f.Button,{disabled:he,onClick:ve,children:s.t("find-replace.dialog.replace")}),d.jsx(f.Button,{disabled:pe,onClick:Se,children:s.t("find-replace.dialog.replace-all")})]})]})]})});function Be(){const t=l.useDependency(C),e=l.useDependency(l.ILayoutService),n=l.useDependency(c.IContextService),i=l.useObservable(t.state$,void 0,!0),s=h.useRef(null);h.useEffect(()=>{let p;return s.current&&(p=e.registerContainerElement(s.current)),()=>p==null?void 0:p.dispose()},[e]);const r=h.useRef(null),a=h.useCallback(p=>n.setContextValue(Z,p),[n]),o=h.useCallback(p=>n.setContextValue(Y,p),[n]);return h.useEffect(()=>{var v;const p=m.fromEvent(document,"focusin").subscribe(S=>{var g;S.target&&((g=s.current)!=null&&g.contains(S.target))?a(!0):a(!1),!r.current||!r.current.selectHasFocus()?o(!0):o(!1)});return(v=r.current)==null||v.focus(),a(!0),o(!0),()=>{p.unsubscribe(),a(!1)}},[a,o]),d.jsx("div",{ref:s,children:i.replaceRevealed?d.jsx(ke,{ref:r}):d.jsx(Ue,{ref:r})})}function We(t){const e=t.getCurrentLocale();return h.useMemo(()=>[{label:t.t("find-replace.dialog.find-scope.current-sheet"),value:P.SUBUNIT},{label:t.t("find-replace.dialog.find-scope.workbook"),value:P.UNIT}],[e])}function Ge(t){const e=t.getCurrentLocale();return h.useMemo(()=>[{label:t.t("find-replace.dialog.find-direction.row"),value:T.ROW},{label:t.t("find-replace.dialog.find-direction.column"),value:T.COLUMN}],[e])}function Ve(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 I(t){return t.getContextValue(Z)}function Ke(t){return t.getContextValue(J)}function ne(t){return t.getContextValue(Y)}const F="7_find-replace-shortcuts";function B(t){return t.getContextValue(c.FOCUSING_SHEET)}function W(t){return!t.getContextValue(c.EDITOR_ACTIVATED)}const He={id:y.id,description:"find-replace.shortcut.open-find-dialog",binding:l.KeyCode.F|l.MetaKeys.CTRL_COMMAND,group:F,preconditions(t){return!I(t)&&B(t)&&W(t)}},qe={id:y.id,description:"find-replace.shortcut.open-find-dialog",binding:l.KeyCode.F|l.MetaKeys.CTRL_COMMAND,mac:l.KeyCode.F|l.MetaKeys.MAC_CTRL,preconditions(t){return!I(t)&&B(t)&&W(t)}},ze={id:N.id,description:"find-replace.shortcut.open-replace-dialog",binding:l.KeyCode.H|l.MetaKeys.CTRL_COMMAND,mac:l.KeyCode.H|l.MetaKeys.MAC_CTRL,group:F,preconditions(t){return B(t)&&W(t)&&(!I(t)||!Ke(t))}},Ye={id:U.id,description:"find-replace.shortcut.go-to-next-match",binding:l.KeyCode.ENTER,group:F,priority:1e3,preconditions(t){return ne(t)&&I(t)}},Ze={id:k.id,description:"find-replace.shortcut.go-to-previous-match",binding:l.KeyCode.ENTER|l.MetaKeys.SHIFT,group:F,priority:1e3,preconditions(t){return ne(t)&&I(t)}},Je={id:ee.id,description:"find-replace.shortcut.focus-selection",binding:l.KeyCode.ESC,group:F,priority:1e3,preconditions(t){return I(t)}};function Qe(t){const e=t.get(c.IContextService);return{id:y.id,icon:"SearchIcon",tooltip:"find-replace.toolbar",type:l.MenuItemType.BUTTON,hidden$:l.getMenuHiddenObservable(t,c.UniverInstanceType.UNIVER_SHEET),disabled$:m.combineLatest([e.subscribeContextValue$(c.EDITOR_ACTIVATED),e.subscribeContextValue$(c.FOCUSING_SHEET)]).pipe(m.map(([n,i])=>n||!i))}}const Xe={[l.RibbonStartGroup.OTHERS]:{[y.id]:{order:2,menuItemFactory:Qe}}};var et=Object.getOwnPropertyDescriptor,tt=(t,e,n,i)=>{for(var s=i>1?void 0:i?et(e,n):e,r=t.length-1,a;r>=0;r--)(a=t[r])&&(s=a(s)||s);return s},b=(t,e)=>(n,i)=>e(n,i,t);const V="DESKTOP_FIND_REPLACE_DIALOG",se=350,it=20,nt=-90;exports.FindReplaceController=class extends c.RxDisposable{constructor(n,i,s,r,a,o,p,v,S,g){super();u(this,"_closingListenerDisposable");this._univerInstanceService=n,this._menuManagerService=i,this._shortcutService=s,this._commandService=r,this._findReplaceService=a,this._dialogService=o,this._layoutService=p,this._localeService=v,this._componentManager=S,this._injector=g,this._initCommands(),this._initUI(),this._initShortcuts()}dispose(){var n;super.dispose(),(n=this._closingListenerDisposable)==null||n.dispose(),this._closingListenerDisposable=null}_initCommands(){[y,N,U,k,w,A,ee].forEach(n=>{this.disposeWithMe(this._commandService.registerCommand(n))})}_initShortcuts(){[ze,He,qe,Ze,Ye,Je].forEach(n=>this.disposeWithMe(this._shortcutService.registerShortcut(n)))}_initUI(){this.disposeWithMe(this._componentManager.register("FindReplaceDialog",Be)),this.disposeWithMe(this._componentManager.register("SearchIcon",z)),this._menuManagerService.mergeMenu(Xe),this._findReplaceService.stateUpdates$.pipe(m.takeUntil(this.dispose$)).subscribe(n=>{n.revealed===!0&&this._openPanel()})}_openPanel(){this._dialogService.open({id:V,draggable:!0,width:se,title:{title:this._localeService.t("find-replace.dialog.title")},children:{label:"FindReplaceDialog"},destroyOnClose:!0,defaultPosition:st(),preservePositionOnDestroy:!0,onClose:()=>this.closePanel()}),this._closingListenerDisposable=c.toDisposable(this._univerInstanceService.focused$.pipe(m.takeUntil(this.dispose$)).subscribe(n=>{(!n||!this._univerInstanceService.getUniverSheetInstance(n))&&this.closePanel()}))}closePanel(){this._closingListenerDisposable&&(this._closingListenerDisposable.dispose(),this._closingListenerDisposable=null,this._dialogService.close(V),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus()))}};exports.FindReplaceController=tt([b(0,c.IUniverInstanceService),b(1,l.IMenuManagerService),b(2,l.IShortcutService),b(3,c.ICommandService),b(4,C),b(5,l.IDialogService),b(6,l.ILayoutService),b(7,c.Inject(c.LocaleService)),b(8,c.Inject(l.ComponentManager)),b(9,c.Inject(c.Injector))],exports.FindReplaceController);function st(){const{innerWidth:t}=window;return{x:(t-se)/2-it,y:nt}}var rt=Object.getOwnPropertyDescriptor,at=(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=a(s)||s);return s},K=(t,e)=>(n,i)=>e(n,i,t);const ot="UNIVER_FIND_REPLACE_PLUGIN";var j;exports.UniverFindReplacePlugin=(j=class extends c.Plugin{constructor(e=G,n,i){super(),this._config=e,this._injector=n,this._configService=i;const{...s}=c.merge({},G,this._config);this._configService.setConfig(Te,s)}onStarting(){[[exports.FindReplaceController],[C,{useClass:$}]].forEach(e=>this._injector.add(e))}onRendered(){this._injector.get(exports.FindReplaceController)}},u(j,"pluginName",ot),j);exports.UniverFindReplacePlugin=at([K(1,c.Inject(c.Injector)),K(2,c.IConfigService)],exports.UniverFindReplacePlugin);exports.FindBy=O;exports.FindDirection=T;exports.FindModel=$e;exports.FindReplaceState=X;exports.FindScope=P;exports.GoToNextMatchOperation=U;exports.GoToPreviousMatchOperation=k;exports.IFindReplaceService=C;exports.OpenFindDialogOperation=y;exports.OpenReplaceDialogOperation=N;exports.ReplaceAllMatchesCommand=w;exports.ReplaceCurrentMatchCommand=A;exports.createInitFindReplaceState=E;
4
+ `,onClick:g,children:i.t("find-replace.dialog.advanced-finding")})})]})}),ke=h.forwardRef(function(e,n){const i=l.useDependency(C),s=l.useDependency(c.LocaleService),r=l.useDependency(c.ICommandService),a=l.useDependency(l.IMessageService),o=l.useObservable(i.currentMatch$,void 0,!0),p=l.useObservable(i.replaceables$,void 0,!0),v=l.useObservable(i.state$,void 0,!0),{matchesCount:S,matchesPosition:g,findString:x,inputtingFindString:R,replaceString:re,caseSensitive:ae,matchesTheWholeCell:oe,findDirection:ce,findScope:le,findBy:de,findCompleted:L}=v,ue=R.length===0,he=S===0||!(o!=null&&o.replaceable),pe=p.length===0,fe=h.useCallback(_=>i.changeInputtingFindString(_),[i]),ge=h.useCallback(_=>i.changeReplaceString(_),[i]),{focus:_e}=ie(i,n),me=h.useCallback(()=>{x===R?i.moveToNextMatch():(i.changeFindString(R),i.find())},[x,R,i]),ve=h.useCallback(()=>r.executeCommand(A.id),[r]),Se=h.useCallback(async()=>{await r.executeCommand(w.id),_e()},[r]),Ce=h.useCallback(_=>{i.changeFindDirection(_)},[i]),be=h.useCallback(_=>{i.changeFindScope(_)},[i]),Me=h.useCallback(_=>{i.changeFindBy(_)},[i]),Re=We(s),ye=Ge(s),Ie=Ve(s);return h.useEffect(()=>{L&&S===0&&a.show({content:s.t("find-replace.dialog.no-match"),type:f.MessageType.Warning,duration:5e3})},[L,S,a,s]),d.jsxs("div",{className:"univer-theme",children:[d.jsx(f.FormLayout,{label:s.t("find-replace.dialog.find"),children:d.jsx(te,{findCompleted:L,className:"univer-find-input",matchesCount:S,matchesPosition:g,findReplaceService:i,localeService:s,findString:R,onChange:fe})}),d.jsx(f.FormLayout,{label:s.t("find-replace.dialog.replace"),children:d.jsx(f.Input,{placeholder:s.t("find-replace.dialog.replace-placeholder"),value:re,onChange:_=>ge(_)})}),d.jsx(f.FormLayout,{label:s.t("find-replace.dialog.find-direction.title"),children:d.jsx(f.Select,{value:ce,options:ye,onChange:Ce})}),d.jsx(f.FormDualColumnLayout,{children:d.jsxs(d.Fragment,{children:[d.jsx(f.FormLayout,{label:s.t("find-replace.dialog.find-scope.title"),children:d.jsx(f.Select,{value:le,options:Re,onChange:be})}),d.jsx(f.FormLayout,{label:s.t("find-replace.dialog.find-by.title"),children:d.jsx(f.Select,{value:de,options:Ie,onChange:Me})})]})}),d.jsx(f.FormDualColumnLayout,{children:d.jsxs(d.Fragment,{children:[d.jsx(f.FormLayout,{children:d.jsx(f.Checkbox,{checked:ae,onChange:_=>{i.changeCaseSensitive(_)},children:s.t("find-replace.dialog.case-sensitive")})}),d.jsx(f.FormLayout,{children:d.jsx(f.Checkbox,{checked:oe,onChange:_=>{i.changeMatchesTheWholeCell(_)},children:s.t("find-replace.dialog.match-the-whole-cell")})})]})}),d.jsxs("div",{className:"univer-mt-6 univer-flex univer-justify-between",children:[d.jsx(f.Button,{variant:"primary",onClick:me,disabled:ue,children:s.t("find-replace.dialog.find")}),d.jsxs("span",{className:"univer-inline-flex univer-gap-2",children:[d.jsx(f.Button,{disabled:he,onClick:ve,children:s.t("find-replace.dialog.replace")}),d.jsx(f.Button,{disabled:pe,onClick:Se,children:s.t("find-replace.dialog.replace-all")})]})]})]})});function Be(){const t=l.useDependency(C),e=l.useDependency(l.ILayoutService),n=l.useDependency(c.IContextService),i=l.useObservable(t.state$,void 0,!0),s=h.useRef(null);h.useEffect(()=>{let p;return s.current&&(p=e.registerContainerElement(s.current)),()=>p==null?void 0:p.dispose()},[e]);const r=h.useRef(null),a=h.useCallback(p=>n.setContextValue(Z,p),[n]),o=h.useCallback(p=>n.setContextValue(Y,p),[n]);return h.useEffect(()=>{var v;const p=m.fromEvent(document,"focusin").subscribe(S=>{var g;S.target&&((g=s.current)!=null&&g.contains(S.target))?a(!0):a(!1),!r.current||!r.current.selectHasFocus()?o(!0):o(!1)});return(v=r.current)==null||v.focus(),a(!0),o(!0),()=>{p.unsubscribe(),a(!1)}},[a,o]),d.jsx("div",{ref:s,children:i.replaceRevealed?d.jsx(ke,{ref:r}):d.jsx(Ue,{ref:r})})}function We(t){const e=t.getCurrentLocale();return h.useMemo(()=>[{label:t.t("find-replace.dialog.find-scope.current-sheet"),value:P.SUBUNIT},{label:t.t("find-replace.dialog.find-scope.workbook"),value:P.UNIT}],[e])}function Ge(t){const e=t.getCurrentLocale();return h.useMemo(()=>[{label:t.t("find-replace.dialog.find-direction.row"),value:T.ROW},{label:t.t("find-replace.dialog.find-direction.column"),value:T.COLUMN}],[e])}function Ve(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 I(t){return t.getContextValue(Z)}function Ke(t){return t.getContextValue(J)}function ne(t){return t.getContextValue(Y)}const F="7_find-replace-shortcuts";function B(t){return t.getContextValue(c.FOCUSING_SHEET)}function W(t){return!t.getContextValue(c.EDITOR_ACTIVATED)}const He={id:y.id,description:"find-replace.shortcut.open-find-dialog",binding:l.KeyCode.F|l.MetaKeys.CTRL_COMMAND,group:F,preconditions(t){return!I(t)&&B(t)&&W(t)}},qe={id:y.id,description:"find-replace.shortcut.open-find-dialog",binding:l.KeyCode.F|l.MetaKeys.CTRL_COMMAND,mac:l.KeyCode.F|l.MetaKeys.MAC_CTRL,preconditions(t){return!I(t)&&B(t)&&W(t)}},ze={id:N.id,description:"find-replace.shortcut.open-replace-dialog",binding:l.KeyCode.H|l.MetaKeys.CTRL_COMMAND,mac:l.KeyCode.H|l.MetaKeys.MAC_CTRL,group:F,preconditions(t){return B(t)&&W(t)&&(!I(t)||!Ke(t))}},Ye={id:U.id,description:"find-replace.shortcut.go-to-next-match",binding:l.KeyCode.ENTER,group:F,priority:1e3,preconditions(t){return ne(t)&&I(t)}},Ze={id:k.id,description:"find-replace.shortcut.go-to-previous-match",binding:l.KeyCode.ENTER|l.MetaKeys.SHIFT,group:F,priority:1e3,preconditions(t){return ne(t)&&I(t)}},Je={id:ee.id,description:"find-replace.shortcut.focus-selection",binding:l.KeyCode.ESC,group:F,priority:1e3,preconditions(t){return I(t)}};function Qe(t){const e=t.get(c.IContextService);return{id:y.id,icon:"SearchIcon",tooltip:"find-replace.toolbar",type:l.MenuItemType.BUTTON,hidden$:l.getMenuHiddenObservable(t,c.UniverInstanceType.UNIVER_SHEET),disabled$:m.combineLatest([e.subscribeContextValue$(c.EDITOR_ACTIVATED),e.subscribeContextValue$(c.FOCUSING_SHEET)]).pipe(m.map(([n,i])=>n||!i))}}const Xe={[l.RibbonStartGroup.OTHERS]:{[y.id]:{order:2,menuItemFactory:Qe}}};var et=Object.getOwnPropertyDescriptor,tt=(t,e,n,i)=>{for(var s=i>1?void 0:i?et(e,n):e,r=t.length-1,a;r>=0;r--)(a=t[r])&&(s=a(s)||s);return s},M=(t,e)=>(n,i)=>e(n,i,t);const V="DESKTOP_FIND_REPLACE_DIALOG",se=350,it=20,nt=64;exports.FindReplaceController=class extends c.RxDisposable{constructor(n,i,s,r,a,o,p,v,S,g){super();u(this,"_closingListenerDisposable");this._univerInstanceService=n,this._menuManagerService=i,this._shortcutService=s,this._commandService=r,this._findReplaceService=a,this._dialogService=o,this._layoutService=p,this._localeService=v,this._componentManager=S,this._injector=g,this._initCommands(),this._initUI(),this._initShortcuts()}dispose(){var n;super.dispose(),(n=this._closingListenerDisposable)==null||n.dispose(),this._closingListenerDisposable=null}_initCommands(){[y,N,U,k,w,A,ee].forEach(n=>{this.disposeWithMe(this._commandService.registerCommand(n))})}_initShortcuts(){[ze,He,qe,Ze,Ye,Je].forEach(n=>this.disposeWithMe(this._shortcutService.registerShortcut(n)))}_initUI(){this.disposeWithMe(this._componentManager.register("FindReplaceDialog",Be)),this.disposeWithMe(this._componentManager.register("SearchIcon",z)),this._menuManagerService.mergeMenu(Xe),this._findReplaceService.stateUpdates$.pipe(m.takeUntil(this.dispose$)).subscribe(n=>{n.revealed===!0&&this._openPanel()})}_openPanel(){this._dialogService.open({id:V,draggable:!0,width:se,title:{title:this._localeService.t("find-replace.dialog.title")},children:{label:"FindReplaceDialog"},destroyOnClose:!0,mask:!1,maskClosable:!1,defaultPosition:st(),preservePositionOnDestroy:!0,onClose:()=>this.closePanel()}),this._closingListenerDisposable=c.toDisposable(this._univerInstanceService.focused$.pipe(m.takeUntil(this.dispose$)).subscribe(n=>{(!n||!this._univerInstanceService.getUniverSheetInstance(n))&&this.closePanel()}))}closePanel(){this._closingListenerDisposable&&(this._closingListenerDisposable.dispose(),this._closingListenerDisposable=null,this._dialogService.close(V),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus()))}};exports.FindReplaceController=tt([M(0,c.IUniverInstanceService),M(1,l.IMenuManagerService),M(2,l.IShortcutService),M(3,c.ICommandService),M(4,C),M(5,l.IDialogService),M(6,l.ILayoutService),M(7,c.Inject(c.LocaleService)),M(8,c.Inject(l.ComponentManager)),M(9,c.Inject(c.Injector))],exports.FindReplaceController);function st(){const{innerWidth:t}=window;return{x:t-se-it,y:nt}}var rt=Object.getOwnPropertyDescriptor,at=(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=a(s)||s);return s},K=(t,e)=>(n,i)=>e(n,i,t);const ot="UNIVER_FIND_REPLACE_PLUGIN";var j;exports.UniverFindReplacePlugin=(j=class extends c.Plugin{constructor(e=G,n,i){super(),this._config=e,this._injector=n,this._configService=i;const{...s}=c.merge({},G,this._config);this._configService.setConfig(Te,s)}onStarting(){[[exports.FindReplaceController],[C,{useClass:$}]].forEach(e=>this._injector.add(e))}onRendered(){this._injector.get(exports.FindReplaceController)}},u(j,"pluginName",ot),j);exports.UniverFindReplacePlugin=at([K(1,c.Inject(c.Injector)),K(2,c.IConfigService)],exports.UniverFindReplacePlugin);exports.FindBy=O;exports.FindDirection=T;exports.FindModel=$e;exports.FindReplaceState=X;exports.FindScope=P;exports.GoToNextMatchOperation=U;exports.GoToPreviousMatchOperation=k;exports.IFindReplaceService=C;exports.OpenFindDialogOperation=y;exports.OpenReplaceDialogOperation=N;exports.ReplaceAllMatchesCommand=w;exports.ReplaceCurrentMatchCommand=A;exports.createInitFindReplaceState=E;
package/lib/es/index.js CHANGED
@@ -1,13 +1,13 @@
1
1
  var st = Object.defineProperty;
2
2
  var at = (t, e, n) => e in t ? st(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
3
  var o = (t, e, n) => at(t, typeof e != "symbol" ? e + "" : e, n);
4
- import { createIdentifier as ot, Inject as D, Injector as Q, IContextService as X, Disposable as ee, DisposableCollection as ct, toDisposable as A, IUniverInstanceService as fe, ICommandService as W, CommandType as I, LocaleService as B, FOCUSING_SHEET as pe, EDITOR_ACTIVATED as _e, UniverInstanceType as lt, RxDisposable as dt, IConfigService as ht, Plugin as ut, merge as ft } from "@univerjs/core";
4
+ import { createIdentifier as ot, Inject as D, Injector as Q, IContextService as X, Disposable as ee, DisposableCollection as ct, toDisposable as $, IUniverInstanceService as fe, ICommandService as U, CommandType as I, LocaleService as W, FOCUSING_SHEET as pe, EDITOR_ACTIVATED as _e, UniverInstanceType as lt, RxDisposable as dt, IConfigService as ht, Plugin as ut, merge as ft } from "@univerjs/core";
5
5
  import { IConfirmService as pt, IMessageService as ge, useDependency as v, useObservable as x, ILayoutService as me, KeyCode as C, MetaKeys as y, getMenuHiddenObservable as _t, MenuItemType as gt, RibbonStartGroup as mt, IMenuManagerService as vt, IShortcutService as St, IDialogService as Ct, ComponentManager as Mt } from "@univerjs/ui";
6
6
  import { throttleTime as Rt, BehaviorSubject as P, combineLatest as ve, debounceTime as bt, Subject as Se, fromEvent as It, map as yt, takeUntil as ae } from "rxjs";
7
- import { MessageType as N, Input as Ce, Pager as Ft, FormLayout as R, Select as V, FormDualColumnLayout as oe, Checkbox as ce, Button as G } from "@univerjs/design";
7
+ import { MessageType as N, Input as Ce, Pager as Ft, FormLayout as R, Select as j, FormDualColumnLayout as oe, Checkbox as ce, Button as V } from "@univerjs/design";
8
8
  import { RENDER_RAW_FORMULA_KEY as Dt } from "@univerjs/engine-render";
9
- import { jsxs as b, jsx as l, Fragment as $ } from "react/jsx-runtime";
10
- import { forwardRef as j, useRef as K, createElement as Me, useCallback as f, useEffect as L, useMemo as te, useImperativeHandle as xt } from "react";
9
+ import { jsxs as b, jsx as l, Fragment as H } from "react/jsx-runtime";
10
+ import { forwardRef as B, useRef as K, createElement as Me, useCallback as f, useEffect as A, useMemo as te, useImperativeHandle as xt } from "react";
11
11
  const Pt = "find-replace.config", le = {};
12
12
  var _ = function() {
13
13
  return _ = Object.assign || function(t) {
@@ -24,7 +24,7 @@ var _ = function() {
24
24
  for (var r = 0, i = Object.getOwnPropertySymbols(t); r < i.length; r++)
25
25
  e.indexOf(i[r]) < 0 && Object.prototype.propertyIsEnumerable.call(t, i[r]) && (n[i[r]] = t[i[r]]);
26
26
  return n;
27
- }, Re = j(function(t, e) {
27
+ }, Re = B(function(t, e) {
28
28
  var n = t.icon, i = t.id, r = t.className, s = t.extend, a = Tt(t, ["icon", "id", "className", "extend"]), c = "univerjs-icon univerjs-icon-".concat(i, " ").concat(r || "").trim(), d = K("_".concat(Nt()));
29
29
  return be(n, "".concat(i), { defIds: n.defIds, idSuffix: d.current }, _({ ref: e, className: c }, a), s);
30
30
  });
@@ -55,7 +55,7 @@ function Nt() {
55
55
  return Math.random().toString(36).substring(2, 8);
56
56
  }
57
57
  Re.displayName = "UniverIcon";
58
- var $t = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M7.71899 1.36938C4.37604 1.36938 1.66602 4.07941 1.66602 7.42236C1.66602 10.7653 4.37604 13.4753 7.71899 13.4753C9.16744 13.4753 10.4971 12.9666 11.5389 12.118L13.6598 14.4109C13.8848 14.6542 14.2644 14.669 14.5077 14.444C14.7509 14.219 14.7657 13.8393 14.5407 13.5961L12.3906 11.2716C13.2536 10.2254 13.772 8.88442 13.772 7.42236C13.772 4.07941 11.0619 1.36938 7.71899 1.36938ZM2.86602 7.42236C2.86602 4.74215 5.03878 2.56938 7.71899 2.56938C10.3992 2.56938 12.572 4.74215 12.572 7.42236C12.572 10.1026 10.3992 12.2753 7.71899 12.2753C5.03878 12.2753 2.86602 10.1026 2.86602 7.42236Z", fillRule: "evenodd", clipRule: "evenodd" } }] }, Ie = j(function(t, e) {
58
+ var $t = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M7.71899 1.36938C4.37604 1.36938 1.66602 4.07941 1.66602 7.42236C1.66602 10.7653 4.37604 13.4753 7.71899 13.4753C9.16744 13.4753 10.4971 12.9666 11.5389 12.118L13.6598 14.4109C13.8848 14.6542 14.2644 14.669 14.5077 14.444C14.7509 14.219 14.7657 13.8393 14.5407 13.5961L12.3906 11.2716C13.2536 10.2254 13.772 8.88442 13.772 7.42236C13.772 4.07941 11.0619 1.36938 7.71899 1.36938ZM2.86602 7.42236C2.86602 4.74215 5.03878 2.56938 7.71899 2.56938C10.3992 2.56938 12.572 4.74215 12.572 7.42236C12.572 10.1026 10.3992 12.2753 7.71899 12.2753C5.03878 12.2753 2.86602 10.1026 2.86602 7.42236Z", fillRule: "evenodd", clipRule: "evenodd" } }] }, Ie = B(function(t, e) {
59
59
  return Me(Re, Object.assign({}, t, {
60
60
  id: "search-single",
61
61
  ref: e,
@@ -68,7 +68,7 @@ var At = Object.getOwnPropertyDescriptor, xe = (t, e, n, i) => {
68
68
  for (var r = i > 1 ? void 0 : i ? At(e, n) : e, s = t.length - 1, a; s >= 0; s--)
69
69
  (a = t[s]) && (r = a(r) || r);
70
70
  return r;
71
- }, w = (t, e) => (n, i) => e(n, i, t);
71
+ }, L = (t, e) => (n, i) => e(n, i, t);
72
72
  class gi extends ee {
73
73
  }
74
74
  const g = ot("find-replace.service");
@@ -141,10 +141,10 @@ let q = class extends ee {
141
141
  const s = this._matches = r.flat();
142
142
  s.length ? (this._moveToInitialMatch(this._findModels, !0), this._state.changeState({ matchesCount: s.length }), this.replaceables$.next(s.filter((a) => a.replaceable))) : (this._state.changeState({ matchesCount: 0, matchesPosition: 0 }), this.replaceables$.next([]));
143
143
  });
144
- e.forEach((r) => n.add(A(r.activelyChangingMatch$.subscribe((s) => {
144
+ e.forEach((r) => n.add($(r.activelyChangingMatch$.subscribe((s) => {
145
145
  const a = this._matches.findIndex((c) => c === s);
146
146
  this._state.changeState({ matchesPosition: a + 1 });
147
- })))), n.add(A(i));
147
+ })))), n.add($(i));
148
148
  }
149
149
  async replace() {
150
150
  return this._matchingModel ? this._matchingModel.replace(this._state.replaceString) : !1;
@@ -219,8 +219,8 @@ let q = class extends ee {
219
219
  }
220
220
  };
221
221
  q = xe([
222
- w(2, fe),
223
- w(3, W)
222
+ L(2, fe),
223
+ L(3, U)
224
224
  ], q);
225
225
  var z = /* @__PURE__ */ ((t) => (t.ROW = "row", t.COLUMN = "column", t))(z || {}), Y = /* @__PURE__ */ ((t) => (t.VALUE = "value", t.FORMULA = "formula", t))(Y || {}), Z = /* @__PURE__ */ ((t) => (t.SUBUNIT = "subunit", t.UNIT = "unit", t))(Z || {});
226
226
  function ie() {
@@ -428,7 +428,7 @@ let J = class extends ee {
428
428
  (e = this._model) == null || e.dispose(), this._model = null, this._toggleDisplayRawFormula(!1), this._toggleRevealReplace(!1);
429
429
  }
430
430
  registerFindReplaceProvider(e) {
431
- return this._providers.add(e), A(() => this._providers.delete(e));
431
+ return this._providers.add(e), $(() => this._providers.delete(e));
432
432
  }
433
433
  _toggleRevealReplace(e) {
434
434
  this._contextService.setContextValue(De, e);
@@ -438,8 +438,8 @@ let J = class extends ee {
438
438
  }
439
439
  };
440
440
  J = xe([
441
- w(0, D(Q)),
442
- w(1, X)
441
+ L(0, D(Q)),
442
+ L(1, X)
443
443
  ], J);
444
444
  const Pe = {
445
445
  id: "ui.command.replace-current-match",
@@ -449,7 +449,7 @@ const Pe = {
449
449
  id: "ui.command.replace-all-matches",
450
450
  type: I.COMMAND,
451
451
  handler: async (t) => {
452
- const e = t.get(pt), n = t.get(B), i = t.get(ge);
452
+ const e = t.get(pt), n = t.get(W), i = t.get(ge);
453
453
  if (!await e.confirm({
454
454
  id: Ut,
455
455
  title: { title: n.t("find-replace.replace.confirm.title") },
@@ -531,16 +531,16 @@ function Ae(t, e) {
531
531
  const r = document.querySelectorAll(".univer-find-replace-dialog-container .univer-select-selection-search-input");
532
532
  return Array.from(r).some((s) => s === document.activeElement);
533
533
  }, []);
534
- return xt(e, () => ({ focus: n, selectHasFocus: i })), L(() => {
534
+ return xt(e, () => ({ focus: n, selectHasFocus: i })), A(() => {
535
535
  const r = t.focusSignal$.subscribe(() => n());
536
536
  return () => r.unsubscribe();
537
537
  }, [t, n]), { focus: n, selectHasFocus: i };
538
538
  }
539
- const Wt = j(function(e, n) {
540
- const i = v(B), r = v(g), s = v(W), a = x(r.state$, void 0, !0), { findCompleted: c, findString: d, matchesCount: S, matchesPosition: p } = a, u = f(() => {
539
+ const Wt = B(function(e, n) {
540
+ const i = v(W), r = v(g), s = v(U), a = x(r.state$, void 0, !0), { findCompleted: c, findString: d, matchesCount: S, matchesPosition: p } = a, u = f(() => {
541
541
  s.executeCommand(ne.id);
542
542
  }, [s]), E = f((M) => r.changeFindString(M), [r]);
543
- return Ae(r, n), /* @__PURE__ */ b($, { children: [
543
+ return Ae(r, n), /* @__PURE__ */ b(H, { children: [
544
544
  /* @__PURE__ */ l(
545
545
  $e,
546
546
  {
@@ -566,8 +566,8 @@ const Wt = j(function(e, n) {
566
566
  }
567
567
  ) })
568
568
  ] });
569
- }), Bt = j(function(e, n) {
570
- const i = v(g), r = v(B), s = v(W), a = v(ge), c = x(i.currentMatch$, void 0, !0), d = x(i.replaceables$, void 0, !0), S = x(i.state$, void 0, !0), {
569
+ }), Bt = B(function(e, n) {
570
+ const i = v(g), r = v(W), s = v(U), a = v(ge), c = x(i.currentMatch$, void 0, !0), d = x(i.replaceables$, void 0, !0), S = x(i.state$, void 0, !0), {
571
571
  matchesCount: p,
572
572
  matchesPosition: u,
573
573
  findString: E,
@@ -575,8 +575,8 @@ const Wt = j(function(e, n) {
575
575
  replaceString: Ue,
576
576
  caseSensitive: We,
577
577
  matchesTheWholeCell: Be,
578
- findDirection: je,
579
- findScope: ke,
578
+ findDirection: ke,
579
+ findScope: je,
580
580
  findBy: Ve,
581
581
  findCompleted: k
582
582
  } = S, Ge = M.length === 0, He = p === 0 || !(c != null && c.replaceable), Ke = d.length === 0, qe = f(
@@ -595,14 +595,14 @@ const Wt = j(function(e, n) {
595
595
  i.changeFindScope(h);
596
596
  }, [i]), tt = f((h) => {
597
597
  i.changeFindBy(h);
598
- }, [i]), it = kt(r), nt = Vt(r), rt = Gt(r);
599
- return L(() => {
598
+ }, [i]), it = jt(r), nt = Vt(r), rt = Gt(r);
599
+ return A(() => {
600
600
  k && p === 0 && a.show({
601
601
  content: r.t("find-replace.dialog.no-match"),
602
602
  type: N.Warning,
603
603
  duration: 5e3
604
604
  });
605
- }, [k, p, a, r]), /* @__PURE__ */ b($, { children: [
605
+ }, [k, p, a, r]), /* @__PURE__ */ b("div", { className: "univer-theme", children: [
606
606
  /* @__PURE__ */ l(R, { label: r.t("find-replace.dialog.find"), children: /* @__PURE__ */ l(
607
607
  $e,
608
608
  {
@@ -624,12 +624,12 @@ const Wt = j(function(e, n) {
624
624
  onChange: (h) => ze(h)
625
625
  }
626
626
  ) }),
627
- /* @__PURE__ */ l(R, { label: r.t("find-replace.dialog.find-direction.title"), children: /* @__PURE__ */ l(V, { value: je, options: nt, onChange: Xe }) }),
628
- /* @__PURE__ */ l(oe, { children: /* @__PURE__ */ b($, { children: [
629
- /* @__PURE__ */ l(R, { label: r.t("find-replace.dialog.find-scope.title"), children: /* @__PURE__ */ l(V, { value: ke, options: it, onChange: et }) }),
630
- /* @__PURE__ */ l(R, { label: r.t("find-replace.dialog.find-by.title"), children: /* @__PURE__ */ l(V, { value: Ve, options: rt, onChange: tt }) })
627
+ /* @__PURE__ */ l(R, { label: r.t("find-replace.dialog.find-direction.title"), children: /* @__PURE__ */ l(j, { value: ke, options: nt, onChange: Xe }) }),
628
+ /* @__PURE__ */ l(oe, { children: /* @__PURE__ */ b(H, { children: [
629
+ /* @__PURE__ */ l(R, { label: r.t("find-replace.dialog.find-scope.title"), children: /* @__PURE__ */ l(j, { value: je, options: it, onChange: et }) }),
630
+ /* @__PURE__ */ l(R, { label: r.t("find-replace.dialog.find-by.title"), children: /* @__PURE__ */ l(j, { value: Ve, options: rt, onChange: tt }) })
631
631
  ] }) }),
632
- /* @__PURE__ */ l(oe, { children: /* @__PURE__ */ b($, { children: [
632
+ /* @__PURE__ */ l(oe, { children: /* @__PURE__ */ b(H, { children: [
633
633
  /* @__PURE__ */ l(R, { children: /* @__PURE__ */ l(
634
634
  ce,
635
635
  {
@@ -652,17 +652,17 @@ const Wt = j(function(e, n) {
652
652
  ) })
653
653
  ] }) }),
654
654
  /* @__PURE__ */ b("div", { className: "univer-mt-6 univer-flex univer-justify-between", children: [
655
- /* @__PURE__ */ l(G, { variant: "primary", onClick: Ze, disabled: Ge, children: r.t("find-replace.dialog.find") }),
655
+ /* @__PURE__ */ l(V, { variant: "primary", onClick: Ze, disabled: Ge, children: r.t("find-replace.dialog.find") }),
656
656
  /* @__PURE__ */ b("span", { className: "univer-inline-flex univer-gap-2", children: [
657
- /* @__PURE__ */ l(G, { disabled: He, onClick: Je, children: r.t("find-replace.dialog.replace") }),
658
- /* @__PURE__ */ l(G, { disabled: Ke, onClick: Qe, children: r.t("find-replace.dialog.replace-all") })
657
+ /* @__PURE__ */ l(V, { disabled: He, onClick: Je, children: r.t("find-replace.dialog.replace") }),
658
+ /* @__PURE__ */ l(V, { disabled: Ke, onClick: Qe, children: r.t("find-replace.dialog.replace-all") })
659
659
  ] })
660
660
  ] })
661
661
  ] });
662
662
  });
663
- function jt() {
663
+ function kt() {
664
664
  const t = v(g), e = v(me), n = v(X), i = x(t.state$, void 0, !0), r = K(null);
665
- L(() => {
665
+ A(() => {
666
666
  let d;
667
667
  return r.current && (d = e.registerContainerElement(r.current)), () => d == null ? void 0 : d.dispose();
668
668
  }, [e]);
@@ -673,7 +673,7 @@ function jt() {
673
673
  (d) => n.setContextValue(ye, d),
674
674
  [n]
675
675
  );
676
- return L(() => {
676
+ return A(() => {
677
677
  var S;
678
678
  const d = It(document, "focusin").subscribe((p) => {
679
679
  var u;
@@ -684,7 +684,7 @@ function jt() {
684
684
  };
685
685
  }, [a, c]), /* @__PURE__ */ l("div", { ref: r, children: i.replaceRevealed ? /* @__PURE__ */ l(Bt, { ref: s }) : /* @__PURE__ */ l(Wt, { ref: s }) });
686
686
  }
687
- function kt(t) {
687
+ function jt(t) {
688
688
  const e = t.getCurrentLocale();
689
689
  return te(() => [
690
690
  { label: t.t("find-replace.dialog.find-scope.current-sheet"), value: Z.SUBUNIT },
@@ -801,8 +801,8 @@ var ei = Object.getOwnPropertyDescriptor, ti = (t, e, n, i) => {
801
801
  (a = t[s]) && (r = a(r) || r);
802
802
  return r;
803
803
  }, m = (t, e) => (n, i) => e(n, i, t);
804
- const de = "DESKTOP_FIND_REPLACE_DIALOG", we = 350, ii = 20, ni = -90;
805
- let U = class extends dt {
804
+ const de = "DESKTOP_FIND_REPLACE_DIALOG", we = 350, ii = 20, ni = 64;
805
+ let w = class extends dt {
806
806
  constructor(e, n, i, r, s, a, c, d, S, p) {
807
807
  super();
808
808
  o(this, "_closingListenerDisposable");
@@ -836,7 +836,7 @@ let U = class extends dt {
836
836
  ].forEach((e) => this.disposeWithMe(this._shortcutService.registerShortcut(e)));
837
837
  }
838
838
  _initUI() {
839
- this.disposeWithMe(this._componentManager.register("FindReplaceDialog", jt)), this.disposeWithMe(this._componentManager.register("SearchIcon", Ie)), this._menuManagerService.mergeMenu(Xt), this._findReplaceService.stateUpdates$.pipe(ae(this.dispose$)).subscribe((e) => {
839
+ this.disposeWithMe(this._componentManager.register("FindReplaceDialog", kt)), this.disposeWithMe(this._componentManager.register("SearchIcon", Ie)), this._menuManagerService.mergeMenu(Xt), this._findReplaceService.stateUpdates$.pipe(ae(this.dispose$)).subscribe((e) => {
840
840
  e.revealed === !0 && this._openPanel();
841
841
  });
842
842
  }
@@ -848,10 +848,12 @@ let U = class extends dt {
848
848
  title: { title: this._localeService.t("find-replace.dialog.title") },
849
849
  children: { label: "FindReplaceDialog" },
850
850
  destroyOnClose: !0,
851
+ mask: !1,
852
+ maskClosable: !1,
851
853
  defaultPosition: ri(),
852
854
  preservePositionOnDestroy: !0,
853
855
  onClose: () => this.closePanel()
854
- }), this._closingListenerDisposable = A(this._univerInstanceService.focused$.pipe(ae(this.dispose$)).subscribe((e) => {
856
+ }), this._closingListenerDisposable = $(this._univerInstanceService.focused$.pipe(ae(this.dispose$)).subscribe((e) => {
855
857
  (!e || !this._univerInstanceService.getUniverSheetInstance(e)) && this.closePanel();
856
858
  }));
857
859
  }
@@ -859,21 +861,21 @@ let U = class extends dt {
859
861
  this._closingListenerDisposable && (this._closingListenerDisposable.dispose(), this._closingListenerDisposable = null, this._dialogService.close(de), this._findReplaceService.terminate(), queueMicrotask(() => this._layoutService.focus()));
860
862
  }
861
863
  };
862
- U = ti([
864
+ w = ti([
863
865
  m(0, fe),
864
866
  m(1, vt),
865
867
  m(2, St),
866
- m(3, W),
868
+ m(3, U),
867
869
  m(4, g),
868
870
  m(5, Ct),
869
871
  m(6, me),
870
- m(7, D(B)),
872
+ m(7, D(W)),
871
873
  m(8, D(Mt)),
872
874
  m(9, D(Q))
873
- ], U);
875
+ ], w);
874
876
  function ri() {
875
877
  const { innerWidth: t } = window;
876
- return { x: (t - we) / 2 - ii, y: ni };
878
+ return { x: t - we - ii, y: ni };
877
879
  }
878
880
  var si = Object.getOwnPropertyDescriptor, ai = (t, e, n, i) => {
879
881
  for (var r = i > 1 ? void 0 : i ? si(e, n) : e, s = t.length - 1, a; s >= 0; s--)
@@ -881,8 +883,8 @@ var si = Object.getOwnPropertyDescriptor, ai = (t, e, n, i) => {
881
883
  return r;
882
884
  }, he = (t, e) => (n, i) => e(n, i, t);
883
885
  const oi = "UNIVER_FIND_REPLACE_PLUGIN";
884
- var H;
885
- let ue = (H = class extends ut {
886
+ var G;
887
+ let ue = (G = class extends ut {
886
888
  constructor(t = le, e, n) {
887
889
  super(), this._config = t, this._injector = e, this._configService = n;
888
890
  const { ...i } = ft(
@@ -894,14 +896,14 @@ let ue = (H = class extends ut {
894
896
  }
895
897
  onStarting() {
896
898
  [
897
- [U],
899
+ [w],
898
900
  [g, { useClass: J }]
899
901
  ].forEach((t) => this._injector.add(t));
900
902
  }
901
903
  onRendered() {
902
- this._injector.get(U);
904
+ this._injector.get(w);
903
905
  }
904
- }, o(H, "pluginName", oi), H);
906
+ }, o(G, "pluginName", oi), G);
905
907
  ue = ai([
906
908
  he(1, D(Q)),
907
909
  he(2, ht)
@@ -910,7 +912,7 @@ export {
910
912
  Y as FindBy,
911
913
  z as FindDirection,
912
914
  gi as FindModel,
913
- U as FindReplaceController,
915
+ w as FindReplaceController,
914
916
  q as FindReplaceModel,
915
917
  wt as FindReplaceState,
916
918
  Z as FindScope,
package/lib/index.css CHANGED
@@ -1 +1 @@
1
- .univer-relative{position:relative}.univer-mt-4{margin-top:1rem}.univer-mt-6{margin-top:1.5rem}.univer-flex{display:flex}.univer-inline-flex{display:inline-flex}.univer-cursor-pointer{cursor:pointer}.univer-items-center{align-items:center}.univer-justify-between{justify-content:space-between}.univer-gap-2{gap:.5rem}.univer-text-center{text-align:center}.univer-text-sm{font-size:.875rem;line-height:1.25rem}.univer-text-primary-500{--tw-text-opacity: 1;color:#466af7;color:rgba(70,106,247,var(--tw-text-opacity, 1))}.univer-transition-colors{transition-property:color,background-color,border-color,text-decoration-color,fill,stroke;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.hover\:univer-text-primary-500\/80:hover{color:#466af7cc}
1
+ .univer-relative{position:relative}.univer-mt-4{margin-top:16px}.univer-mt-6{margin-top:24px}.univer-flex{display:flex}.univer-inline-flex{display:inline-flex}.univer-cursor-pointer{cursor:pointer}.univer-items-center{align-items:center}.univer-justify-between{justify-content:space-between}.univer-gap-2{gap:8px}.univer-text-center{text-align:center}.univer-text-sm{font-size:14px;line-height:20px}.univer-text-primary-500{--tw-text-opacity: 1;color:#466af7;color:rgba(70,106,247,var(--tw-text-opacity, 1))}.univer-transition-colors{transition-property:color,background-color,border-color,text-decoration-color,fill,stroke;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.hover\:univer-text-primary-500\/80:hover{color:#466af7cc}
package/lib/index.js CHANGED
@@ -1,13 +1,13 @@
1
1
  var st = Object.defineProperty;
2
2
  var at = (t, e, n) => e in t ? st(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
3
  var o = (t, e, n) => at(t, typeof e != "symbol" ? e + "" : e, n);
4
- import { createIdentifier as ot, Inject as D, Injector as Q, IContextService as X, Disposable as ee, DisposableCollection as ct, toDisposable as A, IUniverInstanceService as fe, ICommandService as W, CommandType as I, LocaleService as B, FOCUSING_SHEET as pe, EDITOR_ACTIVATED as _e, UniverInstanceType as lt, RxDisposable as dt, IConfigService as ht, Plugin as ut, merge as ft } from "@univerjs/core";
4
+ import { createIdentifier as ot, Inject as D, Injector as Q, IContextService as X, Disposable as ee, DisposableCollection as ct, toDisposable as $, IUniverInstanceService as fe, ICommandService as U, CommandType as I, LocaleService as W, FOCUSING_SHEET as pe, EDITOR_ACTIVATED as _e, UniverInstanceType as lt, RxDisposable as dt, IConfigService as ht, Plugin as ut, merge as ft } from "@univerjs/core";
5
5
  import { IConfirmService as pt, IMessageService as ge, useDependency as v, useObservable as x, ILayoutService as me, KeyCode as C, MetaKeys as y, getMenuHiddenObservable as _t, MenuItemType as gt, RibbonStartGroup as mt, IMenuManagerService as vt, IShortcutService as St, IDialogService as Ct, ComponentManager as Mt } from "@univerjs/ui";
6
6
  import { throttleTime as Rt, BehaviorSubject as P, combineLatest as ve, debounceTime as bt, Subject as Se, fromEvent as It, map as yt, takeUntil as ae } from "rxjs";
7
- import { MessageType as N, Input as Ce, Pager as Ft, FormLayout as R, Select as V, FormDualColumnLayout as oe, Checkbox as ce, Button as G } from "@univerjs/design";
7
+ import { MessageType as N, Input as Ce, Pager as Ft, FormLayout as R, Select as j, FormDualColumnLayout as oe, Checkbox as ce, Button as V } from "@univerjs/design";
8
8
  import { RENDER_RAW_FORMULA_KEY as Dt } from "@univerjs/engine-render";
9
- import { jsxs as b, jsx as l, Fragment as $ } from "react/jsx-runtime";
10
- import { forwardRef as j, useRef as K, createElement as Me, useCallback as f, useEffect as L, useMemo as te, useImperativeHandle as xt } from "react";
9
+ import { jsxs as b, jsx as l, Fragment as H } from "react/jsx-runtime";
10
+ import { forwardRef as B, useRef as K, createElement as Me, useCallback as f, useEffect as A, useMemo as te, useImperativeHandle as xt } from "react";
11
11
  const Pt = "find-replace.config", le = {};
12
12
  var _ = function() {
13
13
  return _ = Object.assign || function(t) {
@@ -24,7 +24,7 @@ var _ = function() {
24
24
  for (var r = 0, i = Object.getOwnPropertySymbols(t); r < i.length; r++)
25
25
  e.indexOf(i[r]) < 0 && Object.prototype.propertyIsEnumerable.call(t, i[r]) && (n[i[r]] = t[i[r]]);
26
26
  return n;
27
- }, Re = j(function(t, e) {
27
+ }, Re = B(function(t, e) {
28
28
  var n = t.icon, i = t.id, r = t.className, s = t.extend, a = Tt(t, ["icon", "id", "className", "extend"]), c = "univerjs-icon univerjs-icon-".concat(i, " ").concat(r || "").trim(), d = K("_".concat(Nt()));
29
29
  return be(n, "".concat(i), { defIds: n.defIds, idSuffix: d.current }, _({ ref: e, className: c }, a), s);
30
30
  });
@@ -55,7 +55,7 @@ function Nt() {
55
55
  return Math.random().toString(36).substring(2, 8);
56
56
  }
57
57
  Re.displayName = "UniverIcon";
58
- var $t = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M7.71899 1.36938C4.37604 1.36938 1.66602 4.07941 1.66602 7.42236C1.66602 10.7653 4.37604 13.4753 7.71899 13.4753C9.16744 13.4753 10.4971 12.9666 11.5389 12.118L13.6598 14.4109C13.8848 14.6542 14.2644 14.669 14.5077 14.444C14.7509 14.219 14.7657 13.8393 14.5407 13.5961L12.3906 11.2716C13.2536 10.2254 13.772 8.88442 13.772 7.42236C13.772 4.07941 11.0619 1.36938 7.71899 1.36938ZM2.86602 7.42236C2.86602 4.74215 5.03878 2.56938 7.71899 2.56938C10.3992 2.56938 12.572 4.74215 12.572 7.42236C12.572 10.1026 10.3992 12.2753 7.71899 12.2753C5.03878 12.2753 2.86602 10.1026 2.86602 7.42236Z", fillRule: "evenodd", clipRule: "evenodd" } }] }, Ie = j(function(t, e) {
58
+ var $t = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M7.71899 1.36938C4.37604 1.36938 1.66602 4.07941 1.66602 7.42236C1.66602 10.7653 4.37604 13.4753 7.71899 13.4753C9.16744 13.4753 10.4971 12.9666 11.5389 12.118L13.6598 14.4109C13.8848 14.6542 14.2644 14.669 14.5077 14.444C14.7509 14.219 14.7657 13.8393 14.5407 13.5961L12.3906 11.2716C13.2536 10.2254 13.772 8.88442 13.772 7.42236C13.772 4.07941 11.0619 1.36938 7.71899 1.36938ZM2.86602 7.42236C2.86602 4.74215 5.03878 2.56938 7.71899 2.56938C10.3992 2.56938 12.572 4.74215 12.572 7.42236C12.572 10.1026 10.3992 12.2753 7.71899 12.2753C5.03878 12.2753 2.86602 10.1026 2.86602 7.42236Z", fillRule: "evenodd", clipRule: "evenodd" } }] }, Ie = B(function(t, e) {
59
59
  return Me(Re, Object.assign({}, t, {
60
60
  id: "search-single",
61
61
  ref: e,
@@ -68,7 +68,7 @@ var At = Object.getOwnPropertyDescriptor, xe = (t, e, n, i) => {
68
68
  for (var r = i > 1 ? void 0 : i ? At(e, n) : e, s = t.length - 1, a; s >= 0; s--)
69
69
  (a = t[s]) && (r = a(r) || r);
70
70
  return r;
71
- }, w = (t, e) => (n, i) => e(n, i, t);
71
+ }, L = (t, e) => (n, i) => e(n, i, t);
72
72
  class gi extends ee {
73
73
  }
74
74
  const g = ot("find-replace.service");
@@ -141,10 +141,10 @@ let q = class extends ee {
141
141
  const s = this._matches = r.flat();
142
142
  s.length ? (this._moveToInitialMatch(this._findModels, !0), this._state.changeState({ matchesCount: s.length }), this.replaceables$.next(s.filter((a) => a.replaceable))) : (this._state.changeState({ matchesCount: 0, matchesPosition: 0 }), this.replaceables$.next([]));
143
143
  });
144
- e.forEach((r) => n.add(A(r.activelyChangingMatch$.subscribe((s) => {
144
+ e.forEach((r) => n.add($(r.activelyChangingMatch$.subscribe((s) => {
145
145
  const a = this._matches.findIndex((c) => c === s);
146
146
  this._state.changeState({ matchesPosition: a + 1 });
147
- })))), n.add(A(i));
147
+ })))), n.add($(i));
148
148
  }
149
149
  async replace() {
150
150
  return this._matchingModel ? this._matchingModel.replace(this._state.replaceString) : !1;
@@ -219,8 +219,8 @@ let q = class extends ee {
219
219
  }
220
220
  };
221
221
  q = xe([
222
- w(2, fe),
223
- w(3, W)
222
+ L(2, fe),
223
+ L(3, U)
224
224
  ], q);
225
225
  var z = /* @__PURE__ */ ((t) => (t.ROW = "row", t.COLUMN = "column", t))(z || {}), Y = /* @__PURE__ */ ((t) => (t.VALUE = "value", t.FORMULA = "formula", t))(Y || {}), Z = /* @__PURE__ */ ((t) => (t.SUBUNIT = "subunit", t.UNIT = "unit", t))(Z || {});
226
226
  function ie() {
@@ -428,7 +428,7 @@ let J = class extends ee {
428
428
  (e = this._model) == null || e.dispose(), this._model = null, this._toggleDisplayRawFormula(!1), this._toggleRevealReplace(!1);
429
429
  }
430
430
  registerFindReplaceProvider(e) {
431
- return this._providers.add(e), A(() => this._providers.delete(e));
431
+ return this._providers.add(e), $(() => this._providers.delete(e));
432
432
  }
433
433
  _toggleRevealReplace(e) {
434
434
  this._contextService.setContextValue(De, e);
@@ -438,8 +438,8 @@ let J = class extends ee {
438
438
  }
439
439
  };
440
440
  J = xe([
441
- w(0, D(Q)),
442
- w(1, X)
441
+ L(0, D(Q)),
442
+ L(1, X)
443
443
  ], J);
444
444
  const Pe = {
445
445
  id: "ui.command.replace-current-match",
@@ -449,7 +449,7 @@ const Pe = {
449
449
  id: "ui.command.replace-all-matches",
450
450
  type: I.COMMAND,
451
451
  handler: async (t) => {
452
- const e = t.get(pt), n = t.get(B), i = t.get(ge);
452
+ const e = t.get(pt), n = t.get(W), i = t.get(ge);
453
453
  if (!await e.confirm({
454
454
  id: Ut,
455
455
  title: { title: n.t("find-replace.replace.confirm.title") },
@@ -531,16 +531,16 @@ function Ae(t, e) {
531
531
  const r = document.querySelectorAll(".univer-find-replace-dialog-container .univer-select-selection-search-input");
532
532
  return Array.from(r).some((s) => s === document.activeElement);
533
533
  }, []);
534
- return xt(e, () => ({ focus: n, selectHasFocus: i })), L(() => {
534
+ return xt(e, () => ({ focus: n, selectHasFocus: i })), A(() => {
535
535
  const r = t.focusSignal$.subscribe(() => n());
536
536
  return () => r.unsubscribe();
537
537
  }, [t, n]), { focus: n, selectHasFocus: i };
538
538
  }
539
- const Wt = j(function(e, n) {
540
- const i = v(B), r = v(g), s = v(W), a = x(r.state$, void 0, !0), { findCompleted: c, findString: d, matchesCount: S, matchesPosition: p } = a, u = f(() => {
539
+ const Wt = B(function(e, n) {
540
+ const i = v(W), r = v(g), s = v(U), a = x(r.state$, void 0, !0), { findCompleted: c, findString: d, matchesCount: S, matchesPosition: p } = a, u = f(() => {
541
541
  s.executeCommand(ne.id);
542
542
  }, [s]), E = f((M) => r.changeFindString(M), [r]);
543
- return Ae(r, n), /* @__PURE__ */ b($, { children: [
543
+ return Ae(r, n), /* @__PURE__ */ b(H, { children: [
544
544
  /* @__PURE__ */ l(
545
545
  $e,
546
546
  {
@@ -566,8 +566,8 @@ const Wt = j(function(e, n) {
566
566
  }
567
567
  ) })
568
568
  ] });
569
- }), Bt = j(function(e, n) {
570
- const i = v(g), r = v(B), s = v(W), a = v(ge), c = x(i.currentMatch$, void 0, !0), d = x(i.replaceables$, void 0, !0), S = x(i.state$, void 0, !0), {
569
+ }), Bt = B(function(e, n) {
570
+ const i = v(g), r = v(W), s = v(U), a = v(ge), c = x(i.currentMatch$, void 0, !0), d = x(i.replaceables$, void 0, !0), S = x(i.state$, void 0, !0), {
571
571
  matchesCount: p,
572
572
  matchesPosition: u,
573
573
  findString: E,
@@ -575,8 +575,8 @@ const Wt = j(function(e, n) {
575
575
  replaceString: Ue,
576
576
  caseSensitive: We,
577
577
  matchesTheWholeCell: Be,
578
- findDirection: je,
579
- findScope: ke,
578
+ findDirection: ke,
579
+ findScope: je,
580
580
  findBy: Ve,
581
581
  findCompleted: k
582
582
  } = S, Ge = M.length === 0, He = p === 0 || !(c != null && c.replaceable), Ke = d.length === 0, qe = f(
@@ -595,14 +595,14 @@ const Wt = j(function(e, n) {
595
595
  i.changeFindScope(h);
596
596
  }, [i]), tt = f((h) => {
597
597
  i.changeFindBy(h);
598
- }, [i]), it = kt(r), nt = Vt(r), rt = Gt(r);
599
- return L(() => {
598
+ }, [i]), it = jt(r), nt = Vt(r), rt = Gt(r);
599
+ return A(() => {
600
600
  k && p === 0 && a.show({
601
601
  content: r.t("find-replace.dialog.no-match"),
602
602
  type: N.Warning,
603
603
  duration: 5e3
604
604
  });
605
- }, [k, p, a, r]), /* @__PURE__ */ b($, { children: [
605
+ }, [k, p, a, r]), /* @__PURE__ */ b("div", { className: "univer-theme", children: [
606
606
  /* @__PURE__ */ l(R, { label: r.t("find-replace.dialog.find"), children: /* @__PURE__ */ l(
607
607
  $e,
608
608
  {
@@ -624,12 +624,12 @@ const Wt = j(function(e, n) {
624
624
  onChange: (h) => ze(h)
625
625
  }
626
626
  ) }),
627
- /* @__PURE__ */ l(R, { label: r.t("find-replace.dialog.find-direction.title"), children: /* @__PURE__ */ l(V, { value: je, options: nt, onChange: Xe }) }),
628
- /* @__PURE__ */ l(oe, { children: /* @__PURE__ */ b($, { children: [
629
- /* @__PURE__ */ l(R, { label: r.t("find-replace.dialog.find-scope.title"), children: /* @__PURE__ */ l(V, { value: ke, options: it, onChange: et }) }),
630
- /* @__PURE__ */ l(R, { label: r.t("find-replace.dialog.find-by.title"), children: /* @__PURE__ */ l(V, { value: Ve, options: rt, onChange: tt }) })
627
+ /* @__PURE__ */ l(R, { label: r.t("find-replace.dialog.find-direction.title"), children: /* @__PURE__ */ l(j, { value: ke, options: nt, onChange: Xe }) }),
628
+ /* @__PURE__ */ l(oe, { children: /* @__PURE__ */ b(H, { children: [
629
+ /* @__PURE__ */ l(R, { label: r.t("find-replace.dialog.find-scope.title"), children: /* @__PURE__ */ l(j, { value: je, options: it, onChange: et }) }),
630
+ /* @__PURE__ */ l(R, { label: r.t("find-replace.dialog.find-by.title"), children: /* @__PURE__ */ l(j, { value: Ve, options: rt, onChange: tt }) })
631
631
  ] }) }),
632
- /* @__PURE__ */ l(oe, { children: /* @__PURE__ */ b($, { children: [
632
+ /* @__PURE__ */ l(oe, { children: /* @__PURE__ */ b(H, { children: [
633
633
  /* @__PURE__ */ l(R, { children: /* @__PURE__ */ l(
634
634
  ce,
635
635
  {
@@ -652,17 +652,17 @@ const Wt = j(function(e, n) {
652
652
  ) })
653
653
  ] }) }),
654
654
  /* @__PURE__ */ b("div", { className: "univer-mt-6 univer-flex univer-justify-between", children: [
655
- /* @__PURE__ */ l(G, { variant: "primary", onClick: Ze, disabled: Ge, children: r.t("find-replace.dialog.find") }),
655
+ /* @__PURE__ */ l(V, { variant: "primary", onClick: Ze, disabled: Ge, children: r.t("find-replace.dialog.find") }),
656
656
  /* @__PURE__ */ b("span", { className: "univer-inline-flex univer-gap-2", children: [
657
- /* @__PURE__ */ l(G, { disabled: He, onClick: Je, children: r.t("find-replace.dialog.replace") }),
658
- /* @__PURE__ */ l(G, { disabled: Ke, onClick: Qe, children: r.t("find-replace.dialog.replace-all") })
657
+ /* @__PURE__ */ l(V, { disabled: He, onClick: Je, children: r.t("find-replace.dialog.replace") }),
658
+ /* @__PURE__ */ l(V, { disabled: Ke, onClick: Qe, children: r.t("find-replace.dialog.replace-all") })
659
659
  ] })
660
660
  ] })
661
661
  ] });
662
662
  });
663
- function jt() {
663
+ function kt() {
664
664
  const t = v(g), e = v(me), n = v(X), i = x(t.state$, void 0, !0), r = K(null);
665
- L(() => {
665
+ A(() => {
666
666
  let d;
667
667
  return r.current && (d = e.registerContainerElement(r.current)), () => d == null ? void 0 : d.dispose();
668
668
  }, [e]);
@@ -673,7 +673,7 @@ function jt() {
673
673
  (d) => n.setContextValue(ye, d),
674
674
  [n]
675
675
  );
676
- return L(() => {
676
+ return A(() => {
677
677
  var S;
678
678
  const d = It(document, "focusin").subscribe((p) => {
679
679
  var u;
@@ -684,7 +684,7 @@ function jt() {
684
684
  };
685
685
  }, [a, c]), /* @__PURE__ */ l("div", { ref: r, children: i.replaceRevealed ? /* @__PURE__ */ l(Bt, { ref: s }) : /* @__PURE__ */ l(Wt, { ref: s }) });
686
686
  }
687
- function kt(t) {
687
+ function jt(t) {
688
688
  const e = t.getCurrentLocale();
689
689
  return te(() => [
690
690
  { label: t.t("find-replace.dialog.find-scope.current-sheet"), value: Z.SUBUNIT },
@@ -801,8 +801,8 @@ var ei = Object.getOwnPropertyDescriptor, ti = (t, e, n, i) => {
801
801
  (a = t[s]) && (r = a(r) || r);
802
802
  return r;
803
803
  }, m = (t, e) => (n, i) => e(n, i, t);
804
- const de = "DESKTOP_FIND_REPLACE_DIALOG", we = 350, ii = 20, ni = -90;
805
- let U = class extends dt {
804
+ const de = "DESKTOP_FIND_REPLACE_DIALOG", we = 350, ii = 20, ni = 64;
805
+ let w = class extends dt {
806
806
  constructor(e, n, i, r, s, a, c, d, S, p) {
807
807
  super();
808
808
  o(this, "_closingListenerDisposable");
@@ -836,7 +836,7 @@ let U = class extends dt {
836
836
  ].forEach((e) => this.disposeWithMe(this._shortcutService.registerShortcut(e)));
837
837
  }
838
838
  _initUI() {
839
- this.disposeWithMe(this._componentManager.register("FindReplaceDialog", jt)), this.disposeWithMe(this._componentManager.register("SearchIcon", Ie)), this._menuManagerService.mergeMenu(Xt), this._findReplaceService.stateUpdates$.pipe(ae(this.dispose$)).subscribe((e) => {
839
+ this.disposeWithMe(this._componentManager.register("FindReplaceDialog", kt)), this.disposeWithMe(this._componentManager.register("SearchIcon", Ie)), this._menuManagerService.mergeMenu(Xt), this._findReplaceService.stateUpdates$.pipe(ae(this.dispose$)).subscribe((e) => {
840
840
  e.revealed === !0 && this._openPanel();
841
841
  });
842
842
  }
@@ -848,10 +848,12 @@ let U = class extends dt {
848
848
  title: { title: this._localeService.t("find-replace.dialog.title") },
849
849
  children: { label: "FindReplaceDialog" },
850
850
  destroyOnClose: !0,
851
+ mask: !1,
852
+ maskClosable: !1,
851
853
  defaultPosition: ri(),
852
854
  preservePositionOnDestroy: !0,
853
855
  onClose: () => this.closePanel()
854
- }), this._closingListenerDisposable = A(this._univerInstanceService.focused$.pipe(ae(this.dispose$)).subscribe((e) => {
856
+ }), this._closingListenerDisposable = $(this._univerInstanceService.focused$.pipe(ae(this.dispose$)).subscribe((e) => {
855
857
  (!e || !this._univerInstanceService.getUniverSheetInstance(e)) && this.closePanel();
856
858
  }));
857
859
  }
@@ -859,21 +861,21 @@ let U = class extends dt {
859
861
  this._closingListenerDisposable && (this._closingListenerDisposable.dispose(), this._closingListenerDisposable = null, this._dialogService.close(de), this._findReplaceService.terminate(), queueMicrotask(() => this._layoutService.focus()));
860
862
  }
861
863
  };
862
- U = ti([
864
+ w = ti([
863
865
  m(0, fe),
864
866
  m(1, vt),
865
867
  m(2, St),
866
- m(3, W),
868
+ m(3, U),
867
869
  m(4, g),
868
870
  m(5, Ct),
869
871
  m(6, me),
870
- m(7, D(B)),
872
+ m(7, D(W)),
871
873
  m(8, D(Mt)),
872
874
  m(9, D(Q))
873
- ], U);
875
+ ], w);
874
876
  function ri() {
875
877
  const { innerWidth: t } = window;
876
- return { x: (t - we) / 2 - ii, y: ni };
878
+ return { x: t - we - ii, y: ni };
877
879
  }
878
880
  var si = Object.getOwnPropertyDescriptor, ai = (t, e, n, i) => {
879
881
  for (var r = i > 1 ? void 0 : i ? si(e, n) : e, s = t.length - 1, a; s >= 0; s--)
@@ -881,8 +883,8 @@ var si = Object.getOwnPropertyDescriptor, ai = (t, e, n, i) => {
881
883
  return r;
882
884
  }, he = (t, e) => (n, i) => e(n, i, t);
883
885
  const oi = "UNIVER_FIND_REPLACE_PLUGIN";
884
- var H;
885
- let ue = (H = class extends ut {
886
+ var G;
887
+ let ue = (G = class extends ut {
886
888
  constructor(t = le, e, n) {
887
889
  super(), this._config = t, this._injector = e, this._configService = n;
888
890
  const { ...i } = ft(
@@ -894,14 +896,14 @@ let ue = (H = class extends ut {
894
896
  }
895
897
  onStarting() {
896
898
  [
897
- [U],
899
+ [w],
898
900
  [g, { useClass: J }]
899
901
  ].forEach((t) => this._injector.add(t));
900
902
  }
901
903
  onRendered() {
902
- this._injector.get(U);
904
+ this._injector.get(w);
903
905
  }
904
- }, o(H, "pluginName", oi), H);
906
+ }, o(G, "pluginName", oi), G);
905
907
  ue = ai([
906
908
  he(1, D(Q)),
907
909
  he(2, ht)
@@ -910,7 +912,7 @@ export {
910
912
  Y as FindBy,
911
913
  z as FindDirection,
912
914
  gi as FindModel,
913
- U as FindReplaceController,
915
+ w as FindReplaceController,
914
916
  q as FindReplaceModel,
915
917
  wt as FindReplaceState,
916
918
  Z as FindScope,
package/lib/umd/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  (function(d,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/design"),require("@univerjs/engine-render"),require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/ui","rxjs","@univerjs/design","@univerjs/engine-render","react/jsx-runtime","react"],o):(d=typeof globalThis<"u"?globalThis:d||self,o(d.UniverFindReplace={},d.UniverCore,d.UniverUi,d.rxjs,d.UniverDesign,d.UniverEngineRender,d.React,d.React))})(this,function(d,o,c,m,_,re,h,f){"use strict";var ot=Object.defineProperty;var ct=(d,o,c)=>o in d?ot(d,o,{enumerable:!0,configurable:!0,writable:!0,value:c}):d[o]=c;var u=(d,o,c)=>ct(d,typeof o!="symbol"?o+"":o,c);var W;const oe="find-replace.config",V={};var b=function(){return b=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},b.apply(this,arguments)},ce=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},K=f.forwardRef(function(t,e){var n=t.icon,i=t.id,s=t.className,a=t.extend,r=ce(t,["icon","id","className","extend"]),l="univerjs-icon univerjs-icon-".concat(i," ").concat(s||"").trim(),p=f.useRef("_".concat(he()));return H(n,"".concat(i),{defIds:n.defIds,idSuffix:p.current},b({ref:e,className:l},r),a)});function H(t,e,n,i,s){return f.createElement(t.tag,b(b({key:e},le(t,n,s)),i),(de(t,n).children||[]).map(function(a,r){return H(a,"".concat(e,"-").concat(t.tag,"-").concat(r),n,void 0,s)}))}function le(t,e,n){var i=b({},t.attrs);n!=null&&n.colorChannel1&&i.fill==="colorChannel1"&&(i.fill=n.colorChannel1),t.tag==="mask"&&i.id&&(i.id=i.id+e.idSuffix),Object.entries(i).forEach(function(a){var r=a[0],l=a[1];r==="mask"&&typeof l=="string"&&(i[r]=l.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))});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(a){var r=a[0],l=a[1];typeof l=="string"&&(i[r]=l.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),i}function de(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)?b(b({},t),{children:t.children.map(function(s){return typeof s.attrs.id=="string"&&i&&i.indexOf(s.attrs.id)>-1?b(b({},s),{attrs:b(b({},s.attrs),{id:s.attrs.id+e.idSuffix})}):s})}):t}function he(){return Math.random().toString(36).substring(2,8)}K.displayName="UniverIcon";var ue={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M7.71899 1.36938C4.37604 1.36938 1.66602 4.07941 1.66602 7.42236C1.66602 10.7653 4.37604 13.4753 7.71899 13.4753C9.16744 13.4753 10.4971 12.9666 11.5389 12.118L13.6598 14.4109C13.8848 14.6542 14.2644 14.669 14.5077 14.444C14.7509 14.219 14.7657 13.8393 14.5407 13.5961L12.3906 11.2716C13.2536 10.2254 13.772 8.88442 13.772 7.42236C13.772 4.07941 11.0619 1.36938 7.71899 1.36938ZM2.86602 7.42236C2.86602 4.74215 5.03878 2.56938 7.71899 2.56938C10.3992 2.56938 12.572 4.74215 12.572 7.42236C12.572 10.1026 10.3992 12.2753 7.71899 12.2753C5.03878 12.2753 2.86602 10.1026 2.86602 7.42236Z",fillRule:"evenodd",clipRule:"evenodd"}}]},q=f.forwardRef(function(t,e){return f.createElement(K,Object.assign({},t,{id:"search-single",ref:e,icon:ue}))});q.displayName="SearchSingle";const z="FIND_REPLACE_INPUT_FOCUS",Y="FIND_REPLACE_DIALOG_FOCUS",Z="FIND_REPLACE_REPLACE_REVEALED";var fe=Object.getOwnPropertyDescriptor,J=(t,e,n,i)=>{for(var s=i>1?void 0:i?fe(e,n):e,a=t.length-1,r;a>=0;a--)(r=t[a])&&(s=r(s)||s);return s},T=(t,e)=>(n,i)=>e(n,i,t);class pe extends o.Disposable{}const S=o.createIdentifier("find-replace.service");function _e(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"}d.FindReplaceModel=class extends o.Disposable{constructor(n,i,s,a){super();u(this,"currentMatch$",new m.BehaviorSubject(null));u(this,"replaceables$",new m.BehaviorSubject([]));u(this,"_findModels",[]);u(this,"_matchingModel",null);u(this,"_matches",[]);u(this,"_currentSearchingDisposables",null);this._state=n,this._providers=i,this._univerInstanceService=s,this._commandService=a,this.disposeWithMe(this._state.stateUpdates$.pipe(m.throttleTime(200,void 0,{leading:!0,trailing:!0})).subscribe(async r=>{const l=this._state.state;_e(r)&&(l.findString!==""&&!l.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({...N(),revealed:!1})}async start(){if(!this._state.findString)return{results:[]};const n=await this._startSearching();return this._state.changeState({findCompleted:!0}),n}focusSelection(){var n;(n=this._matchingModel)==null||n.focusSelection()}async _startSearching(){if(!this._state.findString)return{results:[]};const n=Array.from(this._providers),i=this._findModels=(await Promise.all(n.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 s=this._matches=i.map(a=>a.getMatches()).flat();return this.replaceables$.next(s.filter(a=>a.replaceable)),s.length?(this._moveToInitialMatch(i),this._state.changeState({matchesCount:s.length}),{results:s}):(this._state.changeState({matchesCount:0,matchesPosition:0}),{results:[]})}_stopSearching(){var n;this._providers.forEach(i=>i.terminate()),this._findModels=[],this._matches=[],this._matchingModel=null,(n=this._currentSearchingDisposables)==null||n.dispose(),this._currentSearchingDisposables=null,this.currentMatch$.next(null),this.replaceables$.next([]),this._state.changeState({findCompleted:!1,matchesCount:0,matchesPosition:0})}_subscribeToModelsChanges(n){const i=this._currentSearchingDisposables=new o.DisposableCollection,s=m.combineLatest(n.map(a=>a.matchesUpdate$)).pipe(m.debounceTime(220)).subscribe(([...a])=>{const r=this._matches=a.flat();r.length?(this._moveToInitialMatch(this._findModels,!0),this._state.changeState({matchesCount:r.length}),this.replaceables$.next(r.filter(l=>l.replaceable))):(this._state.changeState({matchesCount:0,matchesPosition:0}),this.replaceables$.next([]))});n.forEach(a=>i.add(o.toDisposable(a.activelyChangingMatch$.subscribe(r=>{const l=this._matches.findIndex(p=>p===r);this._state.changeState({matchesPosition:l+1})})))),i.add(o.toDisposable(s))}async replace(){return this._matchingModel?this._matchingModel.replace(this._state.replaceString):!1}async replaceAll(){const n=await Promise.all(this._findModels.map(i=>i.replaceAll(this._state.replaceString))).then(i=>i.reduce((s,a)=>(s.success+=a.success,s.failure+=a.failure,s),{success:0,failure:0}));return n.failure===0&&this._stopSearching(),n}getCurrentMatch(){return this._state.matchesPosition>0?this._matches[this._state.matchesPosition-1]:null}_markMatch(n){const i=this._matches.findIndex(s=>s===n);this.currentMatch$.next(n),this._state.changeState({matchesPosition:i+1})}moveToNextMatch(){if(!this._matchingModel)return;const n=this._findModels.length===1,i=this._matchingModel.moveToNextMatch({loop:n});if(i)return this._markMatch(i),i;{const s=this._findModels.findIndex(a=>a===this._matchingModel);return this._moveToNextUnitMatch(s)}}_moveToNextUnitMatch(n){const i=this._findModels.length;for(let s=(n+1)%i;s!==n;){const a=this._findModels[s],r=a.moveToNextMatch({ignoreSelection:!0});if(r)return this._matchingModel=a,this._markMatch(r),r;s=(s+1)%i}if(this._matchingModel){const s=this._matchingModel.moveToNextMatch({ignoreSelection:!0});return s&&this._markMatch(s),s}}moveToPreviousMatch(){if(!this._matchingModel)return;const n=this._findModels.length===1,i=this._matchingModel.moveToPreviousMatch({loop:n});if(i){const s=this._matches.findIndex(a=>a===i);return this.currentMatch$.next(i),this._state.changeState({matchesPosition:s+1}),i}else{const s=this._findModels.length,a=this._findModels.findIndex(l=>l===this._matchingModel);for(let l=(a-1+s)%s;l!==a;){const p=this._findModels[l],C=p.moveToPreviousMatch({ignoreSelection:!0});if(C)return this._matchingModel=p,this._markMatch(C),C;l=(l-1)%s}const r=this._matchingModel.moveToPreviousMatch({ignoreSelection:!0});return r&&this._markMatch(r),r}}_moveToInitialMatch(n,i=!1){var r;const s=(r=this._univerInstanceService.getFocusedUnit())==null?void 0:r.getUnitId();if(!s)return-1;const a=n.findIndex(l=>l.unitId===s);if(a!==-1){this._matchingModel=n[a];const l=this._matchingModel.moveToNextMatch({stayIfOnMatch:!0,noFocus:i});if(l)return this._markMatch(l),a}return this._moveToNextUnitMatch(a),0}},d.FindReplaceModel=J([T(2,o.IUniverInstanceService),T(3,o.ICommandService)],d.FindReplaceModel);var O=(t=>(t.ROW="row",t.COLUMN="column",t))(O||{}),P=(t=>(t.VALUE="value",t.FORMULA="formula",t))(P||{}),E=(t=>(t.SUBUNIT="subunit",t.UNIT="unit",t))(E||{});function N(){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 Q{constructor(){u(this,"_stateUpdates$",new m.Subject);u(this,"stateUpdates$",this._stateUpdates$.asObservable());u(this,"_state$",new m.BehaviorSubject(N()));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 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 A=class extends o.Disposable{constructor(e,n){super();u(this,"_providers",new Set);u(this,"_state",new Q);u(this,"_model");u(this,"_currentMatch$",new m.BehaviorSubject(null));u(this,"currentMatch$",this._currentMatch$.asObservable());u(this,"_replaceables$",new m.BehaviorSubject([]));u(this,"replaceables$",this._replaceables$.asObservable());u(this,"_focusSignal$",new m.Subject);u(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()}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)}focusSelection(){var e;(e=this._model)==null||e.focusSelection()}start(e=!1){if(this._providers.size===0)return!1;this._model=this._injector.createInstance(d.FindReplaceModel,this._state,this._providers),this._model.currentMatch$.subscribe(i=>this._currentMatch$.next(i)),this._model.replaceables$.subscribe(i=>this._replaceables$.next(i));const n=N();return e&&(n.replaceRevealed=!0),this._state.changeState(n),this._toggleRevealReplace(e),!0}find(){var e;(e=this._model)==null||e.start()}terminate(){var e;(e=this._model)==null||e.dispose(),this._model=null,this._toggleDisplayRawFormula(!1),this._toggleRevealReplace(!1)}registerFindReplaceProvider(e){return this._providers.add(e),o.toDisposable(()=>this._providers.delete(e))}_toggleRevealReplace(e){this._contextService.setContextValue(Z,e)}_toggleDisplayRawFormula(e){this._contextService.setContextValue(re.RENDER_RAW_FORMULA_KEY,e)}};A=J([T(0,o.Inject(o.Injector)),T(1,o.IContextService)],A);const x={id:"ui.command.replace-current-match",type:o.CommandType.COMMAND,handler:t=>t.get(S).replace()},ge="CONFIRM_REPLACE_ALL",U={id:"ui.command.replace-all-matches",type:o.CommandType.COMMAND,handler:async t=>{const e=t.get(c.IConfirmService),n=t.get(o.LocaleService),i=t.get(c.IMessageService);if(!await e.confirm({id:ge,title:{title:n.t("find-replace.replace.confirm.title")},cancelText:n.t("button.cancel"),confirmText:n.t("button.confirm")}))return!1;const a=await t.get(S).replaceAll(),{success:r,failure:l}=a;return l>0?(r===0?i.show({type:_.MessageType.Error,content:n.t("find-replace.replace.all-failure")}):i.show({type:_.MessageType.Warning,content:n.t("find-replace.replace.partial-success",`${r}`,`${l}`)}),!1):(i.show({type:_.MessageType.Success,content:n.t("find-replace.replace.all-success",`${r}`)}),!0)}},F={id:"ui.operation.open-find-dialog",type:o.CommandType.OPERATION,handler:t=>{const e=t.get(S);return e.revealed?e.focusFindInput():e.start(),!0}},L={id:"ui.operation.open-replace-dialog",type:o.CommandType.OPERATION,handler:t=>{const e=t.get(S);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(S).moveToNextMatch(),!0)},k={type:o.CommandType.OPERATION,id:"ui.operation.go-to-previous-match",handler:t=>(t.get(S).moveToPreviousMatch(),!0)},X={type:o.CommandType.OPERATION,id:"ui.operation.focus-selection",handler:t=>(t.get(S).focusSelection(),!0)};function ee(t){const{findCompleted:e,localeService:n,matchesCount:i,matchesPosition:s,findString:a,findReplaceService:r,onChange:l,...p}=t,M=e&&i===0?n.t("find-replace.dialog.no-result"):i===0?" ":void 0;return h.jsxs("div",{className:"univer-relative univer-flex univer-items-center univer-gap-2",onDrag:g=>g.stopPropagation(),children:[h.jsx(_.Input,{autoFocus:!0,placeholder:n.t("find-replace.dialog.find-placeholder"),value:a,onChange:g=>l==null?void 0:l(g),...p}),h.jsx(_.Pager,{loop:!0,text:M,value:s,total:i,onChange:g=>{s===i&&g===1?r.moveToNextMatch():s===1&&g===i||g<s?r.moveToPreviousMatch():r.moveToNextMatch()}})]})}function te(t,e){const n=f.useCallback(()=>{var s;(s=document.querySelector(".univer-find-input input"))==null||s.focus()},[]),i=f.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 f.useImperativeHandle(e,()=>({focus:n,selectHasFocus:i})),f.useEffect(()=>{const s=t.focusSignal$.subscribe(()=>n());return()=>s.unsubscribe()},[t,n]),{focus:n,selectHasFocus:i}}const ve=f.forwardRef(function(e,n){const i=c.useDependency(o.LocaleService),s=c.useDependency(S),a=c.useDependency(o.ICommandService),r=c.useObservable(s.state$,void 0,!0),{findCompleted:l,findString:p,matchesCount:C,matchesPosition:M}=r,g=f.useCallback(()=>{a.executeCommand(L.id)},[a]),$=f.useCallback(I=>s.changeFindString(I),[s]);return te(s,n),h.jsxs(h.Fragment,{children:[h.jsx(ee,{findCompleted:l,className:"univer-find-input",matchesCount:C,matchesPosition:M,findReplaceService:s,localeService:i,findString:p,onChange:$}),h.jsx("div",{className:"univer-mt-4 univer-text-center",children:h.jsx("a",{className:`
2
2
  univer-cursor-pointer univer-text-sm univer-text-primary-500 univer-transition-colors
3
3
  hover:univer-text-primary-500/80
4
- `,onClick:g,children:i.t("find-replace.dialog.advanced-finding")})})]})}),me=f.forwardRef(function(e,n){const i=c.useDependency(S),s=c.useDependency(o.LocaleService),a=c.useDependency(o.ICommandService),r=c.useDependency(c.IMessageService),l=c.useObservable(i.currentMatch$,void 0,!0),p=c.useObservable(i.replaceables$,void 0,!0),C=c.useObservable(i.state$,void 0,!0),{matchesCount:M,matchesPosition:g,findString:$,inputtingFindString:I,replaceString:Be,caseSensitive:je,matchesTheWholeCell:We,findDirection:Ge,findScope:Ve,findBy:Ke,findCompleted:G}=C,He=I.length===0,qe=M===0||!(l!=null&&l.replaceable),ze=p.length===0,Ye=f.useCallback(v=>i.changeInputtingFindString(v),[i]),Ze=f.useCallback(v=>i.changeReplaceString(v),[i]),{focus:Je}=te(i,n),Qe=f.useCallback(()=>{$===I?i.moveToNextMatch():(i.changeFindString(I),i.find())},[$,I,i]),Xe=f.useCallback(()=>a.executeCommand(x.id),[a]),et=f.useCallback(async()=>{await a.executeCommand(U.id),Je()},[a]),tt=f.useCallback(v=>{i.changeFindDirection(v)},[i]),it=f.useCallback(v=>{i.changeFindScope(v)},[i]),nt=f.useCallback(v=>{i.changeFindBy(v)},[i]),st=Ce(s),at=Me(s),rt=be(s);return f.useEffect(()=>{G&&M===0&&r.show({content:s.t("find-replace.dialog.no-match"),type:_.MessageType.Warning,duration:5e3})},[G,M,r,s]),h.jsxs(h.Fragment,{children:[h.jsx(_.FormLayout,{label:s.t("find-replace.dialog.find"),children:h.jsx(ee,{findCompleted:G,className:"univer-find-input",matchesCount:M,matchesPosition:g,findReplaceService:i,localeService:s,findString:I,onChange:Ye})}),h.jsx(_.FormLayout,{label:s.t("find-replace.dialog.replace"),children:h.jsx(_.Input,{placeholder:s.t("find-replace.dialog.replace-placeholder"),value:Be,onChange:v=>Ze(v)})}),h.jsx(_.FormLayout,{label:s.t("find-replace.dialog.find-direction.title"),children:h.jsx(_.Select,{value:Ge,options:at,onChange:tt})}),h.jsx(_.FormDualColumnLayout,{children:h.jsxs(h.Fragment,{children:[h.jsx(_.FormLayout,{label:s.t("find-replace.dialog.find-scope.title"),children:h.jsx(_.Select,{value:Ve,options:st,onChange:it})}),h.jsx(_.FormLayout,{label:s.t("find-replace.dialog.find-by.title"),children:h.jsx(_.Select,{value:Ke,options:rt,onChange:nt})})]})}),h.jsx(_.FormDualColumnLayout,{children:h.jsxs(h.Fragment,{children:[h.jsx(_.FormLayout,{children:h.jsx(_.Checkbox,{checked:je,onChange:v=>{i.changeCaseSensitive(v)},children:s.t("find-replace.dialog.case-sensitive")})}),h.jsx(_.FormLayout,{children:h.jsx(_.Checkbox,{checked:We,onChange:v=>{i.changeMatchesTheWholeCell(v)},children:s.t("find-replace.dialog.match-the-whole-cell")})})]})}),h.jsxs("div",{className:"univer-mt-6 univer-flex univer-justify-between",children:[h.jsx(_.Button,{variant:"primary",onClick:Qe,disabled:He,children:s.t("find-replace.dialog.find")}),h.jsxs("span",{className:"univer-inline-flex univer-gap-2",children:[h.jsx(_.Button,{disabled:qe,onClick:Xe,children:s.t("find-replace.dialog.replace")}),h.jsx(_.Button,{disabled:ze,onClick:et,children:s.t("find-replace.dialog.replace-all")})]})]})]})});function Se(){const t=c.useDependency(S),e=c.useDependency(c.ILayoutService),n=c.useDependency(o.IContextService),i=c.useObservable(t.state$,void 0,!0),s=f.useRef(null);f.useEffect(()=>{let p;return s.current&&(p=e.registerContainerElement(s.current)),()=>p==null?void 0:p.dispose()},[e]);const a=f.useRef(null),r=f.useCallback(p=>n.setContextValue(Y,p),[n]),l=f.useCallback(p=>n.setContextValue(z,p),[n]);return f.useEffect(()=>{var C;const p=m.fromEvent(document,"focusin").subscribe(M=>{var g;M.target&&((g=s.current)!=null&&g.contains(M.target))?r(!0):r(!1),!a.current||!a.current.selectHasFocus()?l(!0):l(!1)});return(C=a.current)==null||C.focus(),r(!0),l(!0),()=>{p.unsubscribe(),r(!1)}},[r,l]),h.jsx("div",{ref:s,children:i.replaceRevealed?h.jsx(me,{ref:a}):h.jsx(ve,{ref:a})})}function Ce(t){const e=t.getCurrentLocale();return f.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 Me(t){const e=t.getCurrentLocale();return f.useMemo(()=>[{label:t.t("find-replace.dialog.find-direction.row"),value:O.ROW},{label:t.t("find-replace.dialog.find-direction.column"),value:O.COLUMN}],[e])}function be(t){const e=t.getCurrentLocale();return f.useMemo(()=>[{label:t.t("find-replace.dialog.find-by.value"),value:P.VALUE},{label:t.t("find-replace.dialog.find-by.formula"),value:P.FORMULA}],[e])}function R(t){return t.getContextValue(Y)}function ye(t){return t.getContextValue(Z)}function ie(t){return t.getContextValue(z)}const D="7_find-replace-shortcuts";function B(t){return t.getContextValue(o.FOCUSING_SHEET)}function j(t){return!t.getContextValue(o.EDITOR_ACTIVATED)}const Ie={id:F.id,description:"find-replace.shortcut.open-find-dialog",binding:c.KeyCode.F|c.MetaKeys.CTRL_COMMAND,group:D,preconditions(t){return!R(t)&&B(t)&&j(t)}},Fe={id:F.id,description:"find-replace.shortcut.open-find-dialog",binding:c.KeyCode.F|c.MetaKeys.CTRL_COMMAND,mac:c.KeyCode.F|c.MetaKeys.MAC_CTRL,preconditions(t){return!R(t)&&B(t)&&j(t)}},Re={id:L.id,description:"find-replace.shortcut.open-replace-dialog",binding:c.KeyCode.H|c.MetaKeys.CTRL_COMMAND,mac:c.KeyCode.H|c.MetaKeys.MAC_CTRL,group:D,preconditions(t){return B(t)&&j(t)&&(!R(t)||!ye(t))}},De={id:w.id,description:"find-replace.shortcut.go-to-next-match",binding:c.KeyCode.ENTER,group:D,priority:1e3,preconditions(t){return ie(t)&&R(t)}},Te={id:k.id,description:"find-replace.shortcut.go-to-previous-match",binding:c.KeyCode.ENTER|c.MetaKeys.SHIFT,group:D,priority:1e3,preconditions(t){return ie(t)&&R(t)}},Oe={id:X.id,description:"find-replace.shortcut.focus-selection",binding:c.KeyCode.ESC,group:D,priority:1e3,preconditions(t){return R(t)}};function Pe(t){const e=t.get(o.IContextService);return{id:F.id,icon:"SearchIcon",tooltip:"find-replace.toolbar",type:c.MenuItemType.BUTTON,hidden$:c.getMenuHiddenObservable(t,o.UniverInstanceType.UNIVER_SHEET),disabled$:m.combineLatest([e.subscribeContextValue$(o.EDITOR_ACTIVATED),e.subscribeContextValue$(o.FOCUSING_SHEET)]).pipe(m.map(([n,i])=>n||!i))}}const Ee={[c.RibbonStartGroup.OTHERS]:{[F.id]:{order:2,menuItemFactory:Pe}}};var Ne=Object.getOwnPropertyDescriptor,Le=(t,e,n,i)=>{for(var s=i>1?void 0:i?Ne(e,n):e,a=t.length-1,r;a>=0;a--)(r=t[a])&&(s=r(s)||s);return s},y=(t,e)=>(n,i)=>e(n,i,t);const ne="DESKTOP_FIND_REPLACE_DIALOG",se=350,$e=20,Ae=-90;d.FindReplaceController=class extends o.RxDisposable{constructor(n,i,s,a,r,l,p,C,M,g){super();u(this,"_closingListenerDisposable");this._univerInstanceService=n,this._menuManagerService=i,this._shortcutService=s,this._commandService=a,this._findReplaceService=r,this._dialogService=l,this._layoutService=p,this._localeService=C,this._componentManager=M,this._injector=g,this._initCommands(),this._initUI(),this._initShortcuts()}dispose(){var n;super.dispose(),(n=this._closingListenerDisposable)==null||n.dispose(),this._closingListenerDisposable=null}_initCommands(){[F,L,w,k,U,x,X].forEach(n=>{this.disposeWithMe(this._commandService.registerCommand(n))})}_initShortcuts(){[Re,Ie,Fe,Te,De,Oe].forEach(n=>this.disposeWithMe(this._shortcutService.registerShortcut(n)))}_initUI(){this.disposeWithMe(this._componentManager.register("FindReplaceDialog",Se)),this.disposeWithMe(this._componentManager.register("SearchIcon",q)),this._menuManagerService.mergeMenu(Ee),this._findReplaceService.stateUpdates$.pipe(m.takeUntil(this.dispose$)).subscribe(n=>{n.revealed===!0&&this._openPanel()})}_openPanel(){this._dialogService.open({id:ne,draggable:!0,width:se,title:{title:this._localeService.t("find-replace.dialog.title")},children:{label:"FindReplaceDialog"},destroyOnClose:!0,defaultPosition:xe(),preservePositionOnDestroy:!0,onClose:()=>this.closePanel()}),this._closingListenerDisposable=o.toDisposable(this._univerInstanceService.focused$.pipe(m.takeUntil(this.dispose$)).subscribe(n=>{(!n||!this._univerInstanceService.getUniverSheetInstance(n))&&this.closePanel()}))}closePanel(){this._closingListenerDisposable&&(this._closingListenerDisposable.dispose(),this._closingListenerDisposable=null,this._dialogService.close(ne),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus()))}},d.FindReplaceController=Le([y(0,o.IUniverInstanceService),y(1,c.IMenuManagerService),y(2,c.IShortcutService),y(3,o.ICommandService),y(4,S),y(5,c.IDialogService),y(6,c.ILayoutService),y(7,o.Inject(o.LocaleService)),y(8,o.Inject(c.ComponentManager)),y(9,o.Inject(o.Injector))],d.FindReplaceController);function xe(){const{innerWidth:t}=window;return{x:(t-se)/2-$e,y:Ae}}var Ue=Object.getOwnPropertyDescriptor,we=(t,e,n,i)=>{for(var s=i>1?void 0:i?Ue(e,n):e,a=t.length-1,r;a>=0;a--)(r=t[a])&&(s=r(s)||s);return s},ae=(t,e)=>(n,i)=>e(n,i,t);const ke="UNIVER_FIND_REPLACE_PLUGIN";d.UniverFindReplacePlugin=(W=class extends o.Plugin{constructor(e=V,n,i){super(),this._config=e,this._injector=n,this._configService=i;const{...s}=o.merge({},V,this._config);this._configService.setConfig(oe,s)}onStarting(){[[d.FindReplaceController],[S,{useClass:A}]].forEach(e=>this._injector.add(e))}onRendered(){this._injector.get(d.FindReplaceController)}},u(W,"pluginName",ke),W),d.UniverFindReplacePlugin=we([ae(1,o.Inject(o.Injector)),ae(2,o.IConfigService)],d.UniverFindReplacePlugin),d.FindBy=P,d.FindDirection=O,d.FindModel=pe,d.FindReplaceState=Q,d.FindScope=E,d.GoToNextMatchOperation=w,d.GoToPreviousMatchOperation=k,d.IFindReplaceService=S,d.OpenFindDialogOperation=F,d.OpenReplaceDialogOperation=L,d.ReplaceAllMatchesCommand=U,d.ReplaceCurrentMatchCommand=x,d.createInitFindReplaceState=N,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
4
+ `,onClick:g,children:i.t("find-replace.dialog.advanced-finding")})})]})}),me=f.forwardRef(function(e,n){const i=c.useDependency(S),s=c.useDependency(o.LocaleService),a=c.useDependency(o.ICommandService),r=c.useDependency(c.IMessageService),l=c.useObservable(i.currentMatch$,void 0,!0),p=c.useObservable(i.replaceables$,void 0,!0),C=c.useObservable(i.state$,void 0,!0),{matchesCount:M,matchesPosition:g,findString:$,inputtingFindString:I,replaceString:Be,caseSensitive:je,matchesTheWholeCell:We,findDirection:Ge,findScope:Ve,findBy:Ke,findCompleted:G}=C,He=I.length===0,qe=M===0||!(l!=null&&l.replaceable),ze=p.length===0,Ye=f.useCallback(v=>i.changeInputtingFindString(v),[i]),Ze=f.useCallback(v=>i.changeReplaceString(v),[i]),{focus:Je}=te(i,n),Qe=f.useCallback(()=>{$===I?i.moveToNextMatch():(i.changeFindString(I),i.find())},[$,I,i]),Xe=f.useCallback(()=>a.executeCommand(x.id),[a]),et=f.useCallback(async()=>{await a.executeCommand(U.id),Je()},[a]),tt=f.useCallback(v=>{i.changeFindDirection(v)},[i]),it=f.useCallback(v=>{i.changeFindScope(v)},[i]),nt=f.useCallback(v=>{i.changeFindBy(v)},[i]),st=Ce(s),at=Me(s),rt=be(s);return f.useEffect(()=>{G&&M===0&&r.show({content:s.t("find-replace.dialog.no-match"),type:_.MessageType.Warning,duration:5e3})},[G,M,r,s]),h.jsxs("div",{className:"univer-theme",children:[h.jsx(_.FormLayout,{label:s.t("find-replace.dialog.find"),children:h.jsx(ee,{findCompleted:G,className:"univer-find-input",matchesCount:M,matchesPosition:g,findReplaceService:i,localeService:s,findString:I,onChange:Ye})}),h.jsx(_.FormLayout,{label:s.t("find-replace.dialog.replace"),children:h.jsx(_.Input,{placeholder:s.t("find-replace.dialog.replace-placeholder"),value:Be,onChange:v=>Ze(v)})}),h.jsx(_.FormLayout,{label:s.t("find-replace.dialog.find-direction.title"),children:h.jsx(_.Select,{value:Ge,options:at,onChange:tt})}),h.jsx(_.FormDualColumnLayout,{children:h.jsxs(h.Fragment,{children:[h.jsx(_.FormLayout,{label:s.t("find-replace.dialog.find-scope.title"),children:h.jsx(_.Select,{value:Ve,options:st,onChange:it})}),h.jsx(_.FormLayout,{label:s.t("find-replace.dialog.find-by.title"),children:h.jsx(_.Select,{value:Ke,options:rt,onChange:nt})})]})}),h.jsx(_.FormDualColumnLayout,{children:h.jsxs(h.Fragment,{children:[h.jsx(_.FormLayout,{children:h.jsx(_.Checkbox,{checked:je,onChange:v=>{i.changeCaseSensitive(v)},children:s.t("find-replace.dialog.case-sensitive")})}),h.jsx(_.FormLayout,{children:h.jsx(_.Checkbox,{checked:We,onChange:v=>{i.changeMatchesTheWholeCell(v)},children:s.t("find-replace.dialog.match-the-whole-cell")})})]})}),h.jsxs("div",{className:"univer-mt-6 univer-flex univer-justify-between",children:[h.jsx(_.Button,{variant:"primary",onClick:Qe,disabled:He,children:s.t("find-replace.dialog.find")}),h.jsxs("span",{className:"univer-inline-flex univer-gap-2",children:[h.jsx(_.Button,{disabled:qe,onClick:Xe,children:s.t("find-replace.dialog.replace")}),h.jsx(_.Button,{disabled:ze,onClick:et,children:s.t("find-replace.dialog.replace-all")})]})]})]})});function Se(){const t=c.useDependency(S),e=c.useDependency(c.ILayoutService),n=c.useDependency(o.IContextService),i=c.useObservable(t.state$,void 0,!0),s=f.useRef(null);f.useEffect(()=>{let p;return s.current&&(p=e.registerContainerElement(s.current)),()=>p==null?void 0:p.dispose()},[e]);const a=f.useRef(null),r=f.useCallback(p=>n.setContextValue(Y,p),[n]),l=f.useCallback(p=>n.setContextValue(z,p),[n]);return f.useEffect(()=>{var C;const p=m.fromEvent(document,"focusin").subscribe(M=>{var g;M.target&&((g=s.current)!=null&&g.contains(M.target))?r(!0):r(!1),!a.current||!a.current.selectHasFocus()?l(!0):l(!1)});return(C=a.current)==null||C.focus(),r(!0),l(!0),()=>{p.unsubscribe(),r(!1)}},[r,l]),h.jsx("div",{ref:s,children:i.replaceRevealed?h.jsx(me,{ref:a}):h.jsx(ve,{ref:a})})}function Ce(t){const e=t.getCurrentLocale();return f.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 Me(t){const e=t.getCurrentLocale();return f.useMemo(()=>[{label:t.t("find-replace.dialog.find-direction.row"),value:O.ROW},{label:t.t("find-replace.dialog.find-direction.column"),value:O.COLUMN}],[e])}function be(t){const e=t.getCurrentLocale();return f.useMemo(()=>[{label:t.t("find-replace.dialog.find-by.value"),value:P.VALUE},{label:t.t("find-replace.dialog.find-by.formula"),value:P.FORMULA}],[e])}function R(t){return t.getContextValue(Y)}function ye(t){return t.getContextValue(Z)}function ie(t){return t.getContextValue(z)}const D="7_find-replace-shortcuts";function B(t){return t.getContextValue(o.FOCUSING_SHEET)}function j(t){return!t.getContextValue(o.EDITOR_ACTIVATED)}const Ie={id:F.id,description:"find-replace.shortcut.open-find-dialog",binding:c.KeyCode.F|c.MetaKeys.CTRL_COMMAND,group:D,preconditions(t){return!R(t)&&B(t)&&j(t)}},Fe={id:F.id,description:"find-replace.shortcut.open-find-dialog",binding:c.KeyCode.F|c.MetaKeys.CTRL_COMMAND,mac:c.KeyCode.F|c.MetaKeys.MAC_CTRL,preconditions(t){return!R(t)&&B(t)&&j(t)}},Re={id:L.id,description:"find-replace.shortcut.open-replace-dialog",binding:c.KeyCode.H|c.MetaKeys.CTRL_COMMAND,mac:c.KeyCode.H|c.MetaKeys.MAC_CTRL,group:D,preconditions(t){return B(t)&&j(t)&&(!R(t)||!ye(t))}},De={id:w.id,description:"find-replace.shortcut.go-to-next-match",binding:c.KeyCode.ENTER,group:D,priority:1e3,preconditions(t){return ie(t)&&R(t)}},Te={id:k.id,description:"find-replace.shortcut.go-to-previous-match",binding:c.KeyCode.ENTER|c.MetaKeys.SHIFT,group:D,priority:1e3,preconditions(t){return ie(t)&&R(t)}},Oe={id:X.id,description:"find-replace.shortcut.focus-selection",binding:c.KeyCode.ESC,group:D,priority:1e3,preconditions(t){return R(t)}};function Pe(t){const e=t.get(o.IContextService);return{id:F.id,icon:"SearchIcon",tooltip:"find-replace.toolbar",type:c.MenuItemType.BUTTON,hidden$:c.getMenuHiddenObservable(t,o.UniverInstanceType.UNIVER_SHEET),disabled$:m.combineLatest([e.subscribeContextValue$(o.EDITOR_ACTIVATED),e.subscribeContextValue$(o.FOCUSING_SHEET)]).pipe(m.map(([n,i])=>n||!i))}}const Ee={[c.RibbonStartGroup.OTHERS]:{[F.id]:{order:2,menuItemFactory:Pe}}};var Ne=Object.getOwnPropertyDescriptor,Le=(t,e,n,i)=>{for(var s=i>1?void 0:i?Ne(e,n):e,a=t.length-1,r;a>=0;a--)(r=t[a])&&(s=r(s)||s);return s},y=(t,e)=>(n,i)=>e(n,i,t);const ne="DESKTOP_FIND_REPLACE_DIALOG",se=350,$e=20,Ae=64;d.FindReplaceController=class extends o.RxDisposable{constructor(n,i,s,a,r,l,p,C,M,g){super();u(this,"_closingListenerDisposable");this._univerInstanceService=n,this._menuManagerService=i,this._shortcutService=s,this._commandService=a,this._findReplaceService=r,this._dialogService=l,this._layoutService=p,this._localeService=C,this._componentManager=M,this._injector=g,this._initCommands(),this._initUI(),this._initShortcuts()}dispose(){var n;super.dispose(),(n=this._closingListenerDisposable)==null||n.dispose(),this._closingListenerDisposable=null}_initCommands(){[F,L,w,k,U,x,X].forEach(n=>{this.disposeWithMe(this._commandService.registerCommand(n))})}_initShortcuts(){[Re,Ie,Fe,Te,De,Oe].forEach(n=>this.disposeWithMe(this._shortcutService.registerShortcut(n)))}_initUI(){this.disposeWithMe(this._componentManager.register("FindReplaceDialog",Se)),this.disposeWithMe(this._componentManager.register("SearchIcon",q)),this._menuManagerService.mergeMenu(Ee),this._findReplaceService.stateUpdates$.pipe(m.takeUntil(this.dispose$)).subscribe(n=>{n.revealed===!0&&this._openPanel()})}_openPanel(){this._dialogService.open({id:ne,draggable:!0,width:se,title:{title:this._localeService.t("find-replace.dialog.title")},children:{label:"FindReplaceDialog"},destroyOnClose:!0,mask:!1,maskClosable:!1,defaultPosition:xe(),preservePositionOnDestroy:!0,onClose:()=>this.closePanel()}),this._closingListenerDisposable=o.toDisposable(this._univerInstanceService.focused$.pipe(m.takeUntil(this.dispose$)).subscribe(n=>{(!n||!this._univerInstanceService.getUniverSheetInstance(n))&&this.closePanel()}))}closePanel(){this._closingListenerDisposable&&(this._closingListenerDisposable.dispose(),this._closingListenerDisposable=null,this._dialogService.close(ne),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus()))}},d.FindReplaceController=Le([y(0,o.IUniverInstanceService),y(1,c.IMenuManagerService),y(2,c.IShortcutService),y(3,o.ICommandService),y(4,S),y(5,c.IDialogService),y(6,c.ILayoutService),y(7,o.Inject(o.LocaleService)),y(8,o.Inject(c.ComponentManager)),y(9,o.Inject(o.Injector))],d.FindReplaceController);function xe(){const{innerWidth:t}=window;return{x:t-se-$e,y:Ae}}var Ue=Object.getOwnPropertyDescriptor,we=(t,e,n,i)=>{for(var s=i>1?void 0:i?Ue(e,n):e,a=t.length-1,r;a>=0;a--)(r=t[a])&&(s=r(s)||s);return s},ae=(t,e)=>(n,i)=>e(n,i,t);const ke="UNIVER_FIND_REPLACE_PLUGIN";d.UniverFindReplacePlugin=(W=class extends o.Plugin{constructor(e=V,n,i){super(),this._config=e,this._injector=n,this._configService=i;const{...s}=o.merge({},V,this._config);this._configService.setConfig(oe,s)}onStarting(){[[d.FindReplaceController],[S,{useClass:A}]].forEach(e=>this._injector.add(e))}onRendered(){this._injector.get(d.FindReplaceController)}},u(W,"pluginName",ke),W),d.UniverFindReplacePlugin=we([ae(1,o.Inject(o.Injector)),ae(2,o.IConfigService)],d.UniverFindReplacePlugin),d.FindBy=P,d.FindDirection=O,d.FindModel=pe,d.FindReplaceState=Q,d.FindScope=E,d.GoToNextMatchOperation=w,d.GoToPreviousMatchOperation=k,d.IFindReplaceService=S,d.OpenFindDialogOperation=F,d.OpenReplaceDialogOperation=L,d.ReplaceAllMatchesCommand=U,d.ReplaceCurrentMatchCommand=x,d.createInitFindReplaceState=N,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.6.10-experimental.20250419-8f302dd",
3
+ "version": "0.6.10-experimental.20250421-e4eb9bc",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -55,10 +55,10 @@
55
55
  },
56
56
  "dependencies": {
57
57
  "@univerjs/icons": "^0.3.2",
58
- "@univerjs/core": "0.6.10-experimental.20250419-8f302dd",
59
- "@univerjs/engine-render": "0.6.10-experimental.20250419-8f302dd",
60
- "@univerjs/design": "0.6.10-experimental.20250419-8f302dd",
61
- "@univerjs/ui": "0.6.10-experimental.20250419-8f302dd"
58
+ "@univerjs/core": "0.6.10-experimental.20250421-e4eb9bc",
59
+ "@univerjs/engine-render": "0.6.10-experimental.20250421-e4eb9bc",
60
+ "@univerjs/design": "0.6.10-experimental.20250421-e4eb9bc",
61
+ "@univerjs/ui": "0.6.10-experimental.20250421-e4eb9bc"
62
62
  },
63
63
  "devDependencies": {
64
64
  "postcss": "^8.5.3",
@@ -66,9 +66,9 @@
66
66
  "rxjs": "^7.8.1",
67
67
  "tailwindcss": "^3.4.17",
68
68
  "typescript": "^5.8.3",
69
- "vite": "^6.3.0",
69
+ "vite": "^6.3.2",
70
70
  "vitest": "^3.1.1",
71
- "@univerjs-infra/shared": "0.6.10-alpha.0"
71
+ "@univerjs-infra/shared": "0.6.10"
72
72
  },
73
73
  "scripts": {
74
74
  "test": "vitest run",