@univerjs/find-replace 0.2.4 → 0.2.5
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 +2 -2
- package/lib/es/index.js +19 -21
- package/lib/types/controllers/find-replace.controller.d.ts +1 -2
- package/lib/types/controllers/find-replace.menu.d.ts +1 -1
- package/lib/types/plugin.d.ts +1 -2
- package/lib/types/services/find-replace.service.d.ts +2 -3
- package/lib/umd/index.js +2 -2
- package/package.json +11 -13
package/lib/cjs/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var Pe=Object.defineProperty;var Ee=(i,e,n)=>e in i?Pe(i,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[e]=n;var l=(i,e,n)=>Ee(i,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@univerjs/core"),b=require("@wendellhu/redi"),u=require("@univerjs/ui"),g=require("rxjs"),Ne=require("@univerjs/engine-render"),o=require("react"),p=require("@univerjs/design"),M=require("@wendellhu/redi/react-bindings");var S=function(){return S=Object.assign||function(i){for(var e,n=1,t=arguments.length;n<t;n++){e=arguments[n];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(i[r]=e[r])}return i},S.apply(this,arguments)},je=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 r=0,t=Object.getOwnPropertySymbols(i);r<t.length;r++)e.indexOf(t[r])<0&&Object.prototype.propertyIsEnumerable.call(i,t[r])&&(n[t[r]]=i[t[r]]);return n},J=o.forwardRef(function(i,e){var n=i.icon,t=i.id,r=i.className,s=i.extend,a=je(i,["icon","id","className","extend"]),h="univerjs-icon univerjs-icon-".concat(t," ").concat(r||"").trim(),f=o.useRef("_".concat(Ae()));return Q(n,"".concat(t),{defIds:n.defIds,idSuffix:f.current},S({ref:e,className:h},a),s)});function Q(i,e,n,t,r){return o.createElement(i.tag,S(S({key:e},$e(i,n,r)),t),(Le(i,n).children||[]).map(function(s,a){return Q(s,"".concat(e,"-").concat(i.tag,"-").concat(a),n,void 0,r)}))}function $e(i,e,n){var t=S({},i.attrs);n!=null&&n.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=n.colorChannel1);var r=e.defIds;return!r||r.length===0||(i.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+e.idSuffix),Object.entries(t).forEach(function(s){var a=s[0],h=s[1];typeof h=="string"&&(t[a]=h.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),t}function Le(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)?S(S({},i),{children:i.children.map(function(r){return typeof r.attrs.id=="string"&&t&&t.indexOf(r.attrs.id)>-1?S(S({},r),{attrs:S(S({},r.attrs),{id:r.attrs.id+e.idSuffix})}):r})}):i}function Ae(){return Math.random().toString(36).substring(2,8)}J.displayName="UniverIcon";var we={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_217_40",style:{maskType:"alpha"},width:17,height:17,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#D9D9D9",d:"M0.9 0.09H16.9V16.09H0.9z"}}]},{tag:"g",attrs:{mask:"url(#mask0_217_40)"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.39551 7.37266C2.39551 4.18105 4.98281 1.59375 8.17441 1.59375C11.366 1.59375 13.9533 4.18105 13.9533 7.37266C13.9533 8.72342 13.4898 9.96603 12.7133 10.95L15.1964 13.4331C15.4619 13.6986 15.4619 14.1291 15.1964 14.3946C14.9309 14.6601 14.5004 14.6601 14.2349 14.3946L11.7518 11.9115C10.7678 12.6881 9.52525 13.1516 8.17441 13.1516C4.98281 13.1516 2.39551 10.5642 2.39551 7.37266ZM8.17441 2.95349C5.73378 2.95349 3.75525 4.93202 3.75525 7.37266C3.75525 9.81333 5.73378 11.7918 8.17441 11.7918C10.6151 11.7918 12.5936 9.81333 12.5936 7.37266C12.5936 4.93202 10.6151 2.95349 8.17441 2.95349Z",fillRule:"evenodd",clipRule:"evenodd"}}]}]},X=o.forwardRef(function(i,e){return o.createElement(J,Object.assign({},i,{id:"search-single-16",ref:e,icon:we}))});X.displayName="SearchSingle16";const ee="FIND_REPLACE_INPUT_FOCUS",te="FIND_REPLACE_DIALOG_FOCUS",ie="FIND_REPLACE_REPLACE_REVEALED";var Ue=Object.defineProperty,Be=Object.getOwnPropertyDescriptor,ne=(i,e,n,t)=>{for(var r=t>1?void 0:t?Be(e,n):e,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(t?a(e,n,r):a(r))||r);return t&&r&&Ue(e,n,r),r},U=(i,e)=>(n,t)=>e(n,t,i);class ke extends c.Disposable{}const C=b.createIdentifier("find-replace.service");function We(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"}let B=class extends c.Disposable{constructor(e,n,t){super();l(this,"currentMatch$",new g.BehaviorSubject(null));l(this,"replaceables$",new g.BehaviorSubject([]));l(this,"_findModels",[]);l(this,"_matchingModel",null);l(this,"_matches",[]);l(this,"_currentSearchingDisposables",null);this._state=e,this._providers=n,this._univerInstanceService=t,this.disposeWithMe(this._state.stateUpdates$.pipe(g.throttleTime(200,void 0,{leading:!0,trailing:!0})).subscribe(async r=>{const s=this._state.state;We(r)&&(s.findString!==""&&!s.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({...W(),revealed:!1})}async start(){if(!this._state.findString)return{results:[]};const e=await this._startSearching();return this._state.changeState({findCompleted:!0}),e}async _startSearching(){if(!this._state.findString)return{results:[]};const e=Array.from(this._providers),n=this._findModels=(await Promise.all(e.map(r=>r.find({findString:this._state.findString,findDirection:this._state.findDirection,findScope:this._state.findScope,findBy:this._state.findBy,replaceRevealed:this._state.replaceRevealed,caseSensitive:this._state.caseSensitive,matchesTheWholeCell:this._state.matchesTheWholeCell})))).flat();this._subscribeToModelsChanges(n);const t=this._matches=n.map(r=>r.getMatches()).flat();return this.replaceables$.next(t.filter(r=>r.replaceable)),t.length?(this._moveToInitialMatch(n),this._state.changeState({matchesCount:t.length}),{results:t}):(this._state.changeState({matchesCount:0,matchesPosition:0}),{results:[]})}_stopSearching(){var e;this._providers.forEach(n=>n.terminate()),this._findModels=[],this._matches=[],this._matchingModel=null,(e=this._currentSearchingDisposables)==null||e.dispose(),this._currentSearchingDisposables=null,this.currentMatch$.next(null),this.replaceables$.next([]),this._state.changeState({findCompleted:!1,matchesCount:0,matchesPosition:0})}_subscribeToModelsChanges(e){const n=this._currentSearchingDisposables=new c.DisposableCollection,t=g.combineLatest(e.map(r=>r.matchesUpdate$)).pipe(g.debounceTime(220)).subscribe(([...r])=>{const s=this._matches=r.flat();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([]))});e.forEach(r=>n.add(c.toDisposable(r.activelyChangingMatch$.subscribe(s=>{const a=this._matches.findIndex(h=>h===s);this._state.changeState({matchesPosition:a+1})})))),n.add(c.toDisposable(t))}async replace(){return this._matchingModel?this._matchingModel.replace(this._state.replaceString):!1}async replaceAll(){const e=await Promise.all(this._findModels.map(n=>n.replaceAll(this._state.replaceString))).then(n=>n.reduce((t,r)=>(t.success+=r.success,t.failure+=r.failure,t),{success:0,failure:0}));return e.failure===0&&this._stopSearching(),e}getCurrentMatch(){return this._state.matchesPosition>0?this._matches[this._state.matchesPosition-1]:null}_markMatch(e){const n=this._matches.findIndex(t=>t===e);this.currentMatch$.next(e),this._state.changeState({matchesPosition:n+1})}moveToNextMatch(){if(!this._matchingModel)return;const e=this._findModels.length===1,n=this._matchingModel.moveToNextMatch({loop:e});if(n)this._markMatch(n);else{const t=this._findModels.findIndex(r=>r===this._matchingModel);this._moveToNextUnitMatch(t)}}_moveToNextUnitMatch(e){const n=this._findModels.length;for(let t=(e+1)%n;t!==e;){const r=this._findModels[t],s=r.moveToNextMatch({ignoreSelection:!0});if(s){this._matchingModel=r,this._markMatch(s);return}t=(t+1)%n}if(this._matchingModel){const t=this._matchingModel.moveToNextMatch({ignoreSelection:!0});t&&this._markMatch(t)}}moveToPreviousMatch(){if(!this._matchingModel)return;const e=this._findModels.length===1,n=this._matchingModel.moveToPreviousMatch({loop:e});if(n){const t=this._matches.findIndex(r=>r===n);this.currentMatch$.next(n),this._state.changeState({matchesPosition:t+1})}else{const t=this._findModels.length,r=this._findModels.findIndex(a=>a===this._matchingModel);for(let a=(r-1+t)%t;a!==r;){const h=this._findModels[a],f=h.moveToPreviousMatch({ignoreSelection:!0});if(f){this._matchingModel=h,this._markMatch(f);return}a=(a-1)%t}const s=this._matchingModel.moveToPreviousMatch({ignoreSelection:!0});s&&this._markMatch(s)}}_moveToInitialMatch(e,n=!1){var s;const t=(s=this._univerInstanceService.getFocusedUnit())==null?void 0:s.getUnitId();if(!t)return-1;const r=e.findIndex(a=>a.unitId===t);if(r!==-1){this._matchingModel=e[r];const a=this._matchingModel.moveToNextMatch({stayIfOnMatch:!0,noFocus:n});if(a)return this._markMatch(a),r}return this._moveToNextUnitMatch(r),0}};B=ne([U(2,c.IUniverInstanceService)],B);var O=(i=>(i.ROW="row",i.COLUMN="column",i))(O||{}),P=(i=>(i.VALUE="value",i.FORMULA="formula",i))(P||{}),E=(i=>(i.SUBUNIT="subunit",i.UNIT="unit",i))(E||{});function W(){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 Ge{constructor(){l(this,"_stateUpdates$",new g.Subject);l(this,"stateUpdates$",this._stateUpdates$.asObservable());l(this,"_state$",new g.BehaviorSubject(W()));l(this,"state$",this._state$.asObservable());l(this,"_findString","");l(this,"_inputtingFindString","");l(this,"_replaceString","");l(this,"_revealed",!1);l(this,"_replaceRevealed",!1);l(this,"_matchesPosition",0);l(this,"_matchesCount",0);l(this,"_caseSensitive",!0);l(this,"_matchesTheWholeCell",!1);l(this,"_findDirection","row");l(this,"_findScope","subunit");l(this,"_findBy","value");l(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 k=class extends c.Disposable{constructor(e,n){super();l(this,"_providers",new Set);l(this,"_state",new Ge);l(this,"_model");l(this,"_currentMatch$",new g.BehaviorSubject(null));l(this,"currentMatch$",this._currentMatch$.asObservable());l(this,"_replaceables$",new g.BehaviorSubject([]));l(this,"replaceables$",this._replaceables$.asObservable());l(this,"_focusSignal$",new g.Subject);l(this,"focusSignal$",this._focusSignal$.asObservable());this._injector=e,this._contextService=n}get stateUpdates$(){return this._state.stateUpdates$}get state$(){return this._state.state$}get revealed(){return this._state.revealed}get replaceRevealed(){return this._state.replaceRevealed}dispose(){super.dispose(),this._currentMatch$.next(null),this._currentMatch$.complete(),this._replaceables$.next([]),this._replaceables$.complete(),this._focusSignal$.complete()}getCurrentMatch(){var e;return(e=this._model)==null?void 0:e.getCurrentMatch()}getFindString(){return this._state.findString}changeFindString(e){this._state.changeState({findString:e})}focusFindInput(){this._focusSignal$.next()}changeInputtingFindString(e){e?this._state.changeState({inputtingFindString:e}):this._state.changeState({inputtingFindString:"",findString:""})}changeReplaceString(e){this._state.changeState({replaceString:e})}changeMatchesTheWholeCell(e){this._state.changeState({matchesTheWholeCell:e})}changeCaseSensitive(e){this._state.changeState({caseSensitive:e})}changeFindBy(e){this._state.changeState({findBy:e}),this._toggleDisplayRawFormula(e==="formula")}changeFindScope(e){this._state.changeState({findScope:e})}changeFindDirection(e){this._state.changeState({findDirection:e})}moveToNextMatch(){this._model&&(this._state.replaceRevealed&&!this._model.searched?(this._state.changeState({findString:this._state.inputtingFindString}),this._model.start()):this._model.moveToNextMatch(),this._focusSignal$.next())}moveToPreviousMatch(){this._model&&(this._state.replaceRevealed&&!this._model.searched?(this._state.changeState({findString:this._state.inputtingFindString}),this._model.start()):this._model.moveToPreviousMatch(),this._focusSignal$.next())}async replace(){return this._model?this._model.replace():!1}async replaceAll(){if(!this._model)throw new Error("[FindReplaceService] replaceAll: model is not initialized!");return this._model.replaceAll()}revealReplace(){this._state.changeState({replaceRevealed:!0,inputtingFindString:this._state.findString}),this._toggleRevealReplace(!0)}start(e=!1){if(this._providers.size===0)return!1;this._model=this._injector.createInstance(B,this._state,this._providers),this._model.currentMatch$.subscribe(t=>this._currentMatch$.next(t)),this._model.replaceables$.subscribe(t=>this._replaceables$.next(t));const n=W();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(ie,e)}_toggleDisplayRawFormula(e){this._contextService.setContextValue(Ne.RENDER_RAW_FORMULA_KEY,e)}};k=ne([U(0,b.Inject(b.Injector)),U(1,c.IContextService)],k);const x={id:"ui.operation.open-find-dialog",type:c.CommandType.OPERATION,handler:i=>{const e=i.get(C);return e.revealed?e.focusFindInput():e.start(),!0}},j={id:"ui.operation.open-replace-dialog",type:c.CommandType.OPERATION,handler:i=>{const e=i.get(C);return e.revealed?e.replaceRevealed?e.focusFindInput():e.revealReplace():e.start(!0),!0}},G={type:c.CommandType.OPERATION,id:"ui.operation.go-to-next-match",handler:i=>(i.get(C).moveToNextMatch(),!0)},V={type:c.CommandType.OPERATION,id:"ui.operation.go-to-previous-match",handler:i=>(i.get(C).moveToPreviousMatch(),!0)};var re={exports:{}},$={};/**
|
|
1
|
+
"use strict";var Te=Object.defineProperty;var Oe=(i,e,n)=>e in i?Te(i,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[e]=n;var l=(i,e,n)=>Oe(i,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),u=require("@univerjs/ui"),g=require("rxjs"),Pe=require("@univerjs/engine-render"),c=require("react"),p=require("@univerjs/design");var S=function(){return S=Object.assign||function(i){for(var e,n=1,t=arguments.length;n<t;n++){e=arguments[n];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(i[r]=e[r])}return i},S.apply(this,arguments)},Ee=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 r=0,t=Object.getOwnPropertySymbols(i);r<t.length;r++)e.indexOf(t[r])<0&&Object.prototype.propertyIsEnumerable.call(i,t[r])&&(n[t[r]]=i[t[r]]);return n},Y=c.forwardRef(function(i,e){var n=i.icon,t=i.id,r=i.className,s=i.extend,a=Ee(i,["icon","id","className","extend"]),h="univerjs-icon univerjs-icon-".concat(t," ").concat(r||"").trim(),f=c.useRef("_".concat($e()));return Z(n,"".concat(t),{defIds:n.defIds,idSuffix:f.current},S({ref:e,className:h},a),s)});function Z(i,e,n,t,r){return c.createElement(i.tag,S(S({key:e},Ne(i,n,r)),t),(je(i,n).children||[]).map(function(s,a){return Z(s,"".concat(e,"-").concat(i.tag,"-").concat(a),n,void 0,r)}))}function Ne(i,e,n){var t=S({},i.attrs);n!=null&&n.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=n.colorChannel1);var r=e.defIds;return!r||r.length===0||(i.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+e.idSuffix),Object.entries(t).forEach(function(s){var a=s[0],h=s[1];typeof h=="string"&&(t[a]=h.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),t}function je(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)?S(S({},i),{children:i.children.map(function(r){return typeof r.attrs.id=="string"&&t&&t.indexOf(r.attrs.id)>-1?S(S({},r),{attrs:S(S({},r.attrs),{id:r.attrs.id+e.idSuffix})}):r})}):i}function $e(){return Math.random().toString(36).substring(2,8)}Y.displayName="UniverIcon";var Le={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_217_40",style:{maskType:"alpha"},width:17,height:17,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#D9D9D9",d:"M0.9 0.09H16.9V16.09H0.9z"}}]},{tag:"g",attrs:{mask:"url(#mask0_217_40)"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.39551 7.37266C2.39551 4.18105 4.98281 1.59375 8.17441 1.59375C11.366 1.59375 13.9533 4.18105 13.9533 7.37266C13.9533 8.72342 13.4898 9.96603 12.7133 10.95L15.1964 13.4331C15.4619 13.6986 15.4619 14.1291 15.1964 14.3946C14.9309 14.6601 14.5004 14.6601 14.2349 14.3946L11.7518 11.9115C10.7678 12.6881 9.52525 13.1516 8.17441 13.1516C4.98281 13.1516 2.39551 10.5642 2.39551 7.37266ZM8.17441 2.95349C5.73378 2.95349 3.75525 4.93202 3.75525 7.37266C3.75525 9.81333 5.73378 11.7918 8.17441 11.7918C10.6151 11.7918 12.5936 9.81333 12.5936 7.37266C12.5936 4.93202 10.6151 2.95349 8.17441 2.95349Z",fillRule:"evenodd",clipRule:"evenodd"}}]}]},J=c.forwardRef(function(i,e){return c.createElement(Y,Object.assign({},i,{id:"search-single-16",ref:e,icon:Le}))});J.displayName="SearchSingle16";const Q="FIND_REPLACE_INPUT_FOCUS",X="FIND_REPLACE_DIALOG_FOCUS",ee="FIND_REPLACE_REPLACE_REVEALED";var Ae=Object.defineProperty,we=Object.getOwnPropertyDescriptor,te=(i,e,n,t)=>{for(var r=t>1?void 0:t?we(e,n):e,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(t?a(e,n,r):a(r))||r);return t&&r&&Ae(e,n,r),r},A=(i,e)=>(n,t)=>e(n,t,i);class Ue extends o.Disposable{}const C=o.createIdentifier("find-replace.service");function Be(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"}let w=class extends o.Disposable{constructor(e,n,t){super();l(this,"currentMatch$",new g.BehaviorSubject(null));l(this,"replaceables$",new g.BehaviorSubject([]));l(this,"_findModels",[]);l(this,"_matchingModel",null);l(this,"_matches",[]);l(this,"_currentSearchingDisposables",null);this._state=e,this._providers=n,this._univerInstanceService=t,this.disposeWithMe(this._state.stateUpdates$.pipe(g.throttleTime(200,void 0,{leading:!0,trailing:!0})).subscribe(async r=>{const s=this._state.state;Be(r)&&(s.findString!==""&&!s.replaceRevealed?(await this._startSearching(),this._state.changeState({findCompleted:!0})):r.replaceRevealed!==!0&&this._stopSearching())}))}get searched(){return this._findModels.length>0}dispose(){super.dispose(),this._stopSearching(),this.currentMatch$.complete(),this.replaceables$.complete(),this._state.changeState({...B(),revealed:!1})}async start(){if(!this._state.findString)return{results:[]};const e=await this._startSearching();return this._state.changeState({findCompleted:!0}),e}async _startSearching(){if(!this._state.findString)return{results:[]};const e=Array.from(this._providers),n=this._findModels=(await Promise.all(e.map(r=>r.find({findString:this._state.findString,findDirection:this._state.findDirection,findScope:this._state.findScope,findBy:this._state.findBy,replaceRevealed:this._state.replaceRevealed,caseSensitive:this._state.caseSensitive,matchesTheWholeCell:this._state.matchesTheWholeCell})))).flat();this._subscribeToModelsChanges(n);const t=this._matches=n.map(r=>r.getMatches()).flat();return this.replaceables$.next(t.filter(r=>r.replaceable)),t.length?(this._moveToInitialMatch(n),this._state.changeState({matchesCount:t.length}),{results:t}):(this._state.changeState({matchesCount:0,matchesPosition:0}),{results:[]})}_stopSearching(){var e;this._providers.forEach(n=>n.terminate()),this._findModels=[],this._matches=[],this._matchingModel=null,(e=this._currentSearchingDisposables)==null||e.dispose(),this._currentSearchingDisposables=null,this.currentMatch$.next(null),this.replaceables$.next([]),this._state.changeState({findCompleted:!1,matchesCount:0,matchesPosition:0})}_subscribeToModelsChanges(e){const n=this._currentSearchingDisposables=new o.DisposableCollection,t=g.combineLatest(e.map(r=>r.matchesUpdate$)).pipe(g.debounceTime(220)).subscribe(([...r])=>{const s=this._matches=r.flat();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([]))});e.forEach(r=>n.add(o.toDisposable(r.activelyChangingMatch$.subscribe(s=>{const a=this._matches.findIndex(h=>h===s);this._state.changeState({matchesPosition:a+1})})))),n.add(o.toDisposable(t))}async replace(){return this._matchingModel?this._matchingModel.replace(this._state.replaceString):!1}async replaceAll(){const e=await Promise.all(this._findModels.map(n=>n.replaceAll(this._state.replaceString))).then(n=>n.reduce((t,r)=>(t.success+=r.success,t.failure+=r.failure,t),{success:0,failure:0}));return e.failure===0&&this._stopSearching(),e}getCurrentMatch(){return this._state.matchesPosition>0?this._matches[this._state.matchesPosition-1]:null}_markMatch(e){const n=this._matches.findIndex(t=>t===e);this.currentMatch$.next(e),this._state.changeState({matchesPosition:n+1})}moveToNextMatch(){if(!this._matchingModel)return;const e=this._findModels.length===1,n=this._matchingModel.moveToNextMatch({loop:e});if(n)this._markMatch(n);else{const t=this._findModels.findIndex(r=>r===this._matchingModel);this._moveToNextUnitMatch(t)}}_moveToNextUnitMatch(e){const n=this._findModels.length;for(let t=(e+1)%n;t!==e;){const r=this._findModels[t],s=r.moveToNextMatch({ignoreSelection:!0});if(s){this._matchingModel=r,this._markMatch(s);return}t=(t+1)%n}if(this._matchingModel){const t=this._matchingModel.moveToNextMatch({ignoreSelection:!0});t&&this._markMatch(t)}}moveToPreviousMatch(){if(!this._matchingModel)return;const e=this._findModels.length===1,n=this._matchingModel.moveToPreviousMatch({loop:e});if(n){const t=this._matches.findIndex(r=>r===n);this.currentMatch$.next(n),this._state.changeState({matchesPosition:t+1})}else{const t=this._findModels.length,r=this._findModels.findIndex(a=>a===this._matchingModel);for(let a=(r-1+t)%t;a!==r;){const h=this._findModels[a],f=h.moveToPreviousMatch({ignoreSelection:!0});if(f){this._matchingModel=h,this._markMatch(f);return}a=(a-1)%t}const s=this._matchingModel.moveToPreviousMatch({ignoreSelection:!0});s&&this._markMatch(s)}}_moveToInitialMatch(e,n=!1){var s;const t=(s=this._univerInstanceService.getFocusedUnit())==null?void 0:s.getUnitId();if(!t)return-1;const r=e.findIndex(a=>a.unitId===t);if(r!==-1){this._matchingModel=e[r];const a=this._matchingModel.moveToNextMatch({stayIfOnMatch:!0,noFocus:n});if(a)return this._markMatch(a),r}return this._moveToNextUnitMatch(r),0}};w=te([A(2,o.IUniverInstanceService)],w);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 B(){return{caseSensitive:!1,findBy:"value",findCompleted:!1,findDirection:"row",findScope:"subunit",findString:"",inputtingFindString:"",matchesCount:0,matchesPosition:0,matchesTheWholeCell:!1,replaceRevealed:!1,replaceString:"",revealed:!0}}class ke{constructor(){l(this,"_stateUpdates$",new g.Subject);l(this,"stateUpdates$",this._stateUpdates$.asObservable());l(this,"_state$",new g.BehaviorSubject(B()));l(this,"state$",this._state$.asObservable());l(this,"_findString","");l(this,"_inputtingFindString","");l(this,"_replaceString","");l(this,"_revealed",!1);l(this,"_replaceRevealed",!1);l(this,"_matchesPosition",0);l(this,"_matchesCount",0);l(this,"_caseSensitive",!0);l(this,"_matchesTheWholeCell",!1);l(this,"_findDirection","row");l(this,"_findScope","subunit");l(this,"_findBy","value");l(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 U=class extends o.Disposable{constructor(e,n){super();l(this,"_providers",new Set);l(this,"_state",new ke);l(this,"_model");l(this,"_currentMatch$",new g.BehaviorSubject(null));l(this,"currentMatch$",this._currentMatch$.asObservable());l(this,"_replaceables$",new g.BehaviorSubject([]));l(this,"replaceables$",this._replaceables$.asObservable());l(this,"_focusSignal$",new g.Subject);l(this,"focusSignal$",this._focusSignal$.asObservable());this._injector=e,this._contextService=n}get stateUpdates$(){return this._state.stateUpdates$}get state$(){return this._state.state$}get revealed(){return this._state.revealed}get replaceRevealed(){return this._state.replaceRevealed}dispose(){super.dispose(),this._currentMatch$.next(null),this._currentMatch$.complete(),this._replaceables$.next([]),this._replaceables$.complete(),this._focusSignal$.complete()}getCurrentMatch(){var e;return(e=this._model)==null?void 0:e.getCurrentMatch()}getFindString(){return this._state.findString}changeFindString(e){this._state.changeState({findString:e})}focusFindInput(){this._focusSignal$.next()}changeInputtingFindString(e){e?this._state.changeState({inputtingFindString:e}):this._state.changeState({inputtingFindString:"",findString:""})}changeReplaceString(e){this._state.changeState({replaceString:e})}changeMatchesTheWholeCell(e){this._state.changeState({matchesTheWholeCell:e})}changeCaseSensitive(e){this._state.changeState({caseSensitive:e})}changeFindBy(e){this._state.changeState({findBy:e}),this._toggleDisplayRawFormula(e==="formula")}changeFindScope(e){this._state.changeState({findScope:e})}changeFindDirection(e){this._state.changeState({findDirection:e})}moveToNextMatch(){this._model&&(this._state.replaceRevealed&&!this._model.searched?(this._state.changeState({findString:this._state.inputtingFindString}),this._model.start()):this._model.moveToNextMatch(),this._focusSignal$.next())}moveToPreviousMatch(){this._model&&(this._state.replaceRevealed&&!this._model.searched?(this._state.changeState({findString:this._state.inputtingFindString}),this._model.start()):this._model.moveToPreviousMatch(),this._focusSignal$.next())}async replace(){return this._model?this._model.replace():!1}async replaceAll(){if(!this._model)throw new Error("[FindReplaceService] replaceAll: model is not initialized!");return this._model.replaceAll()}revealReplace(){this._state.changeState({replaceRevealed:!0,inputtingFindString:this._state.findString}),this._toggleRevealReplace(!0)}start(e=!1){if(this._providers.size===0)return!1;this._model=this._injector.createInstance(w,this._state,this._providers),this._model.currentMatch$.subscribe(t=>this._currentMatch$.next(t)),this._model.replaceables$.subscribe(t=>this._replaceables$.next(t));const n=B();return e&&(n.replaceRevealed=!0),this._state.changeState(n),this._toggleRevealReplace(e),!0}find(){var e;(e=this._model)==null||e.start()}terminate(){var e;(e=this._model)==null||e.dispose(),this._model=null,this._toggleDisplayRawFormula(!1),this._toggleRevealReplace(!1)}registerFindReplaceProvider(e){return this._providers.add(e),o.toDisposable(()=>this._providers.delete(e))}_toggleRevealReplace(e){this._contextService.setContextValue(ee,e)}_toggleDisplayRawFormula(e){this._contextService.setContextValue(Pe.RENDER_RAW_FORMULA_KEY,e)}};U=te([A(0,o.Inject(o.Injector)),A(1,o.IContextService)],U);const y={id:"ui.operation.open-find-dialog",type:o.CommandType.OPERATION,handler:i=>{const e=i.get(C);return e.revealed?e.focusFindInput():e.start(),!0}},E={id:"ui.operation.open-replace-dialog",type:o.CommandType.OPERATION,handler:i=>{const e=i.get(C);return e.revealed?e.replaceRevealed?e.focusFindInput():e.revealReplace():e.start(!0),!0}},k={type:o.CommandType.OPERATION,id:"ui.operation.go-to-next-match",handler:i=>(i.get(C).moveToNextMatch(),!0)},W={type:o.CommandType.OPERATION,id:"ui.operation.go-to-previous-match",handler:i=>(i.get(C).moveToPreviousMatch(),!0)};var ie={exports:{}},N={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var Ve=o,He=Symbol.for("react.element"),Ke=Symbol.for("react.fragment"),qe=Object.prototype.hasOwnProperty,ze=Ve.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Ye={key:!0,ref:!0,__self:!0,__source:!0};function se(i,e,n){var t,r={},s=null,a=null;n!==void 0&&(s=""+n),e.key!==void 0&&(s=""+e.key),e.ref!==void 0&&(a=e.ref);for(t in e)qe.call(e,t)&&!Ye.hasOwnProperty(t)&&(r[t]=e[t]);if(i&&i.defaultProps)for(t in e=i.defaultProps,e)r[t]===void 0&&(r[t]=e[t]);return{$$typeof:He,type:i,key:s,ref:a,props:r,_owner:ze.current}}$.Fragment=Ke;$.jsx=se;$.jsxs=se;re.exports=$;var d=re.exports;const H={id:"ui.command.replace-current-match",type:c.CommandType.COMMAND,handler:i=>i.get(C).replace()},Ze="CONFIRM_REPLACE_ALL",K={id:"ui.command.replace-all-matches",type:c.CommandType.COMMAND,handler:async i=>{const e=i.get(u.IConfirmService),n=i.get(c.LocaleService),t=i.get(u.IMessageService);if(!await e.confirm({id:Ze,title:{title:n.t("find-replace.replace.confirm.title")},cancelText:n.t("button.cancel"),confirmText:n.t("button.confirm")}))return!1;const s=await i.get(C).replaceAll(),{success:a,failure:h}=s;return h>0?(a===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",`${a}`,`${h}`)}),!1):(t.show({type:p.MessageType.Success,content:n.t("find-replace.replace.all-success",`${a}`)}),!0)}};function ae(i){const{findCompleted:e,localeService:n,matchesCount:t,matchesPosition:r,findString:s,findReplaceService:a,onChange:h,...f}=i,v=e&&t===0?n.t("find-replace.dialog.no-result"):t===0?" ":void 0;return d.jsx(p.InputWithSlot,{autoFocus:!0,placeholder:n.t("find-replace.dialog.find-placeholder"),slot:d.jsx(p.Pager,{loop:!0,text:v,value:r,total:t,onChange:m=>{r===t&&m===1?a.moveToNextMatch():r===1&&m===t||m<r?a.moveToPreviousMatch():a.moveToNextMatch()}}),value:s,onChange:m=>h==null?void 0:h(m),...f})}const Je="univer-find-replace-dialog-container",Qe="univer-find-replace-expand-container",Xe="univer-button-text",et="univer-find-replace-buttons-group",tt="univer-find-replace-buttons-group-right",N={findReplaceDialogContainer:Je,findReplaceExpandContainer:Qe,buttonText:Xe,findReplaceButtonsGroup:et,findReplaceButtonsGroupRight:tt};function oe(i,e){const n=o.useCallback(()=>{var r;(r=document.querySelector(".univer-find-input input"))==null||r.focus()},[]),t=o.useCallback(()=>{const r=document.querySelectorAll(".univer-find-replace-dialog-container .univer-select-selection-search-input");return Array.from(r).some(s=>s===document.activeElement)},[]);return o.useImperativeHandle(e,()=>({focus:n,selectHasFocus:t})),o.useEffect(()=>{const r=i.focusSignal$.subscribe(()=>n());return()=>r.unsubscribe()},[i,n]),{focus:n,selectHasFocus:t}}const it=o.forwardRef(function(e,n){const t=M.useDependency(c.LocaleService),r=M.useDependency(C),s=M.useDependency(c.ICommandService),a=u.useObservable(r.state$,void 0,!0),{findCompleted:h,findString:f,matchesCount:y,matchesPosition:v}=a,m=o.useCallback(()=>{s.executeCommand(j.id)},[s]),D=o.useCallback(I=>r.changeFindString(I),[r]);return oe(r,n),d.jsxs(o.Fragment,{children:[d.jsx(ae,{findCompleted:h,className:"univer-find-input",matchesCount:y,matchesPosition:v,findReplaceService:r,localeService:t,findString:f,onChange:D}),d.jsx("div",{className:N.findReplaceExpandContainer,children:d.jsx(p.Button,{type:"text",size:"small",onClick:m,children:t.t("find-replace.dialog.advanced-finding")})})]})}),nt=o.forwardRef(function(e,n){const t=M.useDependency(C),r=M.useDependency(c.LocaleService),s=M.useDependency(c.ICommandService),a=M.useDependency(u.IMessageService),h=u.useObservable(t.currentMatch$,void 0,!0),f=u.useObservable(t.replaceables$,void 0,!0),y=u.useObservable(t.state$,void 0,!0),{matchesCount:v,matchesPosition:m,findString:D,inputtingFindString:I,replaceString:de,caseSensitive:ue,matchesTheWholeCell:he,findDirection:pe,findScope:fe,findBy:_e,findCompleted:A}=y,ge=I.length===0,me=v===0||!(h!=null&&h.replaceable),ve=f.length===0,Se=o.useCallback(_=>t.changeInputtingFindString(_),[t]),Ce=o.useCallback(_=>t.changeReplaceString(_),[t]),{focus:Re}=oe(t,n),be=o.useCallback(()=>{D===I?t.moveToNextMatch():(t.changeFindString(I),t.find())},[D,I,t]),Me=o.useCallback(()=>s.executeCommand(H.id),[s]),ye=o.useCallback(async()=>{await s.executeCommand(K.id),Re()},[s]),Ie=o.useCallback(_=>{t.changeFindDirection(_)},[t]),xe=o.useCallback(_=>{t.changeFindScope(_)},[t]),Fe=o.useCallback(_=>{t.changeFindBy(_)},[t]),De=st(r),Te=at(r),Oe=ot(r);return o.useEffect(()=>{const _=A&&v===0;let T=null;return _&&(T=a.show({content:r.t("find-replace.dialog.no-match"),type:p.MessageType.Warning,duration:5e3})),()=>T==null?void 0:T.dispose()},[A,v,a,r]),d.jsxs(o.Fragment,{children:[d.jsx(p.FormLayout,{label:r.t("find-replace.dialog.find"),children:d.jsx(ae,{findCompleted:A,className:"univer-find-input",matchesCount:v,matchesPosition:m,findReplaceService:t,localeService:r,findString:I,onChange:Se})}),d.jsx(p.FormLayout,{label:r.t("find-replace.dialog.replace"),children:d.jsx(p.Input,{placeholder:r.t("find-replace.dialog.replace-placeholder"),value:de,onChange:_=>Ce(_)})}),d.jsx(p.FormLayout,{label:r.t("find-replace.dialog.find-direction.title"),children:d.jsx(p.Select,{value:pe,options:Te,onChange:Ie})}),d.jsx(p.FormDualColumnLayout,{children:d.jsxs(o.Fragment,{children:[d.jsx(p.FormLayout,{label:r.t("find-replace.dialog.find-scope.title"),children:d.jsx(p.Select,{value:fe,options:De,onChange:xe})}),d.jsx(p.FormLayout,{label:r.t("find-replace.dialog.find-by.title"),children:d.jsx(p.Select,{value:_e,options:Oe,onChange:Fe})})]})}),d.jsx(p.FormDualColumnLayout,{children:d.jsxs(o.Fragment,{children:[d.jsx(p.FormLayout,{children:d.jsx(p.Checkbox,{checked:ue,onChange:_=>{t.changeCaseSensitive(_)},children:r.t("find-replace.dialog.case-sensitive")})}),d.jsx(p.FormLayout,{children:d.jsx(p.Checkbox,{checked:he,onChange:_=>{t.changeMatchesTheWholeCell(_)},children:r.t("find-replace.dialog.match-the-whole-cell")})})]})}),d.jsxs("div",{className:N.findReplaceButtonsGroup,children:[d.jsx(p.Button,{type:"primary",onClick:be,disabled:ge,children:r.t("find-replace.dialog.find")}),d.jsxs("span",{className:N.findReplaceButtonsGroupRight,children:[d.jsx(p.Button,{disabled:me,onClick:Me,children:r.t("find-replace.dialog.replace")}),d.jsx(p.Button,{disabled:ve,onClick:ye,children:r.t("find-replace.dialog.replace-all")})]})]})]})});function rt(){const i=M.useDependency(C),e=M.useDependency(u.ILayoutService),n=M.useDependency(c.IContextService),t=u.useObservable(i.state$,void 0,!0),r=o.useRef(null);o.useEffect(()=>{let f;return r.current&&(f=e.registerContainerElement(r.current)),()=>f==null?void 0:f.dispose()},[e]);const s=o.useRef(null),a=o.useCallback(f=>n.setContextValue(te,f),[n]),h=o.useCallback(f=>n.setContextValue(ee,f),[n]);return o.useEffect(()=>{var y;const f=g.fromEvent(document,"focusin").subscribe(v=>{var m;v.target&&((m=r.current)!=null&&m.contains(v.target))?a(!0):a(!1),!s.current||!s.current.selectHasFocus()?h(!0):h(!1)});return(y=s.current)==null||y.focus(),a(!0),h(!0),()=>{f.unsubscribe(),a(!1)}},[a,h]),d.jsx("div",{className:N.findReplaceDialogContainer,ref:r,children:t.replaceRevealed?d.jsx(nt,{ref:s}):d.jsx(it,{ref:s})})}function st(i){const e=i.getCurrentLocale();return o.useMemo(()=>[{label:i.t("find-replace.dialog.find-scope.current-sheet"),value:E.SUBUNIT},{label:i.t("find-replace.dialog.find-scope.workbook"),value:E.UNIT}],[e])}function at(i){const e=i.getCurrentLocale();return o.useMemo(()=>[{label:i.t("find-replace.dialog.find-direction.row"),value:O.ROW},{label:i.t("find-replace.dialog.find-direction.column"),value:O.COLUMN}],[e])}function ot(i){const e=i.getCurrentLocale();return o.useMemo(()=>[{label:i.t("find-replace.dialog.find-by.value"),value:P.VALUE},{label:i.t("find-replace.dialog.find-by.formula"),value:P.FORMULA}],[e])}function F(i){return i.getContextValue(te)}function ct(i){return i.getContextValue(ie)}function ce(i){return i.getContextValue(ee)}const L="7_find-replace-shortcuts";function q(i){return i.getContextValue(c.FOCUSING_SHEET)}function z(i){return!i.getContextValue(c.EDITOR_ACTIVATED)}const lt={id:x.id,description:"find-replace.shortcut.open-find-dialog",binding:u.KeyCode.F|u.MetaKeys.CTRL_COMMAND,group:L,preconditions(i){return!F(i)&&q(i)&&z(i)}},dt={id:x.id,description:"find-replace.shortcut.open-find-dialog",binding:u.KeyCode.F|u.MetaKeys.CTRL_COMMAND,mac:u.KeyCode.F|u.MetaKeys.MAC_CTRL,preconditions(i){return!F(i)&&q(i)&&z(i)}},ut={id:j.id,description:"find-replace.shortcut.open-replace-dialog",binding:u.KeyCode.H|u.MetaKeys.CTRL_COMMAND,mac:u.KeyCode.H|u.MetaKeys.MAC_CTRL,group:L,preconditions(i){return q(i)&&z(i)&&(!F(i)||!ct(i))}},ht={id:G.id,description:"find-replace.shortcut.go-to-next-match",binding:u.KeyCode.ENTER,group:L,priority:1e3,preconditions(i){return ce(i)&&F(i)}},pt={id:V.id,description:"find-replace.shortcut.go-to-previous-match",binding:u.KeyCode.ENTER|u.MetaKeys.SHIFT,group:L,priority:1e3,preconditions(i){return ce(i)&&F(i)}};function ft(i){const e=i.get(c.IContextService);return{id:x.id,icon:"SearchIcon",tooltip:"find-replace.toolbar",group:u.MenuGroup.TOOLBAR_OTHERS,type:u.MenuItemType.BUTTON,positions:[u.MenuPosition.TOOLBAR_START],hidden$:u.getMenuHiddenObservable(i,c.UniverInstanceType.UNIVER_SHEET),disabled$:g.combineLatest([e.subscribeContextValue$(c.EDITOR_ACTIVATED),e.subscribeContextValue$(c.FOCUSING_SHEET)]).pipe(g.map(([n,t])=>n||!t))}}var _t=Object.defineProperty,gt=Object.getOwnPropertyDescriptor,mt=(i,e,n,t)=>{for(var r=t>1?void 0:t?gt(e,n):e,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(t?a(e,n,r):a(r))||r);return t&&r&&_t(e,n,r),r},R=(i,e)=>(n,t)=>e(n,t,i);const vt={},Y="DESKTOP_FIND_REPLACE_DIALOG",le=350,St=20,Ct=-90;exports.FindReplaceController=class extends c.RxDisposable{constructor(e,n,t,r,s,a,h,f,y,v,m){super(),this._config=e,this._univerInstanceService=n,this._menuService=t,this._shortcutService=r,this._commandService=s,this._findReplaceService=a,this._dialogService=h,this._layoutService=f,this._localeService=y,this._componentManager=v,this._injector=m,this._initCommands(),this._initUI(),this._initShortcuts()}_initCommands(){[x,j,G,V,K,H].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initShortcuts(){[ut,lt,dt,pt,ht].forEach(e=>this.disposeWithMe(this._shortcutService.registerShortcut(e)))}_initUI(){const{menu:e={}}=this._config;this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(ft),e)),this.disposeWithMe(this._componentManager.register("FindReplaceDialog",rt)),this.disposeWithMe(this._componentManager.register("SearchIcon",X)),this._findReplaceService.stateUpdates$.pipe(g.takeUntil(this.dispose$)).subscribe(n=>{n.revealed===!0&&this._openPanel()}),this.disposeWithMe(this._univerInstanceService.focused$.pipe(g.takeUntil(this.dispose$)).subscribe(n=>{(!n||!this._univerInstanceService.getUniverSheetInstance(n))&&this.closePanel()}))}_openPanel(){this._dialogService.open({id:Y,draggable:!0,width:le,title:{title:this._localeService.t("find-replace.dialog.title")},children:{label:"FindReplaceDialog"},destroyOnClose:!0,defaultPosition:Rt(),preservePositionOnDestroy:!0,onClose:()=>this.closePanel()})}closePanel(){this._dialogService.close(Y),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus())}};exports.FindReplaceController=mt([c.OnLifecycle(c.LifecycleStages.Rendered,exports.FindReplaceController),R(1,c.IUniverInstanceService),R(2,u.IMenuService),R(3,u.IShortcutService),R(4,c.ICommandService),R(5,C),R(6,u.IDialogService),R(7,u.ILayoutService),R(8,b.Inject(c.LocaleService)),R(9,b.Inject(u.ComponentManager)),R(10,b.Inject(b.Injector))],exports.FindReplaceController);function Rt(){const{innerWidth:i}=window;return{x:(i-le)/2-St,y:Ct}}var bt=Object.defineProperty,Mt=Object.getOwnPropertyDescriptor,yt=(i,e,n,t)=>{for(var r=t>1?void 0:t?Mt(e,n):e,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(t?a(e,n,r):a(r))||r);return t&&r&&bt(e,n,r),r},Z=(i,e)=>(n,t)=>e(n,t,i);const It="FIND_REPLACE_PLUGIN";var w;exports.UniverFindReplacePlugin=(w=class extends c.Plugin{constructor(e={},n,t){super(),this._config=e,this._injector=n,this._localeService=t,this._config=c.Tools.deepMerge({},vt,this._config)}onStarting(e){[[exports.FindReplaceController,{useFactory:()=>this._injector.createInstance(exports.FindReplaceController,this._config)}],[C,{useClass:k}]].forEach(n=>{e.add(n)})}},l(w,"pluginName",It),w);exports.UniverFindReplacePlugin=yt([Z(1,b.Inject(b.Injector)),Z(2,b.Inject(c.LocaleService))],exports.UniverFindReplacePlugin);exports.FindBy=P;exports.FindDirection=O;exports.FindModel=ke;exports.FindScope=E;exports.GoToNextMatchOperation=G;exports.GoToPreviousMatchOperation=V;exports.IFindReplaceService=C;exports.OpenFindDialogOperation=x;exports.OpenReplaceDialogOperation=j;exports.ReplaceAllMatchesCommand=K;exports.ReplaceCurrentMatchCommand=H;
|
|
9
|
+
*/var We=c,Ge=Symbol.for("react.element"),Ve=Symbol.for("react.fragment"),He=Object.prototype.hasOwnProperty,Ke=We.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,qe={key:!0,ref:!0,__self:!0,__source:!0};function ne(i,e,n){var t,r={},s=null,a=null;n!==void 0&&(s=""+n),e.key!==void 0&&(s=""+e.key),e.ref!==void 0&&(a=e.ref);for(t in e)He.call(e,t)&&!qe.hasOwnProperty(t)&&(r[t]=e[t]);if(i&&i.defaultProps)for(t in e=i.defaultProps,e)r[t]===void 0&&(r[t]=e[t]);return{$$typeof:Ge,type:i,key:s,ref:a,props:r,_owner:Ke.current}}N.Fragment=Ve;N.jsx=ne;N.jsxs=ne;ie.exports=N;var d=ie.exports;const G={id:"ui.command.replace-current-match",type:o.CommandType.COMMAND,handler:i=>i.get(C).replace()},ze="CONFIRM_REPLACE_ALL",V={id:"ui.command.replace-all-matches",type:o.CommandType.COMMAND,handler:async i=>{const e=i.get(u.IConfirmService),n=i.get(o.LocaleService),t=i.get(u.IMessageService);if(!await e.confirm({id:ze,title:{title:n.t("find-replace.replace.confirm.title")},cancelText:n.t("button.cancel"),confirmText:n.t("button.confirm")}))return!1;const s=await i.get(C).replaceAll(),{success:a,failure:h}=s;return h>0?(a===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",`${a}`,`${h}`)}),!1):(t.show({type:p.MessageType.Success,content:n.t("find-replace.replace.all-success",`${a}`)}),!0)}};function re(i){const{findCompleted:e,localeService:n,matchesCount:t,matchesPosition:r,findString:s,findReplaceService:a,onChange:h,...f}=i,v=e&&t===0?n.t("find-replace.dialog.no-result"):t===0?" ":void 0;return d.jsx(p.InputWithSlot,{autoFocus:!0,placeholder:n.t("find-replace.dialog.find-placeholder"),slot:d.jsx(p.Pager,{loop:!0,text:v,value:r,total:t,onChange:m=>{r===t&&m===1?a.moveToNextMatch():r===1&&m===t||m<r?a.moveToPreviousMatch():a.moveToNextMatch()}}),value:s,onChange:m=>h==null?void 0:h(m),...f})}const Ye="univer-find-replace-dialog-container",Ze="univer-find-replace-expand-container",Je="univer-button-text",Qe="univer-find-replace-buttons-group",Xe="univer-find-replace-buttons-group-right",P={findReplaceDialogContainer:Ye,findReplaceExpandContainer:Ze,buttonText:Je,findReplaceButtonsGroup:Qe,findReplaceButtonsGroupRight:Xe};function se(i,e){const n=c.useCallback(()=>{var r;(r=document.querySelector(".univer-find-input input"))==null||r.focus()},[]),t=c.useCallback(()=>{const r=document.querySelectorAll(".univer-find-replace-dialog-container .univer-select-selection-search-input");return Array.from(r).some(s=>s===document.activeElement)},[]);return c.useImperativeHandle(e,()=>({focus:n,selectHasFocus:t})),c.useEffect(()=>{const r=i.focusSignal$.subscribe(()=>n());return()=>r.unsubscribe()},[i,n]),{focus:n,selectHasFocus:t}}const et=c.forwardRef(function(e,n){const t=o.useDependency(o.LocaleService),r=o.useDependency(C),s=o.useDependency(o.ICommandService),a=u.useObservable(r.state$,void 0,!0),{findCompleted:h,findString:f,matchesCount:b,matchesPosition:v}=a,m=c.useCallback(()=>{s.executeCommand(E.id)},[s]),x=c.useCallback(M=>r.changeFindString(M),[r]);return se(r,n),d.jsxs(c.Fragment,{children:[d.jsx(re,{findCompleted:h,className:"univer-find-input",matchesCount:b,matchesPosition:v,findReplaceService:r,localeService:t,findString:f,onChange:x}),d.jsx("div",{className:P.findReplaceExpandContainer,children:d.jsx(p.Button,{type:"text",size:"small",onClick:m,children:t.t("find-replace.dialog.advanced-finding")})})]})}),tt=c.forwardRef(function(e,n){const t=o.useDependency(C),r=o.useDependency(o.LocaleService),s=o.useDependency(o.ICommandService),a=o.useDependency(u.IMessageService),h=u.useObservable(t.currentMatch$,void 0,!0),f=u.useObservable(t.replaceables$,void 0,!0),b=u.useObservable(t.state$,void 0,!0),{matchesCount:v,matchesPosition:m,findString:x,inputtingFindString:M,replaceString:ce,caseSensitive:le,matchesTheWholeCell:de,findDirection:ue,findScope:he,findBy:pe,findCompleted:$}=b,fe=M.length===0,_e=v===0||!(h!=null&&h.replaceable),ge=f.length===0,me=c.useCallback(_=>t.changeInputtingFindString(_),[t]),ve=c.useCallback(_=>t.changeReplaceString(_),[t]),{focus:Se}=se(t,n),Ce=c.useCallback(()=>{x===M?t.moveToNextMatch():(t.changeFindString(M),t.find())},[x,M,t]),Re=c.useCallback(()=>s.executeCommand(G.id),[s]),be=c.useCallback(async()=>{await s.executeCommand(V.id),Se()},[s]),Me=c.useCallback(_=>{t.changeFindDirection(_)},[t]),ye=c.useCallback(_=>{t.changeFindScope(_)},[t]),Ie=c.useCallback(_=>{t.changeFindBy(_)},[t]),xe=nt(r),Fe=rt(r),De=st(r);return c.useEffect(()=>{const _=$&&v===0;let F=null;return _&&(F=a.show({content:r.t("find-replace.dialog.no-match"),type:p.MessageType.Warning,duration:5e3})),()=>F==null?void 0:F.dispose()},[$,v,a,r]),d.jsxs(c.Fragment,{children:[d.jsx(p.FormLayout,{label:r.t("find-replace.dialog.find"),children:d.jsx(re,{findCompleted:$,className:"univer-find-input",matchesCount:v,matchesPosition:m,findReplaceService:t,localeService:r,findString:M,onChange:me})}),d.jsx(p.FormLayout,{label:r.t("find-replace.dialog.replace"),children:d.jsx(p.Input,{placeholder:r.t("find-replace.dialog.replace-placeholder"),value:ce,onChange:_=>ve(_)})}),d.jsx(p.FormLayout,{label:r.t("find-replace.dialog.find-direction.title"),children:d.jsx(p.Select,{value:ue,options:Fe,onChange:Me})}),d.jsx(p.FormDualColumnLayout,{children:d.jsxs(c.Fragment,{children:[d.jsx(p.FormLayout,{label:r.t("find-replace.dialog.find-scope.title"),children:d.jsx(p.Select,{value:he,options:xe,onChange:ye})}),d.jsx(p.FormLayout,{label:r.t("find-replace.dialog.find-by.title"),children:d.jsx(p.Select,{value:pe,options:De,onChange:Ie})})]})}),d.jsx(p.FormDualColumnLayout,{children:d.jsxs(c.Fragment,{children:[d.jsx(p.FormLayout,{children:d.jsx(p.Checkbox,{checked:le,onChange:_=>{t.changeCaseSensitive(_)},children:r.t("find-replace.dialog.case-sensitive")})}),d.jsx(p.FormLayout,{children:d.jsx(p.Checkbox,{checked:de,onChange:_=>{t.changeMatchesTheWholeCell(_)},children:r.t("find-replace.dialog.match-the-whole-cell")})})]})}),d.jsxs("div",{className:P.findReplaceButtonsGroup,children:[d.jsx(p.Button,{type:"primary",onClick:Ce,disabled:fe,children:r.t("find-replace.dialog.find")}),d.jsxs("span",{className:P.findReplaceButtonsGroupRight,children:[d.jsx(p.Button,{disabled:_e,onClick:Re,children:r.t("find-replace.dialog.replace")}),d.jsx(p.Button,{disabled:ge,onClick:be,children:r.t("find-replace.dialog.replace-all")})]})]})]})});function it(){const i=o.useDependency(C),e=o.useDependency(u.ILayoutService),n=o.useDependency(o.IContextService),t=u.useObservable(i.state$,void 0,!0),r=c.useRef(null);c.useEffect(()=>{let f;return r.current&&(f=e.registerContainerElement(r.current)),()=>f==null?void 0:f.dispose()},[e]);const s=c.useRef(null),a=c.useCallback(f=>n.setContextValue(X,f),[n]),h=c.useCallback(f=>n.setContextValue(Q,f),[n]);return c.useEffect(()=>{var b;const f=g.fromEvent(document,"focusin").subscribe(v=>{var m;v.target&&((m=r.current)!=null&&m.contains(v.target))?a(!0):a(!1),!s.current||!s.current.selectHasFocus()?h(!0):h(!1)});return(b=s.current)==null||b.focus(),a(!0),h(!0),()=>{f.unsubscribe(),a(!1)}},[a,h]),d.jsx("div",{className:P.findReplaceDialogContainer,ref:r,children:t.replaceRevealed?d.jsx(tt,{ref:s}):d.jsx(et,{ref:s})})}function nt(i){const e=i.getCurrentLocale();return c.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 rt(i){const e=i.getCurrentLocale();return c.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 st(i){const e=i.getCurrentLocale();return c.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 I(i){return i.getContextValue(X)}function at(i){return i.getContextValue(ee)}function ae(i){return i.getContextValue(Q)}const j="7_find-replace-shortcuts";function H(i){return i.getContextValue(o.FOCUSING_SHEET)}function K(i){return!i.getContextValue(o.EDITOR_ACTIVATED)}const ot={id:y.id,description:"find-replace.shortcut.open-find-dialog",binding:u.KeyCode.F|u.MetaKeys.CTRL_COMMAND,group:j,preconditions(i){return!I(i)&&H(i)&&K(i)}},ct={id:y.id,description:"find-replace.shortcut.open-find-dialog",binding:u.KeyCode.F|u.MetaKeys.CTRL_COMMAND,mac:u.KeyCode.F|u.MetaKeys.MAC_CTRL,preconditions(i){return!I(i)&&H(i)&&K(i)}},lt={id:E.id,description:"find-replace.shortcut.open-replace-dialog",binding:u.KeyCode.H|u.MetaKeys.CTRL_COMMAND,mac:u.KeyCode.H|u.MetaKeys.MAC_CTRL,group:j,preconditions(i){return H(i)&&K(i)&&(!I(i)||!at(i))}},dt={id:k.id,description:"find-replace.shortcut.go-to-next-match",binding:u.KeyCode.ENTER,group:j,priority:1e3,preconditions(i){return ae(i)&&I(i)}},ut={id:W.id,description:"find-replace.shortcut.go-to-previous-match",binding:u.KeyCode.ENTER|u.MetaKeys.SHIFT,group:j,priority:1e3,preconditions(i){return ae(i)&&I(i)}};function ht(i){const e=i.get(o.IContextService);return{id:y.id,icon:"SearchIcon",tooltip:"find-replace.toolbar",group:u.MenuGroup.TOOLBAR_OTHERS,type:u.MenuItemType.BUTTON,positions:[u.MenuPosition.TOOLBAR_START],hidden$:u.getMenuHiddenObservable(i,o.UniverInstanceType.UNIVER_SHEET),disabled$:g.combineLatest([e.subscribeContextValue$(o.EDITOR_ACTIVATED),e.subscribeContextValue$(o.FOCUSING_SHEET)]).pipe(g.map(([n,t])=>n||!t))}}var pt=Object.defineProperty,ft=Object.getOwnPropertyDescriptor,_t=(i,e,n,t)=>{for(var r=t>1?void 0:t?ft(e,n):e,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(t?a(e,n,r):a(r))||r);return t&&r&&pt(e,n,r),r},R=(i,e)=>(n,t)=>e(n,t,i);const gt={},q="DESKTOP_FIND_REPLACE_DIALOG",oe=350,mt=20,vt=-90;exports.FindReplaceController=class extends o.RxDisposable{constructor(e,n,t,r,s,a,h,f,b,v,m){super(),this._config=e,this._univerInstanceService=n,this._menuService=t,this._shortcutService=r,this._commandService=s,this._findReplaceService=a,this._dialogService=h,this._layoutService=f,this._localeService=b,this._componentManager=v,this._injector=m,this._initCommands(),this._initUI(),this._initShortcuts()}_initCommands(){[y,E,k,W,V,G].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initShortcuts(){[lt,ot,ct,ut,dt].forEach(e=>this.disposeWithMe(this._shortcutService.registerShortcut(e)))}_initUI(){const{menu:e={}}=this._config;this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(ht),e)),this.disposeWithMe(this._componentManager.register("FindReplaceDialog",it)),this.disposeWithMe(this._componentManager.register("SearchIcon",J)),this._findReplaceService.stateUpdates$.pipe(g.takeUntil(this.dispose$)).subscribe(n=>{n.revealed===!0&&this._openPanel()}),this.disposeWithMe(this._univerInstanceService.focused$.pipe(g.takeUntil(this.dispose$)).subscribe(n=>{(!n||!this._univerInstanceService.getUniverSheetInstance(n))&&this.closePanel()}))}_openPanel(){this._dialogService.open({id:q,draggable:!0,width:oe,title:{title:this._localeService.t("find-replace.dialog.title")},children:{label:"FindReplaceDialog"},destroyOnClose:!0,defaultPosition:St(),preservePositionOnDestroy:!0,onClose:()=>this.closePanel()})}closePanel(){this._dialogService.close(q),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus())}};exports.FindReplaceController=_t([o.OnLifecycle(o.LifecycleStages.Rendered,exports.FindReplaceController),R(1,o.IUniverInstanceService),R(2,u.IMenuService),R(3,u.IShortcutService),R(4,o.ICommandService),R(5,C),R(6,u.IDialogService),R(7,u.ILayoutService),R(8,o.Inject(o.LocaleService)),R(9,o.Inject(u.ComponentManager)),R(10,o.Inject(o.Injector))],exports.FindReplaceController);function St(){const{innerWidth:i}=window;return{x:(i-oe)/2-mt,y:vt}}var Ct=Object.defineProperty,Rt=Object.getOwnPropertyDescriptor,bt=(i,e,n,t)=>{for(var r=t>1?void 0:t?Rt(e,n):e,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(t?a(e,n,r):a(r))||r);return t&&r&&Ct(e,n,r),r},z=(i,e)=>(n,t)=>e(n,t,i);const Mt="FIND_REPLACE_PLUGIN";var L;exports.UniverFindReplacePlugin=(L=class extends o.Plugin{constructor(e={},n,t){super(),this._config=e,this._injector=n,this._localeService=t,this._config=o.Tools.deepMerge({},gt,this._config)}onStarting(e){[[exports.FindReplaceController,{useFactory:()=>this._injector.createInstance(exports.FindReplaceController,this._config)}],[C,{useClass:U}]].forEach(n=>{e.add(n)})}},l(L,"pluginName",Mt),L);exports.UniverFindReplacePlugin=bt([z(1,o.Inject(o.Injector)),z(2,o.Inject(o.LocaleService))],exports.UniverFindReplacePlugin);exports.FindBy=T;exports.FindDirection=D;exports.FindModel=Ue;exports.FindScope=O;exports.GoToNextMatchOperation=k;exports.GoToPreviousMatchOperation=W;exports.IFindReplaceService=C;exports.OpenFindDialogOperation=y;exports.OpenReplaceDialogOperation=E;exports.ReplaceAllMatchesCommand=V;exports.ReplaceCurrentMatchCommand=G;
|
package/lib/es/index.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
var at = Object.defineProperty;
|
|
2
2
|
var ot = (t, e, n) => e in t ? at(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
|
|
3
3
|
var o = (t, e, n) => ot(t, typeof e != "symbol" ? e + "" : e, n);
|
|
4
|
-
import { Disposable as X, IUniverInstanceService as pe, toDisposable as H, IContextService as
|
|
5
|
-
import { createIdentifier as _t, Inject as b, Injector as ie } from "@wendellhu/redi";
|
|
4
|
+
import { Disposable as X, createIdentifier as ct, Inject as b, Injector as ee, IUniverInstanceService as pe, toDisposable as H, IContextService as te, DisposableCollection as lt, CommandType as y, LocaleService as O, useDependency as v, ICommandService as ie, FOCUSING_SHEET as _e, EDITOR_ACTIVATED as ge, UniverInstanceType as dt, RxDisposable as ht, OnLifecycle as ut, LifecycleStages as ft, Plugin as pt, Tools as _t } from "@univerjs/core";
|
|
6
5
|
import { IConfirmService as gt, IMessageService as me, useObservable as I, ILayoutService as ve, KeyCode as M, MetaKeys as x, MenuGroup as mt, MenuItemType as vt, MenuPosition as St, getMenuHiddenObservable as Ct, ComponentManager as Rt, IMenuService as Mt, IShortcutService as bt, IDialogService as xt } from "@univerjs/ui";
|
|
7
6
|
import { BehaviorSubject as D, Subject as Se, throttleTime as yt, combineLatest as Ce, debounceTime as It, fromEvent as Ft, map as Dt, takeUntil as ce } from "rxjs";
|
|
8
7
|
import { RENDER_RAW_FORMULA_KEY as Ot } from "@univerjs/engine-render";
|
|
9
8
|
import Pt, { forwardRef as w, useRef as q, createElement as Re, useCallback as u, Fragment as N, useEffect as j, useMemo as ne, useImperativeHandle as Tt } from "react";
|
|
10
9
|
import { MessageType as $, InputWithSlot as Et, Pager as Nt, Button as A, FormLayout as R, Input as $t, Select as G, FormDualColumnLayout as le, Checkbox as de } from "@univerjs/design";
|
|
11
|
-
import { useDependency as v } from "@wendellhu/redi/react-bindings";
|
|
12
10
|
var _ = function() {
|
|
13
11
|
return _ = Object.assign || function(t) {
|
|
14
12
|
for (var e, n = 1, i = arguments.length; n < i; n++) {
|
|
@@ -66,9 +64,9 @@ var Bt = Object.defineProperty, Wt = Object.getOwnPropertyDescriptor, De = (t, e
|
|
|
66
64
|
(a = t[s]) && (r = (i ? a(e, n, r) : a(r)) || r);
|
|
67
65
|
return i && r && Bt(e, n, r), r;
|
|
68
66
|
}, z = (t, e) => (n, i) => e(n, i, t);
|
|
69
|
-
class
|
|
67
|
+
class Ni extends X {
|
|
70
68
|
}
|
|
71
|
-
const g =
|
|
69
|
+
const g = ct("find-replace.service");
|
|
72
70
|
function kt(t) {
|
|
73
71
|
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";
|
|
74
72
|
}
|
|
@@ -130,7 +128,7 @@ let K = class extends X {
|
|
|
130
128
|
}
|
|
131
129
|
// When a document's content changes, we should reset all matches and try to move to the next match.
|
|
132
130
|
_subscribeToModelsChanges(e) {
|
|
133
|
-
const n = this._currentSearchingDisposables = new
|
|
131
|
+
const n = this._currentSearchingDisposables = new lt(), i = Ce(e.map((r) => r.matchesUpdate$)).pipe(It(220)).subscribe(([...r]) => {
|
|
134
132
|
const s = this._matches = r.flat();
|
|
135
133
|
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([]));
|
|
136
134
|
});
|
|
@@ -427,8 +425,8 @@ let Q = class extends X {
|
|
|
427
425
|
}
|
|
428
426
|
};
|
|
429
427
|
Q = De([
|
|
430
|
-
z(0, b(
|
|
431
|
-
z(1,
|
|
428
|
+
z(0, b(ee)),
|
|
429
|
+
z(1, te)
|
|
432
430
|
], Q);
|
|
433
431
|
const U = {
|
|
434
432
|
id: "ui.operation.open-find-dialog",
|
|
@@ -551,7 +549,7 @@ function je(t, e) {
|
|
|
551
549
|
}, [t, n]), { focus: n, selectHasFocus: i };
|
|
552
550
|
}
|
|
553
551
|
const ii = w(function(e, n) {
|
|
554
|
-
const i = v(O), r = v(g), s = v(
|
|
552
|
+
const i = v(O), r = v(g), s = v(ie), a = I(r.state$, void 0, !0), { findCompleted: l, findString: d, matchesCount: S, matchesPosition: f } = a, p = u(() => {
|
|
555
553
|
s.executeCommand(se.id);
|
|
556
554
|
}, [s]), T = u((C) => r.changeFindString(C), [r]);
|
|
557
555
|
return je(r, n), /* @__PURE__ */ c.jsxs(N, { children: [
|
|
@@ -571,7 +569,7 @@ const ii = w(function(e, n) {
|
|
|
571
569
|
/* @__PURE__ */ c.jsx("div", { className: L.findReplaceExpandContainer, children: /* @__PURE__ */ c.jsx(A, { type: "text", size: "small", onClick: p, children: i.t("find-replace.dialog.advanced-finding") }) })
|
|
572
570
|
] });
|
|
573
571
|
}), ni = w(function(e, n) {
|
|
574
|
-
const i = v(g), r = v(O), s = v(
|
|
572
|
+
const i = v(g), r = v(O), s = v(ie), a = v(me), l = I(i.currentMatch$, void 0, !0), d = I(i.replaceables$, void 0, !0), S = I(i.state$, void 0, !0), {
|
|
575
573
|
matchesCount: f,
|
|
576
574
|
matchesPosition: p,
|
|
577
575
|
findString: T,
|
|
@@ -667,7 +665,7 @@ const ii = w(function(e, n) {
|
|
|
667
665
|
] });
|
|
668
666
|
});
|
|
669
667
|
function ri() {
|
|
670
|
-
const t = v(g), e = v(ve), n = v(
|
|
668
|
+
const t = v(g), e = v(ve), n = v(te), i = I(t.state$, void 0, !0), r = q(null);
|
|
671
669
|
j(() => {
|
|
672
670
|
let d;
|
|
673
671
|
return r.current && (d = e.registerContainerElement(r.current)), () => d == null ? void 0 : d.dispose();
|
|
@@ -772,7 +770,7 @@ const li = {
|
|
|
772
770
|
}
|
|
773
771
|
};
|
|
774
772
|
function pi(t) {
|
|
775
|
-
const e = t.get(
|
|
773
|
+
const e = t.get(te);
|
|
776
774
|
return {
|
|
777
775
|
id: U.id,
|
|
778
776
|
icon: "SearchIcon",
|
|
@@ -780,7 +778,7 @@ function pi(t) {
|
|
|
780
778
|
group: mt.TOOLBAR_OTHERS,
|
|
781
779
|
type: vt.BUTTON,
|
|
782
780
|
positions: [St.TOOLBAR_START],
|
|
783
|
-
hidden$: Ct(t,
|
|
781
|
+
hidden$: Ct(t, dt.UNIVER_SHEET),
|
|
784
782
|
disabled$: Ce([
|
|
785
783
|
e.subscribeContextValue$(ge),
|
|
786
784
|
e.subscribeContextValue$(_e)
|
|
@@ -793,7 +791,7 @@ var _i = Object.defineProperty, gi = Object.getOwnPropertyDescriptor, mi = (t, e
|
|
|
793
791
|
return i && r && _i(e, n, r), r;
|
|
794
792
|
}, m = (t, e) => (n, i) => e(n, i, t);
|
|
795
793
|
const vi = {}, he = "DESKTOP_FIND_REPLACE_DIALOG", we = 350, Si = 20, Ci = -90;
|
|
796
|
-
let F = class extends
|
|
794
|
+
let F = class extends ht {
|
|
797
795
|
constructor(t, e, n, i, r, s, a, l, d, S, f) {
|
|
798
796
|
super(), this._config = t, this._univerInstanceService = e, this._menuService = n, this._shortcutService = i, this._commandService = r, this._findReplaceService = s, this._dialogService = a, this._layoutService = l, this._localeService = d, this._componentManager = S, this._injector = f, this._initCommands(), this._initUI(), this._initShortcuts();
|
|
799
797
|
}
|
|
@@ -846,17 +844,17 @@ let F = class extends dt {
|
|
|
846
844
|
}
|
|
847
845
|
};
|
|
848
846
|
F = mi([
|
|
849
|
-
|
|
847
|
+
ut(ft.Rendered, F),
|
|
850
848
|
m(1, pe),
|
|
851
849
|
m(2, Mt),
|
|
852
850
|
m(3, bt),
|
|
853
|
-
m(4,
|
|
851
|
+
m(4, ie),
|
|
854
852
|
m(5, g),
|
|
855
853
|
m(6, xt),
|
|
856
854
|
m(7, ve),
|
|
857
855
|
m(8, b(O)),
|
|
858
856
|
m(9, b(Rt)),
|
|
859
|
-
m(10, b(
|
|
857
|
+
m(10, b(ee))
|
|
860
858
|
], F);
|
|
861
859
|
function Ri() {
|
|
862
860
|
const { innerWidth: t } = window;
|
|
@@ -869,9 +867,9 @@ var Mi = Object.defineProperty, bi = Object.getOwnPropertyDescriptor, xi = (t, e
|
|
|
869
867
|
}, ue = (t, e) => (n, i) => e(n, i, t);
|
|
870
868
|
const yi = "FIND_REPLACE_PLUGIN";
|
|
871
869
|
var V;
|
|
872
|
-
let fe = (V = class extends
|
|
870
|
+
let fe = (V = class extends pt {
|
|
873
871
|
constructor(t = {}, e, n) {
|
|
874
|
-
super(), this._config = t, this._injector = e, this._localeService = n, this._config =
|
|
872
|
+
super(), this._config = t, this._injector = e, this._localeService = n, this._config = _t.deepMerge({}, vi, this._config);
|
|
875
873
|
}
|
|
876
874
|
onStarting(t) {
|
|
877
875
|
[
|
|
@@ -890,13 +888,13 @@ let fe = (V = class extends ft {
|
|
|
890
888
|
}
|
|
891
889
|
}, o(V, "pluginName", yi), V);
|
|
892
890
|
fe = xi([
|
|
893
|
-
ue(1, b(
|
|
891
|
+
ue(1, b(ee)),
|
|
894
892
|
ue(2, b(O))
|
|
895
893
|
], fe);
|
|
896
894
|
export {
|
|
897
895
|
Z as FindBy,
|
|
898
896
|
Y as FindDirection,
|
|
899
|
-
|
|
897
|
+
Ni as FindModel,
|
|
900
898
|
F as FindReplaceController,
|
|
901
899
|
J as FindScope,
|
|
902
900
|
Oe as GoToNextMatchOperation,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { ICommandService, IUniverInstanceService, LocaleService, RxDisposable } from '@univerjs/core';
|
|
1
|
+
import { ICommandService, Injector, IUniverInstanceService, LocaleService, RxDisposable } from '@univerjs/core';
|
|
2
2
|
import { MenuConfig, ComponentManager, IDialogService, ILayoutService, IMenuService, IShortcutService } from '@univerjs/ui';
|
|
3
|
-
import { Injector } from '@wendellhu/redi';
|
|
4
3
|
import { IFindReplaceService } from '../services/find-replace.service';
|
|
5
4
|
|
|
6
5
|
export interface IUniverFindReplaceConfig {
|
package/lib/types/plugin.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { LocaleService, Plugin } from '@univerjs/core';
|
|
2
|
-
import { Injector } from '@wendellhu/redi';
|
|
1
|
+
import { LocaleService, Plugin, Injector } from '@univerjs/core';
|
|
3
2
|
import { IUniverFindReplaceConfig } from './controllers/find-replace.controller';
|
|
4
3
|
|
|
5
4
|
export declare class UniverFindReplacePlugin extends Plugin {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Nullable, Disposable, IContextService, IUniverInstanceService } from '@univerjs/core';
|
|
2
|
-
import { IDisposable, Injector } from '@wendellhu/redi';
|
|
1
|
+
import { IDisposable, Nullable, Disposable, IContextService, Injector, IUniverInstanceService } from '@univerjs/core';
|
|
3
2
|
import { Observable, BehaviorSubject } from 'rxjs';
|
|
4
3
|
|
|
5
4
|
export type FindProgressFn = () => void;
|
|
@@ -110,7 +109,7 @@ export interface IFindReplaceService {
|
|
|
110
109
|
replace(): Promise<boolean>;
|
|
111
110
|
replaceAll(): Promise<IReplaceAllResult>;
|
|
112
111
|
}
|
|
113
|
-
export declare const IFindReplaceService: import('@
|
|
112
|
+
export declare const IFindReplaceService: import('@univerjs/core').IdentifierDecorator<IFindReplaceService>;
|
|
114
113
|
/**
|
|
115
114
|
* The find query object with finding options.
|
|
116
115
|
*/
|
package/lib/umd/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(c,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/engine-render"),require("react"),require("@univerjs/design"),require("@wendellhu/redi/react-bindings")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","@univerjs/ui","rxjs","@univerjs/engine-render","react","@univerjs/design","@wendellhu/redi/react-bindings"],o):(c=typeof globalThis<"u"?globalThis:c||self,o(c.UniverFindReplace={},c.UniverCore,c["@wendellhu/redi"],c.UniverUi,c.rxjs,c.UniverEngineRender,c.React,c.UniverDesign,c["@wendellhu/redi/react-bindings"]))})(this,function(c,o,m,u,v,he,l,p,y){"use strict";var Ct=Object.defineProperty;var Rt=(c,o,m)=>o in c?Ct(c,o,{enumerable:!0,configurable:!0,writable:!0,value:m}):c[o]=m;var d=(c,o,m)=>Rt(c,typeof o!="symbol"?o+"":o,m);var Y;var R=function(){return R=Object.assign||function(n){for(var e,i=1,t=arguments.length;i<t;i++){e=arguments[i];for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&(n[a]=e[a])}return n},R.apply(this,arguments)},ue=function(n,e){var i={};for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&e.indexOf(t)<0&&(i[t]=n[t]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var a=0,t=Object.getOwnPropertySymbols(n);a<t.length;a++)e.indexOf(t[a])<0&&Object.prototype.propertyIsEnumerable.call(n,t[a])&&(i[t[a]]=n[t[a]]);return i},J=l.forwardRef(function(n,e){var i=n.icon,t=n.id,a=n.className,s=n.extend,r=ue(n,["icon","id","className","extend"]),f="univerjs-icon univerjs-icon-".concat(t," ").concat(a||"").trim(),_=l.useRef("_".concat(_e()));return Q(i,"".concat(t),{defIds:i.defIds,idSuffix:_.current},R({ref:e,className:f},r),s)});function Q(n,e,i,t,a){return l.createElement(n.tag,R(R({key:e},fe(n,i,a)),t),(pe(n,i).children||[]).map(function(s,r){return Q(s,"".concat(e,"-").concat(n.tag,"-").concat(r),i,void 0,a)}))}function fe(n,e,i){var t=R({},n.attrs);i!=null&&i.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=i.colorChannel1);var a=e.defIds;return!a||a.length===0||(n.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+e.idSuffix),Object.entries(t).forEach(function(s){var r=s[0],f=s[1];typeof f=="string"&&(t[r]=f.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),t}function pe(n,e){var i,t=e.defIds;return!t||t.length===0?n:n.tag==="defs"&&(!((i=n.children)===null||i===void 0)&&i.length)?R(R({},n),{children:n.children.map(function(a){return typeof a.attrs.id=="string"&&t&&t.indexOf(a.attrs.id)>-1?R(R({},a),{attrs:R(R({},a.attrs),{id:a.attrs.id+e.idSuffix})}):a})}):n}function _e(){return Math.random().toString(36).substring(2,8)}J.displayName="UniverIcon";var ge={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_217_40",style:{maskType:"alpha"},width:17,height:17,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#D9D9D9",d:"M0.9 0.09H16.9V16.09H0.9z"}}]},{tag:"g",attrs:{mask:"url(#mask0_217_40)"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.39551 7.37266C2.39551 4.18105 4.98281 1.59375 8.17441 1.59375C11.366 1.59375 13.9533 4.18105 13.9533 7.37266C13.9533 8.72342 13.4898 9.96603 12.7133 10.95L15.1964 13.4331C15.4619 13.6986 15.4619 14.1291 15.1964 14.3946C14.9309 14.6601 14.5004 14.6601 14.2349 14.3946L11.7518 11.9115C10.7678 12.6881 9.52525 13.1516 8.17441 13.1516C4.98281 13.1516 2.39551 10.5642 2.39551 7.37266ZM8.17441 2.95349C5.73378 2.95349 3.75525 4.93202 3.75525 7.37266C3.75525 9.81333 5.73378 11.7918 8.17441 11.7918C10.6151 11.7918 12.5936 9.81333 12.5936 7.37266C12.5936 4.93202 10.6151 2.95349 8.17441 2.95349Z",fillRule:"evenodd",clipRule:"evenodd"}}]}]},X=l.forwardRef(function(n,e){return l.createElement(J,Object.assign({},n,{id:"search-single-16",ref:e,icon:ge}))});X.displayName="SearchSingle16";const q="FIND_REPLACE_INPUT_FOCUS",ee="FIND_REPLACE_DIALOG_FOCUS",te="FIND_REPLACE_REPLACE_REVEALED";var me=Object.defineProperty,ve=Object.getOwnPropertyDescriptor,ne=(n,e,i,t)=>{for(var a=t>1?void 0:t?ve(e,i):e,s=n.length-1,r;s>=0;s--)(r=n[s])&&(a=(t?r(e,i,a):r(a))||a);return t&&a&&me(e,i,a),a},U=(n,e)=>(i,t)=>e(i,t,n);class Se extends o.Disposable{}const M=m.createIdentifier("find-replace.service");function Ce(n){return typeof n.findString<"u"||typeof n.inputtingFindString<"u"||typeof n.findDirection<"u"||typeof n.matchesTheWholeCell<"u"||typeof n.caseSensitive<"u"||typeof n.findScope<"u"||typeof n.findBy<"u"}let B=class extends o.Disposable{constructor(e,i,t){super();d(this,"currentMatch$",new v.BehaviorSubject(null));d(this,"replaceables$",new v.BehaviorSubject([]));d(this,"_findModels",[]);d(this,"_matchingModel",null);d(this,"_matches",[]);d(this,"_currentSearchingDisposables",null);this._state=e,this._providers=i,this._univerInstanceService=t,this.disposeWithMe(this._state.stateUpdates$.pipe(v.throttleTime(200,void 0,{leading:!0,trailing:!0})).subscribe(async a=>{const s=this._state.state;Ce(a)&&(s.findString!==""&&!s.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({...k(),revealed:!1})}async start(){if(!this._state.findString)return{results:[]};const e=await this._startSearching();return this._state.changeState({findCompleted:!0}),e}async _startSearching(){if(!this._state.findString)return{results:[]};const e=Array.from(this._providers),i=this._findModels=(await Promise.all(e.map(a=>a.find({findString:this._state.findString,findDirection:this._state.findDirection,findScope:this._state.findScope,findBy:this._state.findBy,replaceRevealed:this._state.replaceRevealed,caseSensitive:this._state.caseSensitive,matchesTheWholeCell:this._state.matchesTheWholeCell})))).flat();this._subscribeToModelsChanges(i);const t=this._matches=i.map(a=>a.getMatches()).flat();return this.replaceables$.next(t.filter(a=>a.replaceable)),t.length?(this._moveToInitialMatch(i),this._state.changeState({matchesCount:t.length}),{results:t}):(this._state.changeState({matchesCount:0,matchesPosition:0}),{results:[]})}_stopSearching(){var e;this._providers.forEach(i=>i.terminate()),this._findModels=[],this._matches=[],this._matchingModel=null,(e=this._currentSearchingDisposables)==null||e.dispose(),this._currentSearchingDisposables=null,this.currentMatch$.next(null),this.replaceables$.next([]),this._state.changeState({findCompleted:!1,matchesCount:0,matchesPosition:0})}_subscribeToModelsChanges(e){const i=this._currentSearchingDisposables=new o.DisposableCollection,t=v.combineLatest(e.map(a=>a.matchesUpdate$)).pipe(v.debounceTime(220)).subscribe(([...a])=>{const s=this._matches=a.flat();s.length?(this._moveToInitialMatch(this._findModels,!0),this._state.changeState({matchesCount:s.length}),this.replaceables$.next(s.filter(r=>r.replaceable))):(this._state.changeState({matchesCount:0,matchesPosition:0}),this.replaceables$.next([]))});e.forEach(a=>i.add(o.toDisposable(a.activelyChangingMatch$.subscribe(s=>{const r=this._matches.findIndex(f=>f===s);this._state.changeState({matchesPosition:r+1})})))),i.add(o.toDisposable(t))}async replace(){return this._matchingModel?this._matchingModel.replace(this._state.replaceString):!1}async replaceAll(){const e=await Promise.all(this._findModels.map(i=>i.replaceAll(this._state.replaceString))).then(i=>i.reduce((t,a)=>(t.success+=a.success,t.failure+=a.failure,t),{success:0,failure:0}));return e.failure===0&&this._stopSearching(),e}getCurrentMatch(){return this._state.matchesPosition>0?this._matches[this._state.matchesPosition-1]:null}_markMatch(e){const i=this._matches.findIndex(t=>t===e);this.currentMatch$.next(e),this._state.changeState({matchesPosition:i+1})}moveToNextMatch(){if(!this._matchingModel)return;const e=this._findModels.length===1,i=this._matchingModel.moveToNextMatch({loop:e});if(i)this._markMatch(i);else{const t=this._findModels.findIndex(a=>a===this._matchingModel);this._moveToNextUnitMatch(t)}}_moveToNextUnitMatch(e){const i=this._findModels.length;for(let t=(e+1)%i;t!==e;){const a=this._findModels[t],s=a.moveToNextMatch({ignoreSelection:!0});if(s){this._matchingModel=a,this._markMatch(s);return}t=(t+1)%i}if(this._matchingModel){const t=this._matchingModel.moveToNextMatch({ignoreSelection:!0});t&&this._markMatch(t)}}moveToPreviousMatch(){if(!this._matchingModel)return;const e=this._findModels.length===1,i=this._matchingModel.moveToPreviousMatch({loop:e});if(i){const t=this._matches.findIndex(a=>a===i);this.currentMatch$.next(i),this._state.changeState({matchesPosition:t+1})}else{const t=this._findModels.length,a=this._findModels.findIndex(r=>r===this._matchingModel);for(let r=(a-1+t)%t;r!==a;){const f=this._findModels[r],_=f.moveToPreviousMatch({ignoreSelection:!0});if(_){this._matchingModel=f,this._markMatch(_);return}r=(r-1)%t}const s=this._matchingModel.moveToPreviousMatch({ignoreSelection:!0});s&&this._markMatch(s)}}_moveToInitialMatch(e,i=!1){var s;const t=(s=this._univerInstanceService.getFocusedUnit())==null?void 0:s.getUnitId();if(!t)return-1;const a=e.findIndex(r=>r.unitId===t);if(a!==-1){this._matchingModel=e[a];const r=this._matchingModel.moveToNextMatch({stayIfOnMatch:!0,noFocus:i});if(r)return this._markMatch(r),a}return this._moveToNextUnitMatch(a),0}};B=ne([U(2,o.IUniverInstanceService)],B);var O=(n=>(n.ROW="row",n.COLUMN="column",n))(O||{}),x=(n=>(n.VALUE="value",n.FORMULA="formula",n))(x||{}),P=(n=>(n.SUBUNIT="subunit",n.UNIT="unit",n))(P||{});function k(){return{caseSensitive:!1,findBy:"value",findCompleted:!1,findDirection:"row",findScope:"subunit",findString:"",inputtingFindString:"",matchesCount:0,matchesPosition:0,matchesTheWholeCell:!1,replaceRevealed:!1,replaceString:"",revealed:!0}}class Re{constructor(){d(this,"_stateUpdates$",new v.Subject);d(this,"stateUpdates$",this._stateUpdates$.asObservable());d(this,"_state$",new v.BehaviorSubject(k()));d(this,"state$",this._state$.asObservable());d(this,"_findString","");d(this,"_inputtingFindString","");d(this,"_replaceString","");d(this,"_revealed",!1);d(this,"_replaceRevealed",!1);d(this,"_matchesPosition",0);d(this,"_matchesCount",0);d(this,"_caseSensitive",!0);d(this,"_matchesTheWholeCell",!1);d(this,"_findDirection","row");d(this,"_findScope","subunit");d(this,"_findBy","value");d(this,"_findCompleted",!1)}get state(){return this._state$.getValue()}get inputtingFindString(){return this._inputtingFindString}get findString(){return this._findString}get revealed(){return this._revealed}get replaceRevealed(){return this._replaceRevealed}get matchesPosition(){return this._matchesPosition}get matchesCount(){return this._matchesCount}get replaceString(){return this._replaceString}get caseSensitive(){return this._caseSensitive}get matchesTheWholeCell(){return this._matchesTheWholeCell}get findDirection(){return this._findDirection}get findScope(){return this._findScope}get findBy(){return this._findBy}get findCompleted(){return this._findCompleted}changeState(e){let i=!1;const t={};typeof e.findString<"u"&&e.findString!==this._findString&&(this._findString=e.findString,t.findString=this._findString,i=!0),typeof e.revealed<"u"&&e.revealed!==this._revealed&&(this._revealed=e.revealed,t.revealed=e.revealed,i=!0),typeof e.replaceRevealed<"u"&&e.replaceRevealed!==this._replaceRevealed&&(this._replaceRevealed=e.replaceRevealed,t.replaceRevealed=e.replaceRevealed,i=!0),typeof e.replaceString<"u"&&e.replaceString!==this._replaceString&&(this._replaceString=e.replaceString,t.replaceString=e.replaceString,i=!0),typeof e.matchesCount<"u"&&e.matchesCount!==this._matchesCount&&(this._matchesCount=e.matchesCount,t.matchesCount=e.matchesCount,i=!0),typeof e.matchesPosition<"u"&&e.matchesPosition!==this._matchesPosition&&(this._matchesPosition=e.matchesPosition,t.matchesPosition=e.matchesPosition,i=!0),typeof e.findBy<"u"&&e.findBy!==this._findBy&&(this._findBy=e.findBy,t.findBy=e.findBy,i=!0),typeof e.findScope<"u"&&e.findScope!==this._findScope&&(this._findScope=e.findScope,t.findScope=e.findScope,i=!0),typeof e.findDirection<"u"&&e.findDirection!==this._findDirection&&(this._findDirection=e.findDirection,t.findDirection=e.findDirection,i=!0),typeof e.caseSensitive<"u"&&e.caseSensitive!==this._caseSensitive&&(this._caseSensitive=e.caseSensitive,t.caseSensitive=e.caseSensitive,i=!0),typeof e.matchesTheWholeCell<"u"&&e.matchesTheWholeCell!==this._matchesTheWholeCell&&(this._matchesTheWholeCell=e.matchesTheWholeCell,t.matchesTheWholeCell=e.matchesTheWholeCell,i=!0),typeof e.inputtingFindString<"u"&&e.inputtingFindString!==this._inputtingFindString&&(this._inputtingFindString=e.inputtingFindString,t.inputtingFindString=e.inputtingFindString,i=!0),typeof e.findCompleted<"u"&&e.findCompleted!==this._findCompleted&&(this._findCompleted=e.findCompleted,t.findCompleted=e.findCompleted,i=!0),i&&(this._state$.next({caseSensitive:this._caseSensitive,findBy:this._findBy,findCompleted:this._findCompleted,findDirection:this._findDirection,findScope:this._findScope,findString:this._findString,inputtingFindString:this._inputtingFindString,matchesCount:this._matchesCount,matchesPosition:this._matchesPosition,matchesTheWholeCell:this._matchesTheWholeCell,replaceRevealed:this._replaceRevealed,revealed:this._revealed}),this._stateUpdates$.next(t))}}let W=class extends o.Disposable{constructor(e,i){super();d(this,"_providers",new Set);d(this,"_state",new Re);d(this,"_model");d(this,"_currentMatch$",new v.BehaviorSubject(null));d(this,"currentMatch$",this._currentMatch$.asObservable());d(this,"_replaceables$",new v.BehaviorSubject([]));d(this,"replaceables$",this._replaceables$.asObservable());d(this,"_focusSignal$",new v.Subject);d(this,"focusSignal$",this._focusSignal$.asObservable());this._injector=e,this._contextService=i}get stateUpdates$(){return this._state.stateUpdates$}get state$(){return this._state.state$}get revealed(){return this._state.revealed}get replaceRevealed(){return this._state.replaceRevealed}dispose(){super.dispose(),this._currentMatch$.next(null),this._currentMatch$.complete(),this._replaceables$.next([]),this._replaceables$.complete(),this._focusSignal$.complete()}getCurrentMatch(){var e;return(e=this._model)==null?void 0:e.getCurrentMatch()}getFindString(){return this._state.findString}changeFindString(e){this._state.changeState({findString:e})}focusFindInput(){this._focusSignal$.next()}changeInputtingFindString(e){e?this._state.changeState({inputtingFindString:e}):this._state.changeState({inputtingFindString:"",findString:""})}changeReplaceString(e){this._state.changeState({replaceString:e})}changeMatchesTheWholeCell(e){this._state.changeState({matchesTheWholeCell:e})}changeCaseSensitive(e){this._state.changeState({caseSensitive:e})}changeFindBy(e){this._state.changeState({findBy:e}),this._toggleDisplayRawFormula(e==="formula")}changeFindScope(e){this._state.changeState({findScope:e})}changeFindDirection(e){this._state.changeState({findDirection:e})}moveToNextMatch(){this._model&&(this._state.replaceRevealed&&!this._model.searched?(this._state.changeState({findString:this._state.inputtingFindString}),this._model.start()):this._model.moveToNextMatch(),this._focusSignal$.next())}moveToPreviousMatch(){this._model&&(this._state.replaceRevealed&&!this._model.searched?(this._state.changeState({findString:this._state.inputtingFindString}),this._model.start()):this._model.moveToPreviousMatch(),this._focusSignal$.next())}async replace(){return this._model?this._model.replace():!1}async replaceAll(){if(!this._model)throw new Error("[FindReplaceService] replaceAll: model is not initialized!");return this._model.replaceAll()}revealReplace(){this._state.changeState({replaceRevealed:!0,inputtingFindString:this._state.findString}),this._toggleRevealReplace(!0)}start(e=!1){if(this._providers.size===0)return!1;this._model=this._injector.createInstance(B,this._state,this._providers),this._model.currentMatch$.subscribe(t=>this._currentMatch$.next(t)),this._model.replaceables$.subscribe(t=>this._replaceables$.next(t));const i=k();return e&&(i.replaceRevealed=!0),this._state.changeState(i),this._toggleRevealReplace(e),!0}find(){var e;(e=this._model)==null||e.start()}terminate(){var e;(e=this._model)==null||e.dispose(),this._model=null,this._toggleDisplayRawFormula(!1),this._toggleRevealReplace(!1)}registerFindReplaceProvider(e){return this._providers.add(e),o.toDisposable(()=>this._providers.delete(e))}_toggleRevealReplace(e){this._contextService.setContextValue(te,e)}_toggleDisplayRawFormula(e){this._contextService.setContextValue(he.RENDER_RAW_FORMULA_KEY,e)}};W=ne([U(0,m.Inject(m.Injector)),U(1,o.IContextService)],W);const D={id:"ui.operation.open-find-dialog",type:o.CommandType.OPERATION,handler:n=>{const e=n.get(M);return e.revealed?e.focusFindInput():e.start(),!0}},E={id:"ui.operation.open-replace-dialog",type:o.CommandType.OPERATION,handler:n=>{const e=n.get(M);return e.revealed?e.replaceRevealed?e.focusFindInput():e.revealReplace():e.start(!0),!0}},G={type:o.CommandType.OPERATION,id:"ui.operation.go-to-next-match",handler:n=>(n.get(M).moveToNextMatch(),!0)},V={type:o.CommandType.OPERATION,id:"ui.operation.go-to-previous-match",handler:n=>(n.get(M).moveToPreviousMatch(),!0)};var ie={exports:{}},N={};/**
|
|
1
|
+
(function(c,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("@univerjs/core"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/engine-render"),require("react"),require("@univerjs/design")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/ui","rxjs","@univerjs/engine-render","react","@univerjs/design"],s):(c=typeof globalThis<"u"?globalThis:c||self,s(c.UniverFindReplace={},c.UniverCore,c.UniverUi,c.rxjs,c.UniverEngineRender,c.React,c.UniverDesign))})(this,function(c,s,l,m,le,d,p){"use strict";var vt=Object.defineProperty;var St=(c,s,l)=>s in c?vt(c,s,{enumerable:!0,configurable:!0,writable:!0,value:l}):c[s]=l;var h=(c,s,l)=>St(c,typeof s!="symbol"?s+"":s,l);var $;var C=function(){return C=Object.assign||function(n){for(var e,i=1,t=arguments.length;i<t;i++){e=arguments[i];for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&(n[a]=e[a])}return n},C.apply(this,arguments)},de=function(n,e){var i={};for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&e.indexOf(t)<0&&(i[t]=n[t]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var a=0,t=Object.getOwnPropertySymbols(n);a<t.length;a++)e.indexOf(t[a])<0&&Object.prototype.propertyIsEnumerable.call(n,t[a])&&(i[t[a]]=n[t[a]]);return i},Y=d.forwardRef(function(n,e){var i=n.icon,t=n.id,a=n.className,r=n.extend,o=de(n,["icon","id","className","extend"]),f="univerjs-icon univerjs-icon-".concat(t," ").concat(a||"").trim(),_=d.useRef("_".concat(fe()));return Z(i,"".concat(t),{defIds:i.defIds,idSuffix:_.current},C({ref:e,className:f},o),r)});function Z(n,e,i,t,a){return d.createElement(n.tag,C(C({key:e},he(n,i,a)),t),(ue(n,i).children||[]).map(function(r,o){return Z(r,"".concat(e,"-").concat(n.tag,"-").concat(o),i,void 0,a)}))}function he(n,e,i){var t=C({},n.attrs);i!=null&&i.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=i.colorChannel1);var a=e.defIds;return!a||a.length===0||(n.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+e.idSuffix),Object.entries(t).forEach(function(r){var o=r[0],f=r[1];typeof f=="string"&&(t[o]=f.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),t}function ue(n,e){var i,t=e.defIds;return!t||t.length===0?n:n.tag==="defs"&&(!((i=n.children)===null||i===void 0)&&i.length)?C(C({},n),{children:n.children.map(function(a){return typeof a.attrs.id=="string"&&t&&t.indexOf(a.attrs.id)>-1?C(C({},a),{attrs:C(C({},a.attrs),{id:a.attrs.id+e.idSuffix})}):a})}):n}function fe(){return Math.random().toString(36).substring(2,8)}Y.displayName="UniverIcon";var pe={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_217_40",style:{maskType:"alpha"},width:17,height:17,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#D9D9D9",d:"M0.9 0.09H16.9V16.09H0.9z"}}]},{tag:"g",attrs:{mask:"url(#mask0_217_40)"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.39551 7.37266C2.39551 4.18105 4.98281 1.59375 8.17441 1.59375C11.366 1.59375 13.9533 4.18105 13.9533 7.37266C13.9533 8.72342 13.4898 9.96603 12.7133 10.95L15.1964 13.4331C15.4619 13.6986 15.4619 14.1291 15.1964 14.3946C14.9309 14.6601 14.5004 14.6601 14.2349 14.3946L11.7518 11.9115C10.7678 12.6881 9.52525 13.1516 8.17441 13.1516C4.98281 13.1516 2.39551 10.5642 2.39551 7.37266ZM8.17441 2.95349C5.73378 2.95349 3.75525 4.93202 3.75525 7.37266C3.75525 9.81333 5.73378 11.7918 8.17441 11.7918C10.6151 11.7918 12.5936 9.81333 12.5936 7.37266C12.5936 4.93202 10.6151 2.95349 8.17441 2.95349Z",fillRule:"evenodd",clipRule:"evenodd"}}]}]},J=d.forwardRef(function(n,e){return d.createElement(Y,Object.assign({},n,{id:"search-single-16",ref:e,icon:pe}))});J.displayName="SearchSingle16";const Q="FIND_REPLACE_INPUT_FOCUS",X="FIND_REPLACE_DIALOG_FOCUS",q="FIND_REPLACE_REPLACE_REVEALED";var _e=Object.defineProperty,ge=Object.getOwnPropertyDescriptor,ee=(n,e,i,t)=>{for(var a=t>1?void 0:t?ge(e,i):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(a=(t?o(e,i,a):o(a))||a);return t&&a&&_e(e,i,a),a},A=(n,e)=>(i,t)=>e(i,t,n);class me extends s.Disposable{}const R=s.createIdentifier("find-replace.service");function ve(n){return typeof n.findString<"u"||typeof n.inputtingFindString<"u"||typeof n.findDirection<"u"||typeof n.matchesTheWholeCell<"u"||typeof n.caseSensitive<"u"||typeof n.findScope<"u"||typeof n.findBy<"u"}let U=class extends s.Disposable{constructor(e,i,t){super();h(this,"currentMatch$",new m.BehaviorSubject(null));h(this,"replaceables$",new m.BehaviorSubject([]));h(this,"_findModels",[]);h(this,"_matchingModel",null);h(this,"_matches",[]);h(this,"_currentSearchingDisposables",null);this._state=e,this._providers=i,this._univerInstanceService=t,this.disposeWithMe(this._state.stateUpdates$.pipe(m.throttleTime(200,void 0,{leading:!0,trailing:!0})).subscribe(async a=>{const r=this._state.state;ve(a)&&(r.findString!==""&&!r.replaceRevealed?(await this._startSearching(),this._state.changeState({findCompleted:!0})):a.replaceRevealed!==!0&&this._stopSearching())}))}get searched(){return this._findModels.length>0}dispose(){super.dispose(),this._stopSearching(),this.currentMatch$.complete(),this.replaceables$.complete(),this._state.changeState({...w(),revealed:!1})}async start(){if(!this._state.findString)return{results:[]};const e=await this._startSearching();return this._state.changeState({findCompleted:!0}),e}async _startSearching(){if(!this._state.findString)return{results:[]};const e=Array.from(this._providers),i=this._findModels=(await Promise.all(e.map(a=>a.find({findString:this._state.findString,findDirection:this._state.findDirection,findScope:this._state.findScope,findBy:this._state.findBy,replaceRevealed:this._state.replaceRevealed,caseSensitive:this._state.caseSensitive,matchesTheWholeCell:this._state.matchesTheWholeCell})))).flat();this._subscribeToModelsChanges(i);const t=this._matches=i.map(a=>a.getMatches()).flat();return this.replaceables$.next(t.filter(a=>a.replaceable)),t.length?(this._moveToInitialMatch(i),this._state.changeState({matchesCount:t.length}),{results:t}):(this._state.changeState({matchesCount:0,matchesPosition:0}),{results:[]})}_stopSearching(){var e;this._providers.forEach(i=>i.terminate()),this._findModels=[],this._matches=[],this._matchingModel=null,(e=this._currentSearchingDisposables)==null||e.dispose(),this._currentSearchingDisposables=null,this.currentMatch$.next(null),this.replaceables$.next([]),this._state.changeState({findCompleted:!1,matchesCount:0,matchesPosition:0})}_subscribeToModelsChanges(e){const i=this._currentSearchingDisposables=new s.DisposableCollection,t=m.combineLatest(e.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(o=>o.replaceable))):(this._state.changeState({matchesCount:0,matchesPosition:0}),this.replaceables$.next([]))});e.forEach(a=>i.add(s.toDisposable(a.activelyChangingMatch$.subscribe(r=>{const o=this._matches.findIndex(f=>f===r);this._state.changeState({matchesPosition:o+1})})))),i.add(s.toDisposable(t))}async replace(){return this._matchingModel?this._matchingModel.replace(this._state.replaceString):!1}async replaceAll(){const e=await Promise.all(this._findModels.map(i=>i.replaceAll(this._state.replaceString))).then(i=>i.reduce((t,a)=>(t.success+=a.success,t.failure+=a.failure,t),{success:0,failure:0}));return e.failure===0&&this._stopSearching(),e}getCurrentMatch(){return this._state.matchesPosition>0?this._matches[this._state.matchesPosition-1]:null}_markMatch(e){const i=this._matches.findIndex(t=>t===e);this.currentMatch$.next(e),this._state.changeState({matchesPosition:i+1})}moveToNextMatch(){if(!this._matchingModel)return;const e=this._findModels.length===1,i=this._matchingModel.moveToNextMatch({loop:e});if(i)this._markMatch(i);else{const t=this._findModels.findIndex(a=>a===this._matchingModel);this._moveToNextUnitMatch(t)}}_moveToNextUnitMatch(e){const i=this._findModels.length;for(let t=(e+1)%i;t!==e;){const a=this._findModels[t],r=a.moveToNextMatch({ignoreSelection:!0});if(r){this._matchingModel=a,this._markMatch(r);return}t=(t+1)%i}if(this._matchingModel){const t=this._matchingModel.moveToNextMatch({ignoreSelection:!0});t&&this._markMatch(t)}}moveToPreviousMatch(){if(!this._matchingModel)return;const e=this._findModels.length===1,i=this._matchingModel.moveToPreviousMatch({loop:e});if(i){const t=this._matches.findIndex(a=>a===i);this.currentMatch$.next(i),this._state.changeState({matchesPosition:t+1})}else{const t=this._findModels.length,a=this._findModels.findIndex(o=>o===this._matchingModel);for(let o=(a-1+t)%t;o!==a;){const f=this._findModels[o],_=f.moveToPreviousMatch({ignoreSelection:!0});if(_){this._matchingModel=f,this._markMatch(_);return}o=(o-1)%t}const r=this._matchingModel.moveToPreviousMatch({ignoreSelection:!0});r&&this._markMatch(r)}}_moveToInitialMatch(e,i=!1){var r;const t=(r=this._univerInstanceService.getFocusedUnit())==null?void 0:r.getUnitId();if(!t)return-1;const a=e.findIndex(o=>o.unitId===t);if(a!==-1){this._matchingModel=e[a];const o=this._matchingModel.moveToNextMatch({stayIfOnMatch:!0,noFocus:i});if(o)return this._markMatch(o),a}return this._moveToNextUnitMatch(a),0}};U=ee([A(2,s.IUniverInstanceService)],U);var D=(n=>(n.ROW="row",n.COLUMN="column",n))(D||{}),T=(n=>(n.VALUE="value",n.FORMULA="formula",n))(T||{}),O=(n=>(n.SUBUNIT="subunit",n.UNIT="unit",n))(O||{});function w(){return{caseSensitive:!1,findBy:"value",findCompleted:!1,findDirection:"row",findScope:"subunit",findString:"",inputtingFindString:"",matchesCount:0,matchesPosition:0,matchesTheWholeCell:!1,replaceRevealed:!1,replaceString:"",revealed:!0}}class Se{constructor(){h(this,"_stateUpdates$",new m.Subject);h(this,"stateUpdates$",this._stateUpdates$.asObservable());h(this,"_state$",new m.BehaviorSubject(w()));h(this,"state$",this._state$.asObservable());h(this,"_findString","");h(this,"_inputtingFindString","");h(this,"_replaceString","");h(this,"_revealed",!1);h(this,"_replaceRevealed",!1);h(this,"_matchesPosition",0);h(this,"_matchesCount",0);h(this,"_caseSensitive",!0);h(this,"_matchesTheWholeCell",!1);h(this,"_findDirection","row");h(this,"_findScope","subunit");h(this,"_findBy","value");h(this,"_findCompleted",!1)}get state(){return this._state$.getValue()}get inputtingFindString(){return this._inputtingFindString}get findString(){return this._findString}get revealed(){return this._revealed}get replaceRevealed(){return this._replaceRevealed}get matchesPosition(){return this._matchesPosition}get matchesCount(){return this._matchesCount}get replaceString(){return this._replaceString}get caseSensitive(){return this._caseSensitive}get matchesTheWholeCell(){return this._matchesTheWholeCell}get findDirection(){return this._findDirection}get findScope(){return this._findScope}get findBy(){return this._findBy}get findCompleted(){return this._findCompleted}changeState(e){let i=!1;const t={};typeof e.findString<"u"&&e.findString!==this._findString&&(this._findString=e.findString,t.findString=this._findString,i=!0),typeof e.revealed<"u"&&e.revealed!==this._revealed&&(this._revealed=e.revealed,t.revealed=e.revealed,i=!0),typeof e.replaceRevealed<"u"&&e.replaceRevealed!==this._replaceRevealed&&(this._replaceRevealed=e.replaceRevealed,t.replaceRevealed=e.replaceRevealed,i=!0),typeof e.replaceString<"u"&&e.replaceString!==this._replaceString&&(this._replaceString=e.replaceString,t.replaceString=e.replaceString,i=!0),typeof e.matchesCount<"u"&&e.matchesCount!==this._matchesCount&&(this._matchesCount=e.matchesCount,t.matchesCount=e.matchesCount,i=!0),typeof e.matchesPosition<"u"&&e.matchesPosition!==this._matchesPosition&&(this._matchesPosition=e.matchesPosition,t.matchesPosition=e.matchesPosition,i=!0),typeof e.findBy<"u"&&e.findBy!==this._findBy&&(this._findBy=e.findBy,t.findBy=e.findBy,i=!0),typeof e.findScope<"u"&&e.findScope!==this._findScope&&(this._findScope=e.findScope,t.findScope=e.findScope,i=!0),typeof e.findDirection<"u"&&e.findDirection!==this._findDirection&&(this._findDirection=e.findDirection,t.findDirection=e.findDirection,i=!0),typeof e.caseSensitive<"u"&&e.caseSensitive!==this._caseSensitive&&(this._caseSensitive=e.caseSensitive,t.caseSensitive=e.caseSensitive,i=!0),typeof e.matchesTheWholeCell<"u"&&e.matchesTheWholeCell!==this._matchesTheWholeCell&&(this._matchesTheWholeCell=e.matchesTheWholeCell,t.matchesTheWholeCell=e.matchesTheWholeCell,i=!0),typeof e.inputtingFindString<"u"&&e.inputtingFindString!==this._inputtingFindString&&(this._inputtingFindString=e.inputtingFindString,t.inputtingFindString=e.inputtingFindString,i=!0),typeof e.findCompleted<"u"&&e.findCompleted!==this._findCompleted&&(this._findCompleted=e.findCompleted,t.findCompleted=e.findCompleted,i=!0),i&&(this._state$.next({caseSensitive:this._caseSensitive,findBy:this._findBy,findCompleted:this._findCompleted,findDirection:this._findDirection,findScope:this._findScope,findString:this._findString,inputtingFindString:this._inputtingFindString,matchesCount:this._matchesCount,matchesPosition:this._matchesPosition,matchesTheWholeCell:this._matchesTheWholeCell,replaceRevealed:this._replaceRevealed,revealed:this._revealed}),this._stateUpdates$.next(t))}}let B=class extends s.Disposable{constructor(e,i){super();h(this,"_providers",new Set);h(this,"_state",new Se);h(this,"_model");h(this,"_currentMatch$",new m.BehaviorSubject(null));h(this,"currentMatch$",this._currentMatch$.asObservable());h(this,"_replaceables$",new m.BehaviorSubject([]));h(this,"replaceables$",this._replaceables$.asObservable());h(this,"_focusSignal$",new m.Subject);h(this,"focusSignal$",this._focusSignal$.asObservable());this._injector=e,this._contextService=i}get stateUpdates$(){return this._state.stateUpdates$}get state$(){return this._state.state$}get revealed(){return this._state.revealed}get replaceRevealed(){return this._state.replaceRevealed}dispose(){super.dispose(),this._currentMatch$.next(null),this._currentMatch$.complete(),this._replaceables$.next([]),this._replaceables$.complete(),this._focusSignal$.complete()}getCurrentMatch(){var e;return(e=this._model)==null?void 0:e.getCurrentMatch()}getFindString(){return this._state.findString}changeFindString(e){this._state.changeState({findString:e})}focusFindInput(){this._focusSignal$.next()}changeInputtingFindString(e){e?this._state.changeState({inputtingFindString:e}):this._state.changeState({inputtingFindString:"",findString:""})}changeReplaceString(e){this._state.changeState({replaceString:e})}changeMatchesTheWholeCell(e){this._state.changeState({matchesTheWholeCell:e})}changeCaseSensitive(e){this._state.changeState({caseSensitive:e})}changeFindBy(e){this._state.changeState({findBy:e}),this._toggleDisplayRawFormula(e==="formula")}changeFindScope(e){this._state.changeState({findScope:e})}changeFindDirection(e){this._state.changeState({findDirection:e})}moveToNextMatch(){this._model&&(this._state.replaceRevealed&&!this._model.searched?(this._state.changeState({findString:this._state.inputtingFindString}),this._model.start()):this._model.moveToNextMatch(),this._focusSignal$.next())}moveToPreviousMatch(){this._model&&(this._state.replaceRevealed&&!this._model.searched?(this._state.changeState({findString:this._state.inputtingFindString}),this._model.start()):this._model.moveToPreviousMatch(),this._focusSignal$.next())}async replace(){return this._model?this._model.replace():!1}async replaceAll(){if(!this._model)throw new Error("[FindReplaceService] replaceAll: model is not initialized!");return this._model.replaceAll()}revealReplace(){this._state.changeState({replaceRevealed:!0,inputtingFindString:this._state.findString}),this._toggleRevealReplace(!0)}start(e=!1){if(this._providers.size===0)return!1;this._model=this._injector.createInstance(U,this._state,this._providers),this._model.currentMatch$.subscribe(t=>this._currentMatch$.next(t)),this._model.replaceables$.subscribe(t=>this._replaceables$.next(t));const i=w();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),s.toDisposable(()=>this._providers.delete(e))}_toggleRevealReplace(e){this._contextService.setContextValue(q,e)}_toggleDisplayRawFormula(e){this._contextService.setContextValue(le.RENDER_RAW_FORMULA_KEY,e)}};B=ee([A(0,s.Inject(s.Injector)),A(1,s.IContextService)],B);const I={id:"ui.operation.open-find-dialog",type:s.CommandType.OPERATION,handler:n=>{const e=n.get(R);return e.revealed?e.focusFindInput():e.start(),!0}},x={id:"ui.operation.open-replace-dialog",type:s.CommandType.OPERATION,handler:n=>{const e=n.get(R);return e.revealed?e.replaceRevealed?e.focusFindInput():e.revealReplace():e.start(!0),!0}},k={type:s.CommandType.OPERATION,id:"ui.operation.go-to-next-match",handler:n=>(n.get(R).moveToNextMatch(),!0)},W={type:s.CommandType.OPERATION,id:"ui.operation.go-to-previous-match",handler:n=>(n.get(R).moveToPreviousMatch(),!0)};var te={exports:{}},P={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var Me=l,ye=Symbol.for("react.element"),be=Symbol.for("react.fragment"),Ie=Object.prototype.hasOwnProperty,Fe=Me.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,De={key:!0,ref:!0,__self:!0,__source:!0};function ae(n,e,i){var t,a={},s=null,r=null;i!==void 0&&(s=""+i),e.key!==void 0&&(s=""+e.key),e.ref!==void 0&&(r=e.ref);for(t in e)Ie.call(e,t)&&!De.hasOwnProperty(t)&&(a[t]=e[t]);if(n&&n.defaultProps)for(t in e=n.defaultProps,e)a[t]===void 0&&(a[t]=e[t]);return{$$typeof:ye,type:n,key:s,ref:r,props:a,_owner:Fe.current}}N.Fragment=be,N.jsx=ae,N.jsxs=ae,ie.exports=N;var h=ie.exports;const H={id:"ui.command.replace-current-match",type:o.CommandType.COMMAND,handler:n=>n.get(M).replace()},Te="CONFIRM_REPLACE_ALL",K={id:"ui.command.replace-all-matches",type:o.CommandType.COMMAND,handler:async n=>{const e=n.get(u.IConfirmService),i=n.get(o.LocaleService),t=n.get(u.IMessageService);if(!await e.confirm({id:Te,title:{title:i.t("find-replace.replace.confirm.title")},cancelText:i.t("button.cancel"),confirmText:i.t("button.confirm")}))return!1;const s=await n.get(M).replaceAll(),{success:r,failure:f}=s;return f>0?(r===0?t.show({type:p.MessageType.Error,content:i.t("find-replace.replace.all-failure")}):t.show({type:p.MessageType.Warning,content:i.t("find-replace.replace.partial-success",`${r}`,`${f}`)}),!1):(t.show({type:p.MessageType.Success,content:i.t("find-replace.replace.all-success",`${r}`)}),!0)}};function se(n){const{findCompleted:e,localeService:i,matchesCount:t,matchesPosition:a,findString:s,findReplaceService:r,onChange:f,..._}=n,C=e&&t===0?i.t("find-replace.dialog.no-result"):t===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:t,onChange:S=>{a===t&&S===1?r.moveToNextMatch():a===1&&S===t||S<a?r.moveToPreviousMatch():r.moveToNextMatch()}}),value:s,onChange:S=>f==null?void 0:f(S),..._})}const j={findReplaceDialogContainer:"univer-find-replace-dialog-container",findReplaceExpandContainer:"univer-find-replace-expand-container",buttonText:"univer-button-text",findReplaceButtonsGroup:"univer-find-replace-buttons-group",findReplaceButtonsGroupRight:"univer-find-replace-buttons-group-right"};function re(n,e){const i=l.useCallback(()=>{var a;(a=document.querySelector(".univer-find-input input"))==null||a.focus()},[]),t=l.useCallback(()=>{const a=document.querySelectorAll(".univer-find-replace-dialog-container .univer-select-selection-search-input");return Array.from(a).some(s=>s===document.activeElement)},[]);return l.useImperativeHandle(e,()=>({focus:i,selectHasFocus:t})),l.useEffect(()=>{const a=n.focusSignal$.subscribe(()=>i());return()=>a.unsubscribe()},[n,i]),{focus:i,selectHasFocus:t}}const Oe=l.forwardRef(function(e,i){const t=y.useDependency(o.LocaleService),a=y.useDependency(M),s=y.useDependency(o.ICommandService),r=u.useObservable(a.state$,void 0,!0),{findCompleted:f,findString:_,matchesCount:I,matchesPosition:C}=r,S=l.useCallback(()=>{s.executeCommand(E.id)},[s]),A=l.useCallback(F=>a.changeFindString(F),[a]);return re(a,i),h.jsxs(l.Fragment,{children:[h.jsx(se,{findCompleted:f,className:"univer-find-input",matchesCount:I,matchesPosition:C,findReplaceService:a,localeService:t,findString:_,onChange:A}),h.jsx("div",{className:j.findReplaceExpandContainer,children:h.jsx(p.Button,{type:"text",size:"small",onClick:S,children:t.t("find-replace.dialog.advanced-finding")})})]})}),xe=l.forwardRef(function(e,i){const t=y.useDependency(M),a=y.useDependency(o.LocaleService),s=y.useDependency(o.ICommandService),r=y.useDependency(u.IMessageService),f=u.useObservable(t.currentMatch$,void 0,!0),_=u.useObservable(t.replaceables$,void 0,!0),I=u.useObservable(t.state$,void 0,!0),{matchesCount:C,matchesPosition:S,findString:A,inputtingFindString:F,replaceString:qe,caseSensitive:et,matchesTheWholeCell:tt,findDirection:nt,findScope:it,findBy:at,findCompleted:Z}=I,st=F.length===0,rt=C===0||!(f!=null&&f.replaceable),ot=_.length===0,ct=l.useCallback(g=>t.changeInputtingFindString(g),[t]),lt=l.useCallback(g=>t.changeReplaceString(g),[t]),{focus:dt}=re(t,i),ht=l.useCallback(()=>{A===F?t.moveToNextMatch():(t.changeFindString(F),t.find())},[A,F,t]),ut=l.useCallback(()=>s.executeCommand(H.id),[s]),ft=l.useCallback(async()=>{await s.executeCommand(K.id),dt()},[s]),pt=l.useCallback(g=>{t.changeFindDirection(g)},[t]),_t=l.useCallback(g=>{t.changeFindScope(g)},[t]),gt=l.useCallback(g=>{t.changeFindBy(g)},[t]),mt=Ee(a),vt=Ne(a),St=je(a);return l.useEffect(()=>{const g=Z&&C===0;let w=null;return g&&(w=r.show({content:a.t("find-replace.dialog.no-match"),type:p.MessageType.Warning,duration:5e3})),()=>w==null?void 0:w.dispose()},[Z,C,r,a]),h.jsxs(l.Fragment,{children:[h.jsx(p.FormLayout,{label:a.t("find-replace.dialog.find"),children:h.jsx(se,{findCompleted:Z,className:"univer-find-input",matchesCount:C,matchesPosition:S,findReplaceService:t,localeService:a,findString:F,onChange:ct})}),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:qe,onChange:g=>lt(g)})}),h.jsx(p.FormLayout,{label:a.t("find-replace.dialog.find-direction.title"),children:h.jsx(p.Select,{value:nt,options:vt,onChange:pt})}),h.jsx(p.FormDualColumnLayout,{children:h.jsxs(l.Fragment,{children:[h.jsx(p.FormLayout,{label:a.t("find-replace.dialog.find-scope.title"),children:h.jsx(p.Select,{value:it,options:mt,onChange:_t})}),h.jsx(p.FormLayout,{label:a.t("find-replace.dialog.find-by.title"),children:h.jsx(p.Select,{value:at,options:St,onChange:gt})})]})}),h.jsx(p.FormDualColumnLayout,{children:h.jsxs(l.Fragment,{children:[h.jsx(p.FormLayout,{children:h.jsx(p.Checkbox,{checked:et,onChange:g=>{t.changeCaseSensitive(g)},children:a.t("find-replace.dialog.case-sensitive")})}),h.jsx(p.FormLayout,{children:h.jsx(p.Checkbox,{checked:tt,onChange:g=>{t.changeMatchesTheWholeCell(g)},children:a.t("find-replace.dialog.match-the-whole-cell")})})]})}),h.jsxs("div",{className:j.findReplaceButtonsGroup,children:[h.jsx(p.Button,{type:"primary",onClick:ht,disabled:st,children:a.t("find-replace.dialog.find")}),h.jsxs("span",{className:j.findReplaceButtonsGroupRight,children:[h.jsx(p.Button,{disabled:rt,onClick:ut,children:a.t("find-replace.dialog.replace")}),h.jsx(p.Button,{disabled:ot,onClick:ft,children:a.t("find-replace.dialog.replace-all")})]})]})]})});function Pe(){const n=y.useDependency(M),e=y.useDependency(u.ILayoutService),i=y.useDependency(o.IContextService),t=u.useObservable(n.state$,void 0,!0),a=l.useRef(null);l.useEffect(()=>{let _;return a.current&&(_=e.registerContainerElement(a.current)),()=>_==null?void 0:_.dispose()},[e]);const s=l.useRef(null),r=l.useCallback(_=>i.setContextValue(ee,_),[i]),f=l.useCallback(_=>i.setContextValue(q,_),[i]);return l.useEffect(()=>{var I;const _=v.fromEvent(document,"focusin").subscribe(C=>{var S;C.target&&((S=a.current)!=null&&S.contains(C.target))?r(!0):r(!1),!s.current||!s.current.selectHasFocus()?f(!0):f(!1)});return(I=s.current)==null||I.focus(),r(!0),f(!0),()=>{_.unsubscribe(),r(!1)}},[r,f]),h.jsx("div",{className:j.findReplaceDialogContainer,ref:a,children:t.replaceRevealed?h.jsx(xe,{ref:s}):h.jsx(Oe,{ref:s})})}function Ee(n){const e=n.getCurrentLocale();return l.useMemo(()=>[{label:n.t("find-replace.dialog.find-scope.current-sheet"),value:P.SUBUNIT},{label:n.t("find-replace.dialog.find-scope.workbook"),value:P.UNIT}],[e])}function Ne(n){const e=n.getCurrentLocale();return l.useMemo(()=>[{label:n.t("find-replace.dialog.find-direction.row"),value:O.ROW},{label:n.t("find-replace.dialog.find-direction.column"),value:O.COLUMN}],[e])}function je(n){const e=n.getCurrentLocale();return l.useMemo(()=>[{label:n.t("find-replace.dialog.find-by.value"),value:x.VALUE},{label:n.t("find-replace.dialog.find-by.formula"),value:x.FORMULA}],[e])}function T(n){return n.getContextValue(ee)}function Le(n){return n.getContextValue(te)}function oe(n){return n.getContextValue(q)}const L="7_find-replace-shortcuts";function $(n){return n.getContextValue(o.FOCUSING_SHEET)}function z(n){return!n.getContextValue(o.EDITOR_ACTIVATED)}const Ae={id:D.id,description:"find-replace.shortcut.open-find-dialog",binding:u.KeyCode.F|u.MetaKeys.CTRL_COMMAND,group:L,preconditions(n){return!T(n)&&$(n)&&z(n)}},we={id:D.id,description:"find-replace.shortcut.open-find-dialog",binding:u.KeyCode.F|u.MetaKeys.CTRL_COMMAND,mac:u.KeyCode.F|u.MetaKeys.MAC_CTRL,preconditions(n){return!T(n)&&$(n)&&z(n)}},Ue={id:E.id,description:"find-replace.shortcut.open-replace-dialog",binding:u.KeyCode.H|u.MetaKeys.CTRL_COMMAND,mac:u.KeyCode.H|u.MetaKeys.MAC_CTRL,group:L,preconditions(n){return $(n)&&z(n)&&(!T(n)||!Le(n))}},Be={id:G.id,description:"find-replace.shortcut.go-to-next-match",binding:u.KeyCode.ENTER,group:L,priority:1e3,preconditions(n){return oe(n)&&T(n)}},ke={id:V.id,description:"find-replace.shortcut.go-to-previous-match",binding:u.KeyCode.ENTER|u.MetaKeys.SHIFT,group:L,priority:1e3,preconditions(n){return oe(n)&&T(n)}};function We(n){const e=n.get(o.IContextService);return{id:D.id,icon:"SearchIcon",tooltip:"find-replace.toolbar",group:u.MenuGroup.TOOLBAR_OTHERS,type:u.MenuItemType.BUTTON,positions:[u.MenuPosition.TOOLBAR_START],hidden$:u.getMenuHiddenObservable(n,o.UniverInstanceType.UNIVER_SHEET),disabled$:v.combineLatest([e.subscribeContextValue$(o.EDITOR_ACTIVATED),e.subscribeContextValue$(o.FOCUSING_SHEET)]).pipe(v.map(([i,t])=>i||!t))}}var Ge=Object.defineProperty,Ve=Object.getOwnPropertyDescriptor,He=(n,e,i,t)=>{for(var a=t>1?void 0:t?Ve(e,i):e,s=n.length-1,r;s>=0;s--)(r=n[s])&&(a=(t?r(e,i,a):r(a))||a);return t&&a&&Ge(e,i,a),a},b=(n,e)=>(i,t)=>e(i,t,n);const Ke={},ce="DESKTOP_FIND_REPLACE_DIALOG",le=350,$e=20,ze=-90;c.FindReplaceController=class extends o.RxDisposable{constructor(e,i,t,a,s,r,f,_,I,C,S){super(),this._config=e,this._univerInstanceService=i,this._menuService=t,this._shortcutService=a,this._commandService=s,this._findReplaceService=r,this._dialogService=f,this._layoutService=_,this._localeService=I,this._componentManager=C,this._injector=S,this._initCommands(),this._initUI(),this._initShortcuts()}_initCommands(){[D,E,G,V,K,H].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initShortcuts(){[Ue,Ae,we,ke,Be].forEach(e=>this.disposeWithMe(this._shortcutService.registerShortcut(e)))}_initUI(){const{menu:e={}}=this._config;this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(We),e)),this.disposeWithMe(this._componentManager.register("FindReplaceDialog",Pe)),this.disposeWithMe(this._componentManager.register("SearchIcon",X)),this._findReplaceService.stateUpdates$.pipe(v.takeUntil(this.dispose$)).subscribe(i=>{i.revealed===!0&&this._openPanel()}),this.disposeWithMe(this._univerInstanceService.focused$.pipe(v.takeUntil(this.dispose$)).subscribe(i=>{(!i||!this._univerInstanceService.getUniverSheetInstance(i))&&this.closePanel()}))}_openPanel(){this._dialogService.open({id:ce,draggable:!0,width:le,title:{title:this._localeService.t("find-replace.dialog.title")},children:{label:"FindReplaceDialog"},destroyOnClose:!0,defaultPosition:Ye(),preservePositionOnDestroy:!0,onClose:()=>this.closePanel()})}closePanel(){this._dialogService.close(ce),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus())}},c.FindReplaceController=He([o.OnLifecycle(o.LifecycleStages.Rendered,c.FindReplaceController),b(1,o.IUniverInstanceService),b(2,u.IMenuService),b(3,u.IShortcutService),b(4,o.ICommandService),b(5,M),b(6,u.IDialogService),b(7,u.ILayoutService),b(8,m.Inject(o.LocaleService)),b(9,m.Inject(u.ComponentManager)),b(10,m.Inject(m.Injector))],c.FindReplaceController);function Ye(){const{innerWidth:n}=window;return{x:(n-le)/2-$e,y:ze}}var Ze=Object.defineProperty,Je=Object.getOwnPropertyDescriptor,Qe=(n,e,i,t)=>{for(var a=t>1?void 0:t?Je(e,i):e,s=n.length-1,r;s>=0;s--)(r=n[s])&&(a=(t?r(e,i,a):r(a))||a);return t&&a&&Ze(e,i,a),a},de=(n,e)=>(i,t)=>e(i,t,n);const Xe="FIND_REPLACE_PLUGIN";c.UniverFindReplacePlugin=(Y=class extends o.Plugin{constructor(e={},i,t){super(),this._config=e,this._injector=i,this._localeService=t,this._config=o.Tools.deepMerge({},Ke,this._config)}onStarting(e){[[c.FindReplaceController,{useFactory:()=>this._injector.createInstance(c.FindReplaceController,this._config)}],[M,{useClass:W}]].forEach(i=>{e.add(i)})}},d(Y,"pluginName",Xe),Y),c.UniverFindReplacePlugin=Qe([de(1,m.Inject(m.Injector)),de(2,m.Inject(o.LocaleService))],c.UniverFindReplacePlugin),c.FindBy=x,c.FindDirection=O,c.FindModel=Se,c.FindScope=P,c.GoToNextMatchOperation=G,c.GoToPreviousMatchOperation=V,c.IFindReplaceService=M,c.OpenFindDialogOperation=D,c.OpenReplaceDialogOperation=E,c.ReplaceAllMatchesCommand=K,c.ReplaceCurrentMatchCommand=H,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|
|
9
|
+
*/var Ce=d,Re=Symbol.for("react.element"),Me=Symbol.for("react.fragment"),ye=Object.prototype.hasOwnProperty,be=Ce.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Ie={key:!0,ref:!0,__self:!0,__source:!0};function ne(n,e,i){var t,a={},r=null,o=null;i!==void 0&&(r=""+i),e.key!==void 0&&(r=""+e.key),e.ref!==void 0&&(o=e.ref);for(t in e)ye.call(e,t)&&!Ie.hasOwnProperty(t)&&(a[t]=e[t]);if(n&&n.defaultProps)for(t in e=n.defaultProps,e)a[t]===void 0&&(a[t]=e[t]);return{$$typeof:Re,type:n,key:r,ref:o,props:a,_owner:be.current}}P.Fragment=Me,P.jsx=ne,P.jsxs=ne,te.exports=P;var u=te.exports;const G={id:"ui.command.replace-current-match",type:s.CommandType.COMMAND,handler:n=>n.get(R).replace()},Fe="CONFIRM_REPLACE_ALL",V={id:"ui.command.replace-all-matches",type:s.CommandType.COMMAND,handler:async n=>{const e=n.get(l.IConfirmService),i=n.get(s.LocaleService),t=n.get(l.IMessageService);if(!await e.confirm({id:Fe,title:{title:i.t("find-replace.replace.confirm.title")},cancelText:i.t("button.cancel"),confirmText:i.t("button.confirm")}))return!1;const r=await n.get(R).replaceAll(),{success:o,failure:f}=r;return f>0?(o===0?t.show({type:p.MessageType.Error,content:i.t("find-replace.replace.all-failure")}):t.show({type:p.MessageType.Warning,content:i.t("find-replace.replace.partial-success",`${o}`,`${f}`)}),!1):(t.show({type:p.MessageType.Success,content:i.t("find-replace.replace.all-success",`${o}`)}),!0)}};function ie(n){const{findCompleted:e,localeService:i,matchesCount:t,matchesPosition:a,findString:r,findReplaceService:o,onChange:f,..._}=n,S=e&&t===0?i.t("find-replace.dialog.no-result"):t===0?" ":void 0;return u.jsx(p.InputWithSlot,{autoFocus:!0,placeholder:i.t("find-replace.dialog.find-placeholder"),slot:u.jsx(p.Pager,{loop:!0,text:S,value:a,total:t,onChange:v=>{a===t&&v===1?o.moveToNextMatch():a===1&&v===t||v<a?o.moveToPreviousMatch():o.moveToNextMatch()}}),value:r,onChange:v=>f==null?void 0:f(v),..._})}const E={findReplaceDialogContainer:"univer-find-replace-dialog-container",findReplaceExpandContainer:"univer-find-replace-expand-container",buttonText:"univer-button-text",findReplaceButtonsGroup:"univer-find-replace-buttons-group",findReplaceButtonsGroupRight:"univer-find-replace-buttons-group-right"};function ae(n,e){const i=d.useCallback(()=>{var a;(a=document.querySelector(".univer-find-input input"))==null||a.focus()},[]),t=d.useCallback(()=>{const a=document.querySelectorAll(".univer-find-replace-dialog-container .univer-select-selection-search-input");return Array.from(a).some(r=>r===document.activeElement)},[]);return d.useImperativeHandle(e,()=>({focus:i,selectHasFocus:t})),d.useEffect(()=>{const a=n.focusSignal$.subscribe(()=>i());return()=>a.unsubscribe()},[n,i]),{focus:i,selectHasFocus:t}}const De=d.forwardRef(function(e,i){const t=s.useDependency(s.LocaleService),a=s.useDependency(R),r=s.useDependency(s.ICommandService),o=l.useObservable(a.state$,void 0,!0),{findCompleted:f,findString:_,matchesCount:y,matchesPosition:S}=o,v=d.useCallback(()=>{r.executeCommand(x.id)},[r]),j=d.useCallback(b=>a.changeFindString(b),[a]);return ae(a,i),u.jsxs(d.Fragment,{children:[u.jsx(ie,{findCompleted:f,className:"univer-find-input",matchesCount:y,matchesPosition:S,findReplaceService:a,localeService:t,findString:_,onChange:j}),u.jsx("div",{className:E.findReplaceExpandContainer,children:u.jsx(p.Button,{type:"text",size:"small",onClick:v,children:t.t("find-replace.dialog.advanced-finding")})})]})}),Te=d.forwardRef(function(e,i){const t=s.useDependency(R),a=s.useDependency(s.LocaleService),r=s.useDependency(s.ICommandService),o=s.useDependency(l.IMessageService),f=l.useObservable(t.currentMatch$,void 0,!0),_=l.useObservable(t.replaceables$,void 0,!0),y=l.useObservable(t.state$,void 0,!0),{matchesCount:S,matchesPosition:v,findString:j,inputtingFindString:b,replaceString:Qe,caseSensitive:Xe,matchesTheWholeCell:qe,findDirection:et,findScope:tt,findBy:nt,findCompleted:z}=y,it=b.length===0,at=S===0||!(f!=null&&f.replaceable),st=_.length===0,rt=d.useCallback(g=>t.changeInputtingFindString(g),[t]),ot=d.useCallback(g=>t.changeReplaceString(g),[t]),{focus:ct}=ae(t,i),lt=d.useCallback(()=>{j===b?t.moveToNextMatch():(t.changeFindString(b),t.find())},[j,b,t]),dt=d.useCallback(()=>r.executeCommand(G.id),[r]),ht=d.useCallback(async()=>{await r.executeCommand(V.id),ct()},[r]),ut=d.useCallback(g=>{t.changeFindDirection(g)},[t]),ft=d.useCallback(g=>{t.changeFindScope(g)},[t]),pt=d.useCallback(g=>{t.changeFindBy(g)},[t]),_t=xe(a),gt=Pe(a),mt=Ee(a);return d.useEffect(()=>{const g=z&&S===0;let L=null;return g&&(L=o.show({content:a.t("find-replace.dialog.no-match"),type:p.MessageType.Warning,duration:5e3})),()=>L==null?void 0:L.dispose()},[z,S,o,a]),u.jsxs(d.Fragment,{children:[u.jsx(p.FormLayout,{label:a.t("find-replace.dialog.find"),children:u.jsx(ie,{findCompleted:z,className:"univer-find-input",matchesCount:S,matchesPosition:v,findReplaceService:t,localeService:a,findString:b,onChange:rt})}),u.jsx(p.FormLayout,{label:a.t("find-replace.dialog.replace"),children:u.jsx(p.Input,{placeholder:a.t("find-replace.dialog.replace-placeholder"),value:Qe,onChange:g=>ot(g)})}),u.jsx(p.FormLayout,{label:a.t("find-replace.dialog.find-direction.title"),children:u.jsx(p.Select,{value:et,options:gt,onChange:ut})}),u.jsx(p.FormDualColumnLayout,{children:u.jsxs(d.Fragment,{children:[u.jsx(p.FormLayout,{label:a.t("find-replace.dialog.find-scope.title"),children:u.jsx(p.Select,{value:tt,options:_t,onChange:ft})}),u.jsx(p.FormLayout,{label:a.t("find-replace.dialog.find-by.title"),children:u.jsx(p.Select,{value:nt,options:mt,onChange:pt})})]})}),u.jsx(p.FormDualColumnLayout,{children:u.jsxs(d.Fragment,{children:[u.jsx(p.FormLayout,{children:u.jsx(p.Checkbox,{checked:Xe,onChange:g=>{t.changeCaseSensitive(g)},children:a.t("find-replace.dialog.case-sensitive")})}),u.jsx(p.FormLayout,{children:u.jsx(p.Checkbox,{checked:qe,onChange:g=>{t.changeMatchesTheWholeCell(g)},children:a.t("find-replace.dialog.match-the-whole-cell")})})]})}),u.jsxs("div",{className:E.findReplaceButtonsGroup,children:[u.jsx(p.Button,{type:"primary",onClick:lt,disabled:it,children:a.t("find-replace.dialog.find")}),u.jsxs("span",{className:E.findReplaceButtonsGroupRight,children:[u.jsx(p.Button,{disabled:at,onClick:dt,children:a.t("find-replace.dialog.replace")}),u.jsx(p.Button,{disabled:st,onClick:ht,children:a.t("find-replace.dialog.replace-all")})]})]})]})});function Oe(){const n=s.useDependency(R),e=s.useDependency(l.ILayoutService),i=s.useDependency(s.IContextService),t=l.useObservable(n.state$,void 0,!0),a=d.useRef(null);d.useEffect(()=>{let _;return a.current&&(_=e.registerContainerElement(a.current)),()=>_==null?void 0:_.dispose()},[e]);const r=d.useRef(null),o=d.useCallback(_=>i.setContextValue(X,_),[i]),f=d.useCallback(_=>i.setContextValue(Q,_),[i]);return d.useEffect(()=>{var y;const _=m.fromEvent(document,"focusin").subscribe(S=>{var v;S.target&&((v=a.current)!=null&&v.contains(S.target))?o(!0):o(!1),!r.current||!r.current.selectHasFocus()?f(!0):f(!1)});return(y=r.current)==null||y.focus(),o(!0),f(!0),()=>{_.unsubscribe(),o(!1)}},[o,f]),u.jsx("div",{className:E.findReplaceDialogContainer,ref:a,children:t.replaceRevealed?u.jsx(Te,{ref:r}):u.jsx(De,{ref:r})})}function xe(n){const e=n.getCurrentLocale();return d.useMemo(()=>[{label:n.t("find-replace.dialog.find-scope.current-sheet"),value:O.SUBUNIT},{label:n.t("find-replace.dialog.find-scope.workbook"),value:O.UNIT}],[e])}function Pe(n){const e=n.getCurrentLocale();return d.useMemo(()=>[{label:n.t("find-replace.dialog.find-direction.row"),value:D.ROW},{label:n.t("find-replace.dialog.find-direction.column"),value:D.COLUMN}],[e])}function Ee(n){const e=n.getCurrentLocale();return d.useMemo(()=>[{label:n.t("find-replace.dialog.find-by.value"),value:T.VALUE},{label:n.t("find-replace.dialog.find-by.formula"),value:T.FORMULA}],[e])}function F(n){return n.getContextValue(X)}function Ne(n){return n.getContextValue(q)}function se(n){return n.getContextValue(Q)}const N="7_find-replace-shortcuts";function H(n){return n.getContextValue(s.FOCUSING_SHEET)}function K(n){return!n.getContextValue(s.EDITOR_ACTIVATED)}const je={id:I.id,description:"find-replace.shortcut.open-find-dialog",binding:l.KeyCode.F|l.MetaKeys.CTRL_COMMAND,group:N,preconditions(n){return!F(n)&&H(n)&&K(n)}},Le={id:I.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(n){return!F(n)&&H(n)&&K(n)}},Ae={id:x.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:N,preconditions(n){return H(n)&&K(n)&&(!F(n)||!Ne(n))}},Ue={id:k.id,description:"find-replace.shortcut.go-to-next-match",binding:l.KeyCode.ENTER,group:N,priority:1e3,preconditions(n){return se(n)&&F(n)}},we={id:W.id,description:"find-replace.shortcut.go-to-previous-match",binding:l.KeyCode.ENTER|l.MetaKeys.SHIFT,group:N,priority:1e3,preconditions(n){return se(n)&&F(n)}};function Be(n){const e=n.get(s.IContextService);return{id:I.id,icon:"SearchIcon",tooltip:"find-replace.toolbar",group:l.MenuGroup.TOOLBAR_OTHERS,type:l.MenuItemType.BUTTON,positions:[l.MenuPosition.TOOLBAR_START],hidden$:l.getMenuHiddenObservable(n,s.UniverInstanceType.UNIVER_SHEET),disabled$:m.combineLatest([e.subscribeContextValue$(s.EDITOR_ACTIVATED),e.subscribeContextValue$(s.FOCUSING_SHEET)]).pipe(m.map(([i,t])=>i||!t))}}var ke=Object.defineProperty,We=Object.getOwnPropertyDescriptor,Ge=(n,e,i,t)=>{for(var a=t>1?void 0:t?We(e,i):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(a=(t?o(e,i,a):o(a))||a);return t&&a&&ke(e,i,a),a},M=(n,e)=>(i,t)=>e(i,t,n);const Ve={},re="DESKTOP_FIND_REPLACE_DIALOG",oe=350,He=20,Ke=-90;c.FindReplaceController=class extends s.RxDisposable{constructor(e,i,t,a,r,o,f,_,y,S,v){super(),this._config=e,this._univerInstanceService=i,this._menuService=t,this._shortcutService=a,this._commandService=r,this._findReplaceService=o,this._dialogService=f,this._layoutService=_,this._localeService=y,this._componentManager=S,this._injector=v,this._initCommands(),this._initUI(),this._initShortcuts()}_initCommands(){[I,x,k,W,V,G].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initShortcuts(){[Ae,je,Le,we,Ue].forEach(e=>this.disposeWithMe(this._shortcutService.registerShortcut(e)))}_initUI(){const{menu:e={}}=this._config;this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(Be),e)),this.disposeWithMe(this._componentManager.register("FindReplaceDialog",Oe)),this.disposeWithMe(this._componentManager.register("SearchIcon",J)),this._findReplaceService.stateUpdates$.pipe(m.takeUntil(this.dispose$)).subscribe(i=>{i.revealed===!0&&this._openPanel()}),this.disposeWithMe(this._univerInstanceService.focused$.pipe(m.takeUntil(this.dispose$)).subscribe(i=>{(!i||!this._univerInstanceService.getUniverSheetInstance(i))&&this.closePanel()}))}_openPanel(){this._dialogService.open({id:re,draggable:!0,width:oe,title:{title:this._localeService.t("find-replace.dialog.title")},children:{label:"FindReplaceDialog"},destroyOnClose:!0,defaultPosition:$e(),preservePositionOnDestroy:!0,onClose:()=>this.closePanel()})}closePanel(){this._dialogService.close(re),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus())}},c.FindReplaceController=Ge([s.OnLifecycle(s.LifecycleStages.Rendered,c.FindReplaceController),M(1,s.IUniverInstanceService),M(2,l.IMenuService),M(3,l.IShortcutService),M(4,s.ICommandService),M(5,R),M(6,l.IDialogService),M(7,l.ILayoutService),M(8,s.Inject(s.LocaleService)),M(9,s.Inject(l.ComponentManager)),M(10,s.Inject(s.Injector))],c.FindReplaceController);function $e(){const{innerWidth:n}=window;return{x:(n-oe)/2-He,y:Ke}}var ze=Object.defineProperty,Ye=Object.getOwnPropertyDescriptor,Ze=(n,e,i,t)=>{for(var a=t>1?void 0:t?Ye(e,i):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(a=(t?o(e,i,a):o(a))||a);return t&&a&&ze(e,i,a),a},ce=(n,e)=>(i,t)=>e(i,t,n);const Je="FIND_REPLACE_PLUGIN";c.UniverFindReplacePlugin=($=class extends s.Plugin{constructor(e={},i,t){super(),this._config=e,this._injector=i,this._localeService=t,this._config=s.Tools.deepMerge({},Ve,this._config)}onStarting(e){[[c.FindReplaceController,{useFactory:()=>this._injector.createInstance(c.FindReplaceController,this._config)}],[R,{useClass:B}]].forEach(i=>{e.add(i)})}},h($,"pluginName",Je),$),c.UniverFindReplacePlugin=Ze([ce(1,s.Inject(s.Injector)),ce(2,s.Inject(s.LocaleService))],c.UniverFindReplacePlugin),c.FindBy=T,c.FindDirection=D,c.FindModel=me,c.FindScope=O,c.GoToNextMatchOperation=k,c.GoToPreviousMatchOperation=W,c.IFindReplaceService=R,c.OpenFindDialogOperation=I,c.OpenReplaceDialogOperation=x,c.ReplaceAllMatchesCommand=V,c.ReplaceCurrentMatchCommand=G,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/find-replace",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -50,32 +50,30 @@
|
|
|
50
50
|
"lib"
|
|
51
51
|
],
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"@wendellhu/redi": "0.16.0",
|
|
54
53
|
"react": "^16.9.0 || ^17.0.0 || ^18.0.0",
|
|
55
54
|
"rxjs": ">=7.0.0",
|
|
56
|
-
"@univerjs/core": "0.2.
|
|
57
|
-
"@univerjs/
|
|
58
|
-
"@univerjs/
|
|
59
|
-
"@univerjs/ui": "0.2.
|
|
55
|
+
"@univerjs/core": "0.2.5",
|
|
56
|
+
"@univerjs/design": "0.2.5",
|
|
57
|
+
"@univerjs/engine-render": "0.2.5",
|
|
58
|
+
"@univerjs/ui": "0.2.5"
|
|
60
59
|
},
|
|
61
60
|
"dependencies": {
|
|
62
61
|
"@univerjs/icons": "^0.1.65"
|
|
63
62
|
},
|
|
64
63
|
"devDependencies": {
|
|
65
64
|
"@types/react": "^18.3.3",
|
|
66
|
-
"@wendellhu/redi": "0.16.0",
|
|
67
65
|
"less": "^4.2.0",
|
|
68
66
|
"react": "18.3.1",
|
|
69
67
|
"rxjs": "^7.8.1",
|
|
70
68
|
"typescript": "^5.5.3",
|
|
71
69
|
"vite": "^5.3.4",
|
|
72
70
|
"vitest": "^2.0.3",
|
|
73
|
-
"@univerjs/core": "0.2.
|
|
74
|
-
"@univerjs/design": "0.2.
|
|
75
|
-
"@univerjs/engine-formula": "0.2.
|
|
76
|
-
"@univerjs/engine-render": "0.2.
|
|
77
|
-
"@univerjs/
|
|
78
|
-
"@univerjs/
|
|
71
|
+
"@univerjs/core": "0.2.5",
|
|
72
|
+
"@univerjs/design": "0.2.5",
|
|
73
|
+
"@univerjs/engine-formula": "0.2.5",
|
|
74
|
+
"@univerjs/engine-render": "0.2.5",
|
|
75
|
+
"@univerjs/ui": "0.2.5",
|
|
76
|
+
"@univerjs/shared": "0.2.5"
|
|
79
77
|
},
|
|
80
78
|
"univerSpace": {
|
|
81
79
|
".": {
|