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