@univerjs/find-replace 0.5.3 → 0.5.4
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 +110 -108
- package/lib/types/index.d.ts +2 -2
- package/lib/types/services/find-replace.service.d.ts +8 -4
- package/lib/umd/index.js +2 -2
- package/package.json +9 -8
package/lib/cjs/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var Te=Object.defineProperty;var Pe=(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)=>Pe(i,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),p=require("@univerjs/ui"),v=require("rxjs"),f=require("@univerjs/design"),Ee=require("@univerjs/engine-render"),h=require("react"),Ne="find-replace.config",q={};var C=function(){return C=Object.assign||function(i){for(var e,n=1,t=arguments.length;n<t;n++){e=arguments[n];for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&(i[s]=e[s])}return i},C.apply(this,arguments)},Le=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 s=0,t=Object.getOwnPropertySymbols(i);s<t.length;s++)e.indexOf(t[s])<0&&Object.prototype.propertyIsEnumerable.call(i,t[s])&&(n[t[s]]=i[t[s]]);return n},Q=h.forwardRef(function(i,e){var n=i.icon,t=i.id,s=i.className,r=i.extend,a=Le(i,["icon","id","className","extend"]),d="univerjs-icon univerjs-icon-".concat(t," ").concat(s||"").trim(),u=h.useRef("_".concat(Ae()));return X(n,"".concat(t),{defIds:n.defIds,idSuffix:u.current},C({ref:e,className:d},a),r)});function X(i,e,n,t,s){return h.createElement(i.tag,C(C({key:e},$e(i,n,s)),t),(je(i,n).children||[]).map(function(r,a){return X(r,"".concat(e,"-").concat(i.tag,"-").concat(a),n,void 0,s)}))}function $e(i,e,n){var t=C({},i.attrs);n!=null&&n.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=n.colorChannel1);var s=e.defIds;return!s||s.length===0||(i.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+e.idSuffix),Object.entries(t).forEach(function(r){var a=r[0],d=r[1];typeof d=="string"&&(t[a]=d.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)?C(C({},i),{children:i.children.map(function(s){return typeof s.attrs.id=="string"&&t&&t.indexOf(s.attrs.id)>-1?C(C({},s),{attrs:C(C({},s.attrs),{id:s.attrs.id+e.idSuffix})}):s})}):i}function Ae(){return Math.random().toString(36).substring(2,8)}Q.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"}}]}]},ee=h.forwardRef(function(i,e){return h.createElement(Q,Object.assign({},i,{id:"search-single-16",ref:e,icon:we}))});ee.displayName="SearchSingle16";const te="FIND_REPLACE_INPUT_FOCUS",ie="FIND_REPLACE_DIALOG_FOCUS",ne="FIND_REPLACE_REPLACE_REVEALED";var Ue=Object.defineProperty,Be=Object.getOwnPropertyDescriptor,se=(i,e,n,t)=>{for(var s=t>1?void 0:t?Be(e,n):e,r=i.length-1,a;r>=0;r--)(a=i[r])&&(s=(t?a(e,n,s):a(s))||s);return t&&s&&Ue(e,n,s),s},A=(i,e)=>(n,t)=>e(n,t,i);class ke extends o.Disposable{}const R=o.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 w=class extends o.Disposable{constructor(e,n,t){super();l(this,"currentMatch$",new v.BehaviorSubject(null));l(this,"replaceables$",new v.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(v.throttleTime(200,void 0,{leading:!0,trailing:!0})).subscribe(async s=>{const r=this._state.state;We(s)&&(r.findString!==""&&!r.replaceRevealed?(await this._startSearching(),this._state.changeState({findCompleted:!0})):s.replaceRevealed!==!0&&this._stopSearching())}))}get searched(){return this._findModels.length>0}dispose(){super.dispose(),this._stopSearching(),this.currentMatch$.complete(),this.replaceables$.complete(),this._state.changeState({...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(s=>s.find({findString:this._state.findString,findDirection:this._state.findDirection,findScope:this._state.findScope,findBy:this._state.findBy,replaceRevealed:this._state.replaceRevealed,caseSensitive:this._state.caseSensitive,matchesTheWholeCell:this._state.matchesTheWholeCell})))).flat();this._subscribeToModelsChanges(n);const t=this._matches=n.map(s=>s.getMatches()).flat();return this.replaceables$.next(t.filter(s=>s.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=v.combineLatest(e.map(s=>s.matchesUpdate$)).pipe(v.debounceTime(220)).subscribe(([...s])=>{const r=this._matches=s.flat();r.length?(this._moveToInitialMatch(this._findModels,!0),this._state.changeState({matchesCount:r.length}),this.replaceables$.next(r.filter(a=>a.replaceable))):(this._state.changeState({matchesCount:0,matchesPosition:0}),this.replaceables$.next([]))});e.forEach(s=>n.add(o.toDisposable(s.activelyChangingMatch$.subscribe(r=>{const a=this._matches.findIndex(d=>d===r);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,s)=>(t.success+=s.success,t.failure+=s.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(s=>s===this._matchingModel);this._moveToNextUnitMatch(t)}}_moveToNextUnitMatch(e){const n=this._findModels.length;for(let t=(e+1)%n;t!==e;){const s=this._findModels[t],r=s.moveToNextMatch({ignoreSelection:!0});if(r){this._matchingModel=s,this._markMatch(r);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(s=>s===n);this.currentMatch$.next(n),this._state.changeState({matchesPosition:t+1})}else{const t=this._findModels.length,s=this._findModels.findIndex(a=>a===this._matchingModel);for(let a=(s-1+t)%t;a!==s;){const d=this._findModels[a],u=d.moveToPreviousMatch({ignoreSelection:!0});if(u){this._matchingModel=d,this._markMatch(u);return}a=(a-1)%t}const r=this._matchingModel.moveToPreviousMatch({ignoreSelection:!0});r&&this._markMatch(r)}}_moveToInitialMatch(e,n=!1){var r;const t=(r=this._univerInstanceService.getFocusedUnit())==null?void 0:r.getUnitId();if(!t)return-1;const s=e.findIndex(a=>a.unitId===t);if(s!==-1){this._matchingModel=e[s];const a=this._matchingModel.moveToNextMatch({stayIfOnMatch:!0,noFocus:n});if(a)return this._markMatch(a),s}return this._moveToNextUnitMatch(s),0}};w=se([A(2,o.IUniverInstanceService)],w);var D=(i=>(i.ROW="row",i.COLUMN="column",i))(D||{}),O=(i=>(i.VALUE="value",i.FORMULA="formula",i))(O||{}),T=(i=>(i.SUBUNIT="subunit",i.UNIT="unit",i))(T||{});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 Ge{constructor(){l(this,"_stateUpdates$",new v.Subject);l(this,"stateUpdates$",this._stateUpdates$.asObservable());l(this,"_state$",new v.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 Ge);l(this,"_model");l(this,"_currentMatch$",new v.BehaviorSubject(null));l(this,"currentMatch$",this._currentMatch$.asObservable());l(this,"_replaceables$",new v.BehaviorSubject([]));l(this,"replaceables$",this._replaceables$.asObservable());l(this,"_focusSignal$",new v.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(ne,e)}_toggleDisplayRawFormula(e){this._contextService.setContextValue(Ee.RENDER_RAW_FORMULA_KEY,e)}};U=se([A(0,o.Inject(o.Injector)),A(1,o.IContextService)],U);const k={id:"ui.command.replace-current-match",type:o.CommandType.COMMAND,handler:i=>i.get(R).replace()},Ve="CONFIRM_REPLACE_ALL",W={id:"ui.command.replace-all-matches",type:o.CommandType.COMMAND,handler:async i=>{const e=i.get(p.IConfirmService),n=i.get(o.LocaleService),t=i.get(p.IMessageService);if(!await e.confirm({id:Ve,title:{title:n.t("find-replace.replace.confirm.title")},cancelText:n.t("button.cancel"),confirmText:n.t("button.confirm")}))return!1;const r=await i.get(R).replaceAll(),{success:a,failure:d}=r;return d>0?(a===0?t.show({type:f.MessageType.Error,content:n.t("find-replace.replace.all-failure")}):t.show({type:f.MessageType.Warning,content:n.t("find-replace.replace.partial-success",`${a}`,`${d}`)}),!1):(t.show({type:f.MessageType.Success,content:n.t("find-replace.replace.all-success",`${a}`)}),!0)}},I={id:"ui.operation.open-find-dialog",type:o.CommandType.OPERATION,handler:i=>{const e=i.get(R);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(R);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:i=>(i.get(R).moveToNextMatch(),!0)},V={type:o.CommandType.OPERATION,id:"ui.operation.go-to-previous-match",handler:i=>(i.get(R).moveToPreviousMatch(),!0)};var $={exports:{}},x={};/**
|
|
1
|
+
"use strict";var Te=Object.defineProperty;var Pe=(t,e,i)=>e in t?Te(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i;var u=(t,e,i)=>Pe(t,typeof e!="symbol"?e+"":e,i);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),p=require("@univerjs/ui"),S=require("rxjs"),f=require("@univerjs/design"),Ee=require("@univerjs/engine-render"),h=require("react"),Ne="find-replace.config",K={};var C=function(){return C=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++){e=arguments[i];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])}return t},C.apply(this,arguments)},Le=function(t,e){var i={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(i[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,n=Object.getOwnPropertySymbols(t);r<n.length;r++)e.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(t,n[r])&&(i[n[r]]=t[n[r]]);return i},Z=h.forwardRef(function(t,e){var i=t.icon,n=t.id,r=t.className,s=t.extend,a=Le(t,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(n," ").concat(r||"").trim(),d=h.useRef("_".concat(Ae()));return Q(i,"".concat(n),{defIds:i.defIds,idSuffix:d.current},C({ref:e,className:c},a),s)});function Q(t,e,i,n,r){return h.createElement(t.tag,C(C({key:e},$e(t,i,r)),n),(je(t,i).children||[]).map(function(s,a){return Q(s,"".concat(e,"-").concat(t.tag,"-").concat(a),i,void 0,r)}))}function $e(t,e,i){var n=C({},t.attrs);i!=null&&i.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=i.colorChannel1);var r=e.defIds;return!r||r.length===0||(t.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+e.idSuffix),Object.entries(n).forEach(function(s){var a=s[0],c=s[1];typeof c=="string"&&(n[a]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),n}function je(t,e){var i,n=e.defIds;return!n||n.length===0?t:t.tag==="defs"&&(!((i=t.children)===null||i===void 0)&&i.length)?C(C({},t),{children:t.children.map(function(r){return typeof r.attrs.id=="string"&&n&&n.indexOf(r.attrs.id)>-1?C(C({},r),{attrs:C(C({},r.attrs),{id:r.attrs.id+e.idSuffix})}):r})}):t}function Ae(){return Math.random().toString(36).substring(2,8)}Z.displayName="UniverIcon";var we={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_217_40",style:{maskType:"alpha"},width:17,height:17,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#D9D9D9",d:"M0.9 0.09H16.9V16.09H0.9z"}}]},{tag:"g",attrs:{mask:"url(#mask0_217_40)"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.39551 7.37266C2.39551 4.18105 4.98281 1.59375 8.17441 1.59375C11.366 1.59375 13.9533 4.18105 13.9533 7.37266C13.9533 8.72342 13.4898 9.96603 12.7133 10.95L15.1964 13.4331C15.4619 13.6986 15.4619 14.1291 15.1964 14.3946C14.9309 14.6601 14.5004 14.6601 14.2349 14.3946L11.7518 11.9115C10.7678 12.6881 9.52525 13.1516 8.17441 13.1516C4.98281 13.1516 2.39551 10.5642 2.39551 7.37266ZM8.17441 2.95349C5.73378 2.95349 3.75525 4.93202 3.75525 7.37266C3.75525 9.81333 5.73378 11.7918 8.17441 11.7918C10.6151 11.7918 12.5936 9.81333 12.5936 7.37266C12.5936 4.93202 10.6151 2.95349 8.17441 2.95349Z",fillRule:"evenodd",clipRule:"evenodd"}}]}]},X=h.forwardRef(function(t,e){return h.createElement(Z,Object.assign({},t,{id:"search-single-16",ref:e,icon:we}))});X.displayName="SearchSingle16";const ee="FIND_REPLACE_INPUT_FOCUS",te="FIND_REPLACE_DIALOG_FOCUS",ne="FIND_REPLACE_REPLACE_REVEALED";var Ue=Object.defineProperty,Be=Object.getOwnPropertyDescriptor,ie=(t,e,i,n)=>{for(var r=n>1?void 0:n?Be(e,i):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(r=(n?a(e,i,r):a(r))||r);return n&&r&&Ue(e,i,r),r},w=(t,e)=>(i,n)=>e(i,n,t);class ke extends o.Disposable{}const R=o.createIdentifier("find-replace.service");function We(t){return typeof t.findString<"u"||typeof t.inputtingFindString<"u"||typeof t.findDirection<"u"||typeof t.matchesTheWholeCell<"u"||typeof t.caseSensitive<"u"||typeof t.findScope<"u"||typeof t.findBy<"u"}exports.FindReplaceModel=class extends o.Disposable{constructor(i,n,r){super();u(this,"currentMatch$",new S.BehaviorSubject(null));u(this,"replaceables$",new S.BehaviorSubject([]));u(this,"_findModels",[]);u(this,"_matchingModel",null);u(this,"_matches",[]);u(this,"_currentSearchingDisposables",null);this._state=i,this._providers=n,this._univerInstanceService=r,this.disposeWithMe(this._state.stateUpdates$.pipe(S.throttleTime(200,void 0,{leading:!0,trailing:!0})).subscribe(async s=>{const a=this._state.state;We(s)&&(a.findString!==""&&!a.replaceRevealed?(await this._startSearching(),this._state.changeState({findCompleted:!0})):s.replaceRevealed!==!0&&this._stopSearching())}))}get searched(){return this._findModels.length>0}dispose(){super.dispose(),this._stopSearching(),this.currentMatch$.complete(),this.replaceables$.complete(),this._state.changeState({...E(),revealed:!1})}async start(){if(!this._state.findString)return{results:[]};const i=await this._startSearching();return this._state.changeState({findCompleted:!0}),i}async _startSearching(){if(!this._state.findString)return{results:[]};const i=Array.from(this._providers),n=this._findModels=(await Promise.all(i.map(s=>s.find({findString:this._state.findString,findDirection:this._state.findDirection,findScope:this._state.findScope,findBy:this._state.findBy,replaceRevealed:this._state.replaceRevealed,caseSensitive:this._state.caseSensitive,matchesTheWholeCell:this._state.matchesTheWholeCell})))).flat();this._subscribeToModelsChanges(n);const r=this._matches=n.map(s=>s.getMatches()).flat();return this.replaceables$.next(r.filter(s=>s.replaceable)),r.length?(this._moveToInitialMatch(n),this._state.changeState({matchesCount:r.length}),{results:r}):(this._state.changeState({matchesCount:0,matchesPosition:0}),{results:[]})}_stopSearching(){var i;this._providers.forEach(n=>n.terminate()),this._findModels=[],this._matches=[],this._matchingModel=null,(i=this._currentSearchingDisposables)==null||i.dispose(),this._currentSearchingDisposables=null,this.currentMatch$.next(null),this.replaceables$.next([]),this._state.changeState({findCompleted:!1,matchesCount:0,matchesPosition:0})}_subscribeToModelsChanges(i){const n=this._currentSearchingDisposables=new o.DisposableCollection,r=S.combineLatest(i.map(s=>s.matchesUpdate$)).pipe(S.debounceTime(220)).subscribe(([...s])=>{const a=this._matches=s.flat();a.length?(this._moveToInitialMatch(this._findModels,!0),this._state.changeState({matchesCount:a.length}),this.replaceables$.next(a.filter(c=>c.replaceable))):(this._state.changeState({matchesCount:0,matchesPosition:0}),this.replaceables$.next([]))});i.forEach(s=>n.add(o.toDisposable(s.activelyChangingMatch$.subscribe(a=>{const c=this._matches.findIndex(d=>d===a);this._state.changeState({matchesPosition:c+1})})))),n.add(o.toDisposable(r))}async replace(){return this._matchingModel?this._matchingModel.replace(this._state.replaceString):!1}async replaceAll(){const i=await Promise.all(this._findModels.map(n=>n.replaceAll(this._state.replaceString))).then(n=>n.reduce((r,s)=>(r.success+=s.success,r.failure+=s.failure,r),{success:0,failure:0}));return i.failure===0&&this._stopSearching(),i}getCurrentMatch(){return this._state.matchesPosition>0?this._matches[this._state.matchesPosition-1]:null}_markMatch(i){const n=this._matches.findIndex(r=>r===i);this.currentMatch$.next(i),this._state.changeState({matchesPosition:n+1})}moveToNextMatch(){if(!this._matchingModel)return;const i=this._findModels.length===1,n=this._matchingModel.moveToNextMatch({loop:i});if(n)return this._markMatch(n),n;{const r=this._findModels.findIndex(s=>s===this._matchingModel);return this._moveToNextUnitMatch(r)}}_moveToNextUnitMatch(i){const n=this._findModels.length;for(let r=(i+1)%n;r!==i;){const s=this._findModels[r],a=s.moveToNextMatch({ignoreSelection:!0});if(a)return this._matchingModel=s,this._markMatch(a),a;r=(r+1)%n}if(this._matchingModel){const r=this._matchingModel.moveToNextMatch({ignoreSelection:!0});return r&&this._markMatch(r),r}}moveToPreviousMatch(){if(!this._matchingModel)return;const i=this._findModels.length===1,n=this._matchingModel.moveToPreviousMatch({loop:i});if(n){const r=this._matches.findIndex(s=>s===n);return this.currentMatch$.next(n),this._state.changeState({matchesPosition:r+1}),n}else{const r=this._findModels.length,s=this._findModels.findIndex(c=>c===this._matchingModel);for(let c=(s-1+r)%r;c!==s;){const d=this._findModels[c],m=d.moveToPreviousMatch({ignoreSelection:!0});if(m)return this._matchingModel=d,this._markMatch(m),m;c=(c-1)%r}const a=this._matchingModel.moveToPreviousMatch({ignoreSelection:!0});return a&&this._markMatch(a),a}}_moveToInitialMatch(i,n=!1){var a;const r=(a=this._univerInstanceService.getFocusedUnit())==null?void 0:a.getUnitId();if(!r)return-1;const s=i.findIndex(c=>c.unitId===r);if(s!==-1){this._matchingModel=i[s];const c=this._matchingModel.moveToNextMatch({stayIfOnMatch:!0,noFocus:n});if(c)return this._markMatch(c),s}return this._moveToNextUnitMatch(s),0}};exports.FindReplaceModel=ie([w(2,o.IUniverInstanceService)],exports.FindReplaceModel);var D=(t=>(t.ROW="row",t.COLUMN="column",t))(D||{}),O=(t=>(t.VALUE="value",t.FORMULA="formula",t))(O||{}),T=(t=>(t.SUBUNIT="subunit",t.UNIT="unit",t))(T||{});function E(){return{caseSensitive:!1,findBy:"value",findCompleted:!1,findDirection:"row",findScope:"subunit",findString:"",inputtingFindString:"",matchesCount:0,matchesPosition:0,matchesTheWholeCell:!1,replaceRevealed:!1,replaceString:"",revealed:!0}}class re{constructor(){u(this,"_stateUpdates$",new S.Subject);u(this,"stateUpdates$",this._stateUpdates$.asObservable());u(this,"_state$",new S.BehaviorSubject(E()));u(this,"state$",this._state$.asObservable());u(this,"_findString","");u(this,"_inputtingFindString","");u(this,"_replaceString","");u(this,"_revealed",!1);u(this,"_replaceRevealed",!1);u(this,"_matchesPosition",0);u(this,"_matchesCount",0);u(this,"_caseSensitive",!0);u(this,"_matchesTheWholeCell",!1);u(this,"_findDirection","row");u(this,"_findScope","subunit");u(this,"_findBy","value");u(this,"_findCompleted",!1)}get state(){return this._state$.getValue()}get inputtingFindString(){return this._inputtingFindString}get findString(){return this._findString}get revealed(){return this._revealed}get replaceRevealed(){return this._replaceRevealed}get matchesPosition(){return this._matchesPosition}get matchesCount(){return this._matchesCount}get replaceString(){return this._replaceString}get caseSensitive(){return this._caseSensitive}get matchesTheWholeCell(){return this._matchesTheWholeCell}get findDirection(){return this._findDirection}get findScope(){return this._findScope}get findBy(){return this._findBy}get findCompleted(){return this._findCompleted}changeState(e){let i=!1;const n={};typeof e.findString<"u"&&e.findString!==this._findString&&(this._findString=e.findString,n.findString=this._findString,i=!0),typeof e.revealed<"u"&&e.revealed!==this._revealed&&(this._revealed=e.revealed,n.revealed=e.revealed,i=!0),typeof e.replaceRevealed<"u"&&e.replaceRevealed!==this._replaceRevealed&&(this._replaceRevealed=e.replaceRevealed,n.replaceRevealed=e.replaceRevealed,i=!0),typeof e.replaceString<"u"&&e.replaceString!==this._replaceString&&(this._replaceString=e.replaceString,n.replaceString=e.replaceString,i=!0),typeof e.matchesCount<"u"&&e.matchesCount!==this._matchesCount&&(this._matchesCount=e.matchesCount,n.matchesCount=e.matchesCount,i=!0),typeof e.matchesPosition<"u"&&e.matchesPosition!==this._matchesPosition&&(this._matchesPosition=e.matchesPosition,n.matchesPosition=e.matchesPosition,i=!0),typeof e.findBy<"u"&&e.findBy!==this._findBy&&(this._findBy=e.findBy,n.findBy=e.findBy,i=!0),typeof e.findScope<"u"&&e.findScope!==this._findScope&&(this._findScope=e.findScope,n.findScope=e.findScope,i=!0),typeof e.findDirection<"u"&&e.findDirection!==this._findDirection&&(this._findDirection=e.findDirection,n.findDirection=e.findDirection,i=!0),typeof e.caseSensitive<"u"&&e.caseSensitive!==this._caseSensitive&&(this._caseSensitive=e.caseSensitive,n.caseSensitive=e.caseSensitive,i=!0),typeof e.matchesTheWholeCell<"u"&&e.matchesTheWholeCell!==this._matchesTheWholeCell&&(this._matchesTheWholeCell=e.matchesTheWholeCell,n.matchesTheWholeCell=e.matchesTheWholeCell,i=!0),typeof e.inputtingFindString<"u"&&e.inputtingFindString!==this._inputtingFindString&&(this._inputtingFindString=e.inputtingFindString,n.inputtingFindString=e.inputtingFindString,i=!0),typeof e.findCompleted<"u"&&e.findCompleted!==this._findCompleted&&(this._findCompleted=e.findCompleted,n.findCompleted=e.findCompleted,i=!0),i&&(this._state$.next({caseSensitive:this._caseSensitive,findBy:this._findBy,findCompleted:this._findCompleted,findDirection:this._findDirection,findScope:this._findScope,findString:this._findString,inputtingFindString:this._inputtingFindString,matchesCount:this._matchesCount,matchesPosition:this._matchesPosition,matchesTheWholeCell:this._matchesTheWholeCell,replaceRevealed:this._replaceRevealed,revealed:this._revealed}),this._stateUpdates$.next(n))}}let U=class extends o.Disposable{constructor(e,i){super();u(this,"_providers",new Set);u(this,"_state",new re);u(this,"_model");u(this,"_currentMatch$",new S.BehaviorSubject(null));u(this,"currentMatch$",this._currentMatch$.asObservable());u(this,"_replaceables$",new S.BehaviorSubject([]));u(this,"replaceables$",this._replaceables$.asObservable());u(this,"_focusSignal$",new S.Subject);u(this,"focusSignal$",this._focusSignal$.asObservable());this._injector=e,this._contextService=i}get stateUpdates$(){return this._state.stateUpdates$}get state$(){return this._state.state$}get revealed(){return this._state.revealed}get replaceRevealed(){return this._state.replaceRevealed}dispose(){super.dispose(),this._currentMatch$.next(null),this._currentMatch$.complete(),this._replaceables$.next([]),this._replaceables$.complete(),this._focusSignal$.complete()}getProviders(){return this._providers}getCurrentMatch(){var e;return(e=this._model)==null?void 0:e.getCurrentMatch()}getFindString(){return this._state.findString}changeFindString(e){this._state.changeState({findString:e})}focusFindInput(){this._focusSignal$.next()}changeInputtingFindString(e){e?this._state.changeState({inputtingFindString:e}):this._state.changeState({inputtingFindString:"",findString:""})}changeReplaceString(e){this._state.changeState({replaceString:e})}changeMatchesTheWholeCell(e){this._state.changeState({matchesTheWholeCell:e})}changeCaseSensitive(e){this._state.changeState({caseSensitive:e})}changeFindBy(e){this._state.changeState({findBy:e}),this._toggleDisplayRawFormula(e==="formula")}changeFindScope(e){this._state.changeState({findScope:e})}changeFindDirection(e){this._state.changeState({findDirection:e})}moveToNextMatch(){this._model&&(this._state.replaceRevealed&&!this._model.searched?(this._state.changeState({findString:this._state.inputtingFindString}),this._model.start()):this._model.moveToNextMatch(),this._focusSignal$.next())}moveToPreviousMatch(){this._model&&(this._state.replaceRevealed&&!this._model.searched?(this._state.changeState({findString:this._state.inputtingFindString}),this._model.start()):this._model.moveToPreviousMatch(),this._focusSignal$.next())}async replace(){return this._model?this._model.replace():!1}async replaceAll(){if(!this._model)throw new Error("[FindReplaceService] replaceAll: model is not initialized!");return this._model.replaceAll()}revealReplace(){this._state.changeState({replaceRevealed:!0,inputtingFindString:this._state.findString}),this._toggleRevealReplace(!0)}start(e=!1){if(this._providers.size===0)return!1;this._model=this._injector.createInstance(exports.FindReplaceModel,this._state,this._providers),this._model.currentMatch$.subscribe(n=>this._currentMatch$.next(n)),this._model.replaceables$.subscribe(n=>this._replaceables$.next(n));const i=E();return e&&(i.replaceRevealed=!0),this._state.changeState(i),this._toggleRevealReplace(e),!0}find(){var e;(e=this._model)==null||e.start()}terminate(){var e;(e=this._model)==null||e.dispose(),this._model=null,this._toggleDisplayRawFormula(!1),this._toggleRevealReplace(!1)}registerFindReplaceProvider(e){return this._providers.add(e),o.toDisposable(()=>this._providers.delete(e))}_toggleRevealReplace(e){this._contextService.setContextValue(ne,e)}_toggleDisplayRawFormula(e){this._contextService.setContextValue(Ee.RENDER_RAW_FORMULA_KEY,e)}};U=ie([w(0,o.Inject(o.Injector)),w(1,o.IContextService)],U);const B={id:"ui.command.replace-current-match",type:o.CommandType.COMMAND,handler:t=>t.get(R).replace()},Ge="CONFIRM_REPLACE_ALL",k={id:"ui.command.replace-all-matches",type:o.CommandType.COMMAND,handler:async t=>{const e=t.get(p.IConfirmService),i=t.get(o.LocaleService),n=t.get(p.IMessageService);if(!await e.confirm({id:Ge,title:{title:i.t("find-replace.replace.confirm.title")},cancelText:i.t("button.cancel"),confirmText:i.t("button.confirm")}))return!1;const s=await t.get(R).replaceAll(),{success:a,failure:c}=s;return c>0?(a===0?n.show({type:f.MessageType.Error,content:i.t("find-replace.replace.all-failure")}):n.show({type:f.MessageType.Warning,content:i.t("find-replace.replace.partial-success",`${a}`,`${c}`)}),!1):(n.show({type:f.MessageType.Success,content:i.t("find-replace.replace.all-success",`${a}`)}),!0)}},I={id:"ui.operation.open-find-dialog",type:o.CommandType.OPERATION,handler:t=>{const e=t.get(R);return e.revealed?e.focusFindInput():e.start(),!0}},N={id:"ui.operation.open-replace-dialog",type:o.CommandType.OPERATION,handler:t=>{const e=t.get(R);return e.revealed?e.replaceRevealed?e.focusFindInput():e.revealReplace():e.start(!0),!0}},W={type:o.CommandType.OPERATION,id:"ui.operation.go-to-next-match",handler:t=>(t.get(R).moveToNextMatch(),!0)},G={type:o.CommandType.OPERATION,id:"ui.operation.go-to-previous-match",handler:t=>(t.get(R).moveToPreviousMatch(),!0)};var j={exports:{}},x={};/**
|
|
2
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 J;function He(){if(J)return x;J=1;var i=h,e=Symbol.for("react.element"),n=Symbol.for("react.fragment"),t=Object.prototype.hasOwnProperty,s=i.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,r={key:!0,ref:!0,__self:!0,__source:!0};function a(d,u,S){var _,g={},y=null,b=null;S!==void 0&&(y=""+S),u.key!==void 0&&(y=""+u.key),u.ref!==void 0&&(b=u.ref);for(_ in u)t.call(u,_)&&!r.hasOwnProperty(_)&&(g[_]=u[_]);if(d&&d.defaultProps)for(_ in u=d.defaultProps,u)g[_]===void 0&&(g[_]=u[_]);return{$$typeof:e,type:d,key:y,ref:b,props:g,_owner:s.current}}return x.Fragment=n,x.jsx=a,x.jsxs=a,x}var z;function Ke(){return z||(z=1,$.exports=He()),$.exports}var c=Ke();const qe="univer-find-replace-dialog-container",Je="univer-find-replace-expand-container",ze="univer-button-text",Ye="univer-find-replace-buttons-group",Ze="univer-find-replace-buttons-group-right",P={findReplaceDialogContainer:qe,findReplaceExpandContainer:Je,buttonText:ze,findReplaceButtonsGroup:Ye,findReplaceButtonsGroupRight:Ze};function re(i){const{findCompleted:e,localeService:n,matchesCount:t,matchesPosition:s,findString:r,findReplaceService:a,onChange:d,...u}=i,_=e&&t===0?n.t("find-replace.dialog.no-result"):t===0?" ":void 0;return c.jsx(f.InputWithSlot,{autoFocus:!0,placeholder:n.t("find-replace.dialog.find-placeholder"),slot:c.jsx(f.Pager,{loop:!0,text:_,value:s,total:t,onChange:g=>{s===t&&g===1?a.moveToNextMatch():s===1&&g===t||g<s?a.moveToPreviousMatch():a.moveToNextMatch()}}),value:r,onChange:g=>d==null?void 0:d(g),...u})}function ae(i,e){const n=h.useCallback(()=>{var s;(s=document.querySelector(".univer-find-input input"))==null||s.focus()},[]),t=h.useCallback(()=>{const s=document.querySelectorAll(".univer-find-replace-dialog-container .univer-select-selection-search-input");return Array.from(s).some(r=>r===document.activeElement)},[]);return h.useImperativeHandle(e,()=>({focus:n,selectHasFocus:t})),h.useEffect(()=>{const s=i.focusSignal$.subscribe(()=>n());return()=>s.unsubscribe()},[i,n]),{focus:n,selectHasFocus:t}}const Qe=h.forwardRef(function(e,n){const t=o.useDependency(o.LocaleService),s=o.useDependency(R),r=o.useDependency(o.ICommandService),a=p.useObservable(s.state$,void 0,!0),{findCompleted:d,findString:u,matchesCount:S,matchesPosition:_}=a,g=h.useCallback(()=>{r.executeCommand(E.id)},[r]),y=h.useCallback(b=>s.changeFindString(b),[s]);return ae(s,n),c.jsxs(c.Fragment,{children:[c.jsx(re,{findCompleted:d,className:"univer-find-input",matchesCount:S,matchesPosition:_,findReplaceService:s,localeService:t,findString:u,onChange:y}),c.jsx("div",{className:P.findReplaceExpandContainer,children:c.jsx(f.Button,{type:"text",size:"small",onClick:g,children:t.t("find-replace.dialog.advanced-finding")})})]})}),Xe=h.forwardRef(function(e,n){const t=o.useDependency(R),s=o.useDependency(o.LocaleService),r=o.useDependency(o.ICommandService),a=o.useDependency(p.IMessageService),d=p.useObservable(t.currentMatch$,void 0,!0),u=p.useObservable(t.replaceables$,void 0,!0),S=p.useObservable(t.state$,void 0,!0),{matchesCount:_,matchesPosition:g,findString:y,inputtingFindString:b,replaceString:le,caseSensitive:de,matchesTheWholeCell:ue,findDirection:he,findScope:pe,findBy:fe,findCompleted:L}=S,_e=b.length===0,ge=_===0||!(d!=null&&d.replaceable),me=u.length===0,ve=h.useCallback(m=>t.changeInputtingFindString(m),[t]),Se=h.useCallback(m=>t.changeReplaceString(m),[t]),{focus:Ce}=ae(t,n),Re=h.useCallback(()=>{y===b?t.moveToNextMatch():(t.changeFindString(b),t.find())},[y,b,t]),be=h.useCallback(()=>r.executeCommand(k.id),[r]),Me=h.useCallback(async()=>{await r.executeCommand(W.id),Ce()},[r]),ye=h.useCallback(m=>{t.changeFindDirection(m)},[t]),Ie=h.useCallback(m=>{t.changeFindScope(m)},[t]),xe=h.useCallback(m=>{t.changeFindBy(m)},[t]),Fe=tt(s),De=it(s),Oe=nt(s);return h.useEffect(()=>{L&&_===0&&a.show({content:s.t("find-replace.dialog.no-match"),type:f.MessageType.Warning,duration:5e3})},[L,_,a,s]),c.jsxs(c.Fragment,{children:[c.jsx(f.FormLayout,{label:s.t("find-replace.dialog.find"),children:c.jsx(re,{findCompleted:L,className:"univer-find-input",matchesCount:_,matchesPosition:g,findReplaceService:t,localeService:s,findString:b,onChange:ve})}),c.jsx(f.FormLayout,{label:s.t("find-replace.dialog.replace"),children:c.jsx(f.Input,{placeholder:s.t("find-replace.dialog.replace-placeholder"),value:le,onChange:m=>Se(m)})}),c.jsx(f.FormLayout,{label:s.t("find-replace.dialog.find-direction.title"),children:c.jsx(f.Select,{value:he,options:De,onChange:ye})}),c.jsx(f.FormDualColumnLayout,{children:c.jsxs(c.Fragment,{children:[c.jsx(f.FormLayout,{label:s.t("find-replace.dialog.find-scope.title"),children:c.jsx(f.Select,{value:pe,options:Fe,onChange:Ie})}),c.jsx(f.FormLayout,{label:s.t("find-replace.dialog.find-by.title"),children:c.jsx(f.Select,{value:fe,options:Oe,onChange:xe})})]})}),c.jsx(f.FormDualColumnLayout,{children:c.jsxs(c.Fragment,{children:[c.jsx(f.FormLayout,{children:c.jsx(f.Checkbox,{checked:de,onChange:m=>{t.changeCaseSensitive(m)},children:s.t("find-replace.dialog.case-sensitive")})}),c.jsx(f.FormLayout,{children:c.jsx(f.Checkbox,{checked:ue,onChange:m=>{t.changeMatchesTheWholeCell(m)},children:s.t("find-replace.dialog.match-the-whole-cell")})})]})}),c.jsxs("div",{className:P.findReplaceButtonsGroup,children:[c.jsx(f.Button,{type:"primary",onClick:Re,disabled:_e,children:s.t("find-replace.dialog.find")}),c.jsxs("span",{className:P.findReplaceButtonsGroupRight,children:[c.jsx(f.Button,{disabled:ge,onClick:be,children:s.t("find-replace.dialog.replace")}),c.jsx(f.Button,{disabled:me,onClick:Me,children:s.t("find-replace.dialog.replace-all")})]})]})]})});function et(){const i=o.useDependency(R),e=o.useDependency(p.ILayoutService),n=o.useDependency(o.IContextService),t=p.useObservable(i.state$,void 0,!0),s=h.useRef(null);h.useEffect(()=>{let u;return s.current&&(u=e.registerContainerElement(s.current)),()=>u==null?void 0:u.dispose()},[e]);const r=h.useRef(null),a=h.useCallback(u=>n.setContextValue(ie,u),[n]),d=h.useCallback(u=>n.setContextValue(te,u),[n]);return h.useEffect(()=>{var S;const u=v.fromEvent(document,"focusin").subscribe(_=>{var g;_.target&&((g=s.current)!=null&&g.contains(_.target))?a(!0):a(!1),!r.current||!r.current.selectHasFocus()?d(!0):d(!1)});return(S=r.current)==null||S.focus(),a(!0),d(!0),()=>{u.unsubscribe(),a(!1)}},[a,d]),c.jsx("div",{className:P.findReplaceDialogContainer,ref:s,children:t.replaceRevealed?c.jsx(Xe,{ref:r}):c.jsx(Qe,{ref:r})})}function tt(i){const e=i.getCurrentLocale();return h.useMemo(()=>[{label:i.t("find-replace.dialog.find-scope.current-sheet"),value:T.SUBUNIT},{label:i.t("find-replace.dialog.find-scope.workbook"),value:T.UNIT}],[e])}function it(i){const e=i.getCurrentLocale();return h.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 nt(i){const e=i.getCurrentLocale();return h.useMemo(()=>[{label:i.t("find-replace.dialog.find-by.value"),value:O.VALUE},{label:i.t("find-replace.dialog.find-by.formula"),value:O.FORMULA}],[e])}function F(i){return i.getContextValue(ie)}function st(i){return i.getContextValue(ne)}function oe(i){return i.getContextValue(te)}const N="7_find-replace-shortcuts";function H(i){return i.getContextValue(o.FOCUSING_SHEET)}function K(i){return!i.getContextValue(o.EDITOR_ACTIVATED)}const rt={id:I.id,description:"find-replace.shortcut.open-find-dialog",binding:p.KeyCode.F|p.MetaKeys.CTRL_COMMAND,group:N,preconditions(i){return!F(i)&&H(i)&&K(i)}},at={id:I.id,description:"find-replace.shortcut.open-find-dialog",binding:p.KeyCode.F|p.MetaKeys.CTRL_COMMAND,mac:p.KeyCode.F|p.MetaKeys.MAC_CTRL,preconditions(i){return!F(i)&&H(i)&&K(i)}},ot={id:E.id,description:"find-replace.shortcut.open-replace-dialog",binding:p.KeyCode.H|p.MetaKeys.CTRL_COMMAND,mac:p.KeyCode.H|p.MetaKeys.MAC_CTRL,group:N,preconditions(i){return H(i)&&K(i)&&(!F(i)||!st(i))}},ct={id:G.id,description:"find-replace.shortcut.go-to-next-match",binding:p.KeyCode.ENTER,group:N,priority:1e3,preconditions(i){return oe(i)&&F(i)}},lt={id:V.id,description:"find-replace.shortcut.go-to-previous-match",binding:p.KeyCode.ENTER|p.MetaKeys.SHIFT,group:N,priority:1e3,preconditions(i){return oe(i)&&F(i)}};function dt(i){const e=i.get(o.IContextService);return{id:I.id,icon:"SearchIcon",tooltip:"find-replace.toolbar",type:p.MenuItemType.BUTTON,hidden$:p.getMenuHiddenObservable(i,o.UniverInstanceType.UNIVER_SHEET),disabled$:v.combineLatest([e.subscribeContextValue$(o.EDITOR_ACTIVATED),e.subscribeContextValue$(o.FOCUSING_SHEET)]).pipe(v.map(([n,t])=>n||!t))}}const ut={[p.RibbonStartGroup.OTHERS]:{[I.id]:{order:2,menuItemFactory:dt}}};var ht=Object.defineProperty,pt=Object.getOwnPropertyDescriptor,ft=(i,e,n,t)=>{for(var s=t>1?void 0:t?pt(e,n):e,r=i.length-1,a;r>=0;r--)(a=i[r])&&(s=(t?a(e,n,s):a(s))||s);return t&&s&&ht(e,n,s),s},M=(i,e)=>(n,t)=>e(n,t,i);const Y="DESKTOP_FIND_REPLACE_DIALOG",ce=350,_t=20,gt=-90;exports.FindReplaceController=class extends o.RxDisposable{constructor(n,t,s,r,a,d,u,S,_,g){super();l(this,"_closingListenerDisposable");this._univerInstanceService=n,this._menuManagerService=t,this._shortcutService=s,this._commandService=r,this._findReplaceService=a,this._dialogService=d,this._layoutService=u,this._localeService=S,this._componentManager=_,this._injector=g,this._initCommands(),this._initUI(),this._initShortcuts()}dispose(){var n;super.dispose(),(n=this._closingListenerDisposable)==null||n.dispose(),this._closingListenerDisposable=null}_initCommands(){[I,E,G,V,W,k].forEach(n=>{this.disposeWithMe(this._commandService.registerCommand(n))})}_initShortcuts(){[ot,rt,at,lt,ct].forEach(n=>this.disposeWithMe(this._shortcutService.registerShortcut(n)))}_initUI(){this.disposeWithMe(this._componentManager.register("FindReplaceDialog",et)),this.disposeWithMe(this._componentManager.register("SearchIcon",ee)),this._menuManagerService.mergeMenu(ut),this._findReplaceService.stateUpdates$.pipe(v.takeUntil(this.dispose$)).subscribe(n=>{n.revealed===!0&&this._openPanel()})}_openPanel(){this._dialogService.open({id:Y,draggable:!0,width:ce,title:{title:this._localeService.t("find-replace.dialog.title")},children:{label:"FindReplaceDialog"},destroyOnClose:!0,defaultPosition:mt(),preservePositionOnDestroy:!0,onClose:()=>this.closePanel()}),this._closingListenerDisposable=o.toDisposable(this._univerInstanceService.focused$.pipe(v.takeUntil(this.dispose$)).subscribe(n=>{(!n||!this._univerInstanceService.getUniverSheetInstance(n))&&this.closePanel()}))}closePanel(){this._closingListenerDisposable&&(this._closingListenerDisposable.dispose(),this._closingListenerDisposable=null,this._dialogService.close(Y),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus()))}};exports.FindReplaceController=ft([M(0,o.IUniverInstanceService),M(1,p.IMenuManagerService),M(2,p.IShortcutService),M(3,o.ICommandService),M(4,R),M(5,p.IDialogService),M(6,p.ILayoutService),M(7,o.Inject(o.LocaleService)),M(8,o.Inject(p.ComponentManager)),M(9,o.Inject(o.Injector))],exports.FindReplaceController);function mt(){const{innerWidth:i}=window;return{x:(i-ce)/2-_t,y:gt}}var vt=Object.defineProperty,St=Object.getOwnPropertyDescriptor,Ct=(i,e,n,t)=>{for(var s=t>1?void 0:t?St(e,n):e,r=i.length-1,a;r>=0;r--)(a=i[r])&&(s=(t?a(e,n,s):a(s))||s);return t&&s&&vt(e,n,s),s},Z=(i,e)=>(n,t)=>e(n,t,i);const Rt="UNIVER_FIND_REPLACE_PLUGIN";var j;exports.UniverFindReplacePlugin=(j=class extends o.Plugin{constructor(e=q,n,t){super(),this._config=e,this._injector=n,this._configService=t;const{...s}=o.merge({},q,this._config);this._configService.setConfig(Ne,s)}onStarting(){[[exports.FindReplaceController],[R,{useClass:U}]].forEach(e=>this._injector.add(e))}onRendered(){this._injector.get(exports.FindReplaceController)}},l(j,"pluginName",Rt),j);exports.UniverFindReplacePlugin=Ct([Z(1,o.Inject(o.Injector)),Z(2,o.IConfigService)],exports.UniverFindReplacePlugin);exports.FindBy=O;exports.FindDirection=D;exports.FindModel=ke;exports.FindScope=T;exports.GoToNextMatchOperation=G;exports.GoToPreviousMatchOperation=V;exports.IFindReplaceService=R;exports.OpenFindDialogOperation=I;exports.OpenReplaceDialogOperation=E;exports.ReplaceAllMatchesCommand=W;exports.ReplaceCurrentMatchCommand=k;
|
|
9
|
+
*/var q;function Ve(){if(q)return x;q=1;var t=h,e=Symbol.for("react.element"),i=Symbol.for("react.fragment"),n=Object.prototype.hasOwnProperty,r=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,s={key:!0,ref:!0,__self:!0,__source:!0};function a(c,d,m){var _,g={},y=null,b=null;m!==void 0&&(y=""+m),d.key!==void 0&&(y=""+d.key),d.ref!==void 0&&(b=d.ref);for(_ in d)n.call(d,_)&&!s.hasOwnProperty(_)&&(g[_]=d[_]);if(c&&c.defaultProps)for(_ in d=c.defaultProps,d)g[_]===void 0&&(g[_]=d[_]);return{$$typeof:e,type:c,key:y,ref:b,props:g,_owner:r.current}}return x.Fragment=i,x.jsx=a,x.jsxs=a,x}var J;function He(){return J||(J=1,j.exports=Ve()),j.exports}var l=He();const Ke="univer-find-replace-dialog-container",qe="univer-find-replace-expand-container",Je="univer-button-text",ze="univer-find-replace-buttons-group",Ye="univer-find-replace-buttons-group-right",P={findReplaceDialogContainer:Ke,findReplaceExpandContainer:qe,buttonText:Je,findReplaceButtonsGroup:ze,findReplaceButtonsGroupRight:Ye};function se(t){const{findCompleted:e,localeService:i,matchesCount:n,matchesPosition:r,findString:s,findReplaceService:a,onChange:c,...d}=t,_=e&&n===0?i.t("find-replace.dialog.no-result"):n===0?" ":void 0;return l.jsx(f.InputWithSlot,{autoFocus:!0,placeholder:i.t("find-replace.dialog.find-placeholder"),slot:l.jsx(f.Pager,{loop:!0,text:_,value:r,total:n,onChange:g=>{r===n&&g===1?a.moveToNextMatch():r===1&&g===n||g<r?a.moveToPreviousMatch():a.moveToNextMatch()}}),value:s,onChange:g=>c==null?void 0:c(g),...d})}function ae(t,e){const i=h.useCallback(()=>{var r;(r=document.querySelector(".univer-find-input input"))==null||r.focus()},[]),n=h.useCallback(()=>{const r=document.querySelectorAll(".univer-find-replace-dialog-container .univer-select-selection-search-input");return Array.from(r).some(s=>s===document.activeElement)},[]);return h.useImperativeHandle(e,()=>({focus:i,selectHasFocus:n})),h.useEffect(()=>{const r=t.focusSignal$.subscribe(()=>i());return()=>r.unsubscribe()},[t,i]),{focus:i,selectHasFocus:n}}const Ze=h.forwardRef(function(e,i){const n=o.useDependency(o.LocaleService),r=o.useDependency(R),s=o.useDependency(o.ICommandService),a=p.useObservable(r.state$,void 0,!0),{findCompleted:c,findString:d,matchesCount:m,matchesPosition:_}=a,g=h.useCallback(()=>{s.executeCommand(N.id)},[s]),y=h.useCallback(b=>r.changeFindString(b),[r]);return ae(r,i),l.jsxs(l.Fragment,{children:[l.jsx(se,{findCompleted:c,className:"univer-find-input",matchesCount:m,matchesPosition:_,findReplaceService:r,localeService:n,findString:d,onChange:y}),l.jsx("div",{className:P.findReplaceExpandContainer,children:l.jsx(f.Button,{type:"text",size:"small",onClick:g,children:n.t("find-replace.dialog.advanced-finding")})})]})}),Qe=h.forwardRef(function(e,i){const n=o.useDependency(R),r=o.useDependency(o.LocaleService),s=o.useDependency(o.ICommandService),a=o.useDependency(p.IMessageService),c=p.useObservable(n.currentMatch$,void 0,!0),d=p.useObservable(n.replaceables$,void 0,!0),m=p.useObservable(n.state$,void 0,!0),{matchesCount:_,matchesPosition:g,findString:y,inputtingFindString:b,replaceString:le,caseSensitive:de,matchesTheWholeCell:ue,findDirection:he,findScope:pe,findBy:fe,findCompleted:$}=m,_e=b.length===0,ge=_===0||!(c!=null&&c.replaceable),me=d.length===0,ve=h.useCallback(v=>n.changeInputtingFindString(v),[n]),Se=h.useCallback(v=>n.changeReplaceString(v),[n]),{focus:Ce}=ae(n,i),Re=h.useCallback(()=>{y===b?n.moveToNextMatch():(n.changeFindString(b),n.find())},[y,b,n]),be=h.useCallback(()=>s.executeCommand(B.id),[s]),Me=h.useCallback(async()=>{await s.executeCommand(k.id),Ce()},[s]),ye=h.useCallback(v=>{n.changeFindDirection(v)},[n]),Ie=h.useCallback(v=>{n.changeFindScope(v)},[n]),xe=h.useCallback(v=>{n.changeFindBy(v)},[n]),Fe=et(r),De=tt(r),Oe=nt(r);return h.useEffect(()=>{$&&_===0&&a.show({content:r.t("find-replace.dialog.no-match"),type:f.MessageType.Warning,duration:5e3})},[$,_,a,r]),l.jsxs(l.Fragment,{children:[l.jsx(f.FormLayout,{label:r.t("find-replace.dialog.find"),children:l.jsx(se,{findCompleted:$,className:"univer-find-input",matchesCount:_,matchesPosition:g,findReplaceService:n,localeService:r,findString:b,onChange:ve})}),l.jsx(f.FormLayout,{label:r.t("find-replace.dialog.replace"),children:l.jsx(f.Input,{placeholder:r.t("find-replace.dialog.replace-placeholder"),value:le,onChange:v=>Se(v)})}),l.jsx(f.FormLayout,{label:r.t("find-replace.dialog.find-direction.title"),children:l.jsx(f.Select,{value:he,options:De,onChange:ye})}),l.jsx(f.FormDualColumnLayout,{children:l.jsxs(l.Fragment,{children:[l.jsx(f.FormLayout,{label:r.t("find-replace.dialog.find-scope.title"),children:l.jsx(f.Select,{value:pe,options:Fe,onChange:Ie})}),l.jsx(f.FormLayout,{label:r.t("find-replace.dialog.find-by.title"),children:l.jsx(f.Select,{value:fe,options:Oe,onChange:xe})})]})}),l.jsx(f.FormDualColumnLayout,{children:l.jsxs(l.Fragment,{children:[l.jsx(f.FormLayout,{children:l.jsx(f.Checkbox,{checked:de,onChange:v=>{n.changeCaseSensitive(v)},children:r.t("find-replace.dialog.case-sensitive")})}),l.jsx(f.FormLayout,{children:l.jsx(f.Checkbox,{checked:ue,onChange:v=>{n.changeMatchesTheWholeCell(v)},children:r.t("find-replace.dialog.match-the-whole-cell")})})]})}),l.jsxs("div",{className:P.findReplaceButtonsGroup,children:[l.jsx(f.Button,{type:"primary",onClick:Re,disabled:_e,children:r.t("find-replace.dialog.find")}),l.jsxs("span",{className:P.findReplaceButtonsGroupRight,children:[l.jsx(f.Button,{disabled:ge,onClick:be,children:r.t("find-replace.dialog.replace")}),l.jsx(f.Button,{disabled:me,onClick:Me,children:r.t("find-replace.dialog.replace-all")})]})]})]})});function Xe(){const t=o.useDependency(R),e=o.useDependency(p.ILayoutService),i=o.useDependency(o.IContextService),n=p.useObservable(t.state$,void 0,!0),r=h.useRef(null);h.useEffect(()=>{let d;return r.current&&(d=e.registerContainerElement(r.current)),()=>d==null?void 0:d.dispose()},[e]);const s=h.useRef(null),a=h.useCallback(d=>i.setContextValue(te,d),[i]),c=h.useCallback(d=>i.setContextValue(ee,d),[i]);return h.useEffect(()=>{var m;const d=S.fromEvent(document,"focusin").subscribe(_=>{var g;_.target&&((g=r.current)!=null&&g.contains(_.target))?a(!0):a(!1),!s.current||!s.current.selectHasFocus()?c(!0):c(!1)});return(m=s.current)==null||m.focus(),a(!0),c(!0),()=>{d.unsubscribe(),a(!1)}},[a,c]),l.jsx("div",{className:P.findReplaceDialogContainer,ref:r,children:n.replaceRevealed?l.jsx(Qe,{ref:s}):l.jsx(Ze,{ref:s})})}function et(t){const e=t.getCurrentLocale();return h.useMemo(()=>[{label:t.t("find-replace.dialog.find-scope.current-sheet"),value:T.SUBUNIT},{label:t.t("find-replace.dialog.find-scope.workbook"),value:T.UNIT}],[e])}function tt(t){const e=t.getCurrentLocale();return h.useMemo(()=>[{label:t.t("find-replace.dialog.find-direction.row"),value:D.ROW},{label:t.t("find-replace.dialog.find-direction.column"),value:D.COLUMN}],[e])}function nt(t){const e=t.getCurrentLocale();return h.useMemo(()=>[{label:t.t("find-replace.dialog.find-by.value"),value:O.VALUE},{label:t.t("find-replace.dialog.find-by.formula"),value:O.FORMULA}],[e])}function F(t){return t.getContextValue(te)}function it(t){return t.getContextValue(ne)}function oe(t){return t.getContextValue(ee)}const L="7_find-replace-shortcuts";function V(t){return t.getContextValue(o.FOCUSING_SHEET)}function H(t){return!t.getContextValue(o.EDITOR_ACTIVATED)}const rt={id:I.id,description:"find-replace.shortcut.open-find-dialog",binding:p.KeyCode.F|p.MetaKeys.CTRL_COMMAND,group:L,preconditions(t){return!F(t)&&V(t)&&H(t)}},st={id:I.id,description:"find-replace.shortcut.open-find-dialog",binding:p.KeyCode.F|p.MetaKeys.CTRL_COMMAND,mac:p.KeyCode.F|p.MetaKeys.MAC_CTRL,preconditions(t){return!F(t)&&V(t)&&H(t)}},at={id:N.id,description:"find-replace.shortcut.open-replace-dialog",binding:p.KeyCode.H|p.MetaKeys.CTRL_COMMAND,mac:p.KeyCode.H|p.MetaKeys.MAC_CTRL,group:L,preconditions(t){return V(t)&&H(t)&&(!F(t)||!it(t))}},ot={id:W.id,description:"find-replace.shortcut.go-to-next-match",binding:p.KeyCode.ENTER,group:L,priority:1e3,preconditions(t){return oe(t)&&F(t)}},ct={id:G.id,description:"find-replace.shortcut.go-to-previous-match",binding:p.KeyCode.ENTER|p.MetaKeys.SHIFT,group:L,priority:1e3,preconditions(t){return oe(t)&&F(t)}};function lt(t){const e=t.get(o.IContextService);return{id:I.id,icon:"SearchIcon",tooltip:"find-replace.toolbar",type:p.MenuItemType.BUTTON,hidden$:p.getMenuHiddenObservable(t,o.UniverInstanceType.UNIVER_SHEET),disabled$:S.combineLatest([e.subscribeContextValue$(o.EDITOR_ACTIVATED),e.subscribeContextValue$(o.FOCUSING_SHEET)]).pipe(S.map(([i,n])=>i||!n))}}const dt={[p.RibbonStartGroup.OTHERS]:{[I.id]:{order:2,menuItemFactory:lt}}};var ut=Object.defineProperty,ht=Object.getOwnPropertyDescriptor,pt=(t,e,i,n)=>{for(var r=n>1?void 0:n?ht(e,i):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(r=(n?a(e,i,r):a(r))||r);return n&&r&&ut(e,i,r),r},M=(t,e)=>(i,n)=>e(i,n,t);const z="DESKTOP_FIND_REPLACE_DIALOG",ce=350,ft=20,_t=-90;exports.FindReplaceController=class extends o.RxDisposable{constructor(i,n,r,s,a,c,d,m,_,g){super();u(this,"_closingListenerDisposable");this._univerInstanceService=i,this._menuManagerService=n,this._shortcutService=r,this._commandService=s,this._findReplaceService=a,this._dialogService=c,this._layoutService=d,this._localeService=m,this._componentManager=_,this._injector=g,this._initCommands(),this._initUI(),this._initShortcuts()}dispose(){var i;super.dispose(),(i=this._closingListenerDisposable)==null||i.dispose(),this._closingListenerDisposable=null}_initCommands(){[I,N,W,G,k,B].forEach(i=>{this.disposeWithMe(this._commandService.registerCommand(i))})}_initShortcuts(){[at,rt,st,ct,ot].forEach(i=>this.disposeWithMe(this._shortcutService.registerShortcut(i)))}_initUI(){this.disposeWithMe(this._componentManager.register("FindReplaceDialog",Xe)),this.disposeWithMe(this._componentManager.register("SearchIcon",X)),this._menuManagerService.mergeMenu(dt),this._findReplaceService.stateUpdates$.pipe(S.takeUntil(this.dispose$)).subscribe(i=>{i.revealed===!0&&this._openPanel()})}_openPanel(){this._dialogService.open({id:z,draggable:!0,width:ce,title:{title:this._localeService.t("find-replace.dialog.title")},children:{label:"FindReplaceDialog"},destroyOnClose:!0,defaultPosition:gt(),preservePositionOnDestroy:!0,onClose:()=>this.closePanel()}),this._closingListenerDisposable=o.toDisposable(this._univerInstanceService.focused$.pipe(S.takeUntil(this.dispose$)).subscribe(i=>{(!i||!this._univerInstanceService.getUniverSheetInstance(i))&&this.closePanel()}))}closePanel(){this._closingListenerDisposable&&(this._closingListenerDisposable.dispose(),this._closingListenerDisposable=null,this._dialogService.close(z),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus()))}};exports.FindReplaceController=pt([M(0,o.IUniverInstanceService),M(1,p.IMenuManagerService),M(2,p.IShortcutService),M(3,o.ICommandService),M(4,R),M(5,p.IDialogService),M(6,p.ILayoutService),M(7,o.Inject(o.LocaleService)),M(8,o.Inject(p.ComponentManager)),M(9,o.Inject(o.Injector))],exports.FindReplaceController);function gt(){const{innerWidth:t}=window;return{x:(t-ce)/2-ft,y:_t}}var mt=Object.defineProperty,vt=Object.getOwnPropertyDescriptor,St=(t,e,i,n)=>{for(var r=n>1?void 0:n?vt(e,i):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(r=(n?a(e,i,r):a(r))||r);return n&&r&&mt(e,i,r),r},Y=(t,e)=>(i,n)=>e(i,n,t);const Ct="UNIVER_FIND_REPLACE_PLUGIN";var A;exports.UniverFindReplacePlugin=(A=class extends o.Plugin{constructor(e=K,i,n){super(),this._config=e,this._injector=i,this._configService=n;const{...r}=o.merge({},K,this._config);this._configService.setConfig(Ne,r)}onStarting(){[[exports.FindReplaceController],[R,{useClass:U}]].forEach(e=>this._injector.add(e))}onRendered(){this._injector.get(exports.FindReplaceController)}},u(A,"pluginName",Ct),A);exports.UniverFindReplacePlugin=St([Y(1,o.Inject(o.Injector)),Y(2,o.IConfigService)],exports.UniverFindReplacePlugin);exports.FindBy=O;exports.FindDirection=D;exports.FindModel=ke;exports.FindReplaceState=re;exports.FindScope=T;exports.GoToNextMatchOperation=W;exports.GoToPreviousMatchOperation=G;exports.IFindReplaceService=R;exports.OpenFindDialogOperation=I;exports.OpenReplaceDialogOperation=N;exports.ReplaceAllMatchesCommand=k;exports.ReplaceCurrentMatchCommand=B;exports.createInitFindReplaceState=E;
|
package/lib/es/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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
|
-
var
|
|
4
|
-
import { createIdentifier as ct, Inject as F, Injector as Q, Disposable as X,
|
|
3
|
+
var l = (t, e, n) => ot(t, typeof e != "symbol" ? e + "" : e, n);
|
|
4
|
+
import { createIdentifier as ct, Inject as F, Injector as Q, Disposable as X, DisposableCollection as lt, toDisposable as $, IUniverInstanceService as ge, IContextService as ee, CommandType as y, LocaleService as w, useDependency as C, ICommandService as te, FOCUSING_SHEET as me, EDITOR_ACTIVATED as ve, UniverInstanceType as dt, RxDisposable as ut, Plugin as ht, merge as ft, IConfigService as pt } from "@univerjs/core";
|
|
5
5
|
import { IConfirmService as _t, IMessageService as Se, useObservable as D, ILayoutService as Ce, KeyCode as b, MetaKeys as x, MenuItemType as gt, getMenuHiddenObservable as mt, RibbonStartGroup as vt, ComponentManager as St, IMenuManagerService as Ct, IShortcutService as Rt, IDialogService as Mt } from "@univerjs/ui";
|
|
6
6
|
import { throttleTime as bt, BehaviorSubject as P, combineLatest as Re, debounceTime as xt, Subject as Me, fromEvent as yt, map as It, takeUntil as oe } from "rxjs";
|
|
7
7
|
import { MessageType as E, InputWithSlot as Ft, Pager as Dt, Button as N, FormLayout as M, Input as Pt, Select as G, FormDualColumnLayout as ce, Checkbox as le } from "@univerjs/design";
|
|
@@ -24,8 +24,8 @@ var g = function() {
|
|
|
24
24
|
e.indexOf(i[r]) < 0 && Object.prototype.propertyIsEnumerable.call(t, i[r]) && (n[i[r]] = t[i[r]]);
|
|
25
25
|
return n;
|
|
26
26
|
}, xe = U(function(t, e) {
|
|
27
|
-
var n = t.icon, i = t.id, r = t.className, s = t.extend, a = $t(t, ["icon", "id", "className", "extend"]),
|
|
28
|
-
return ye(n, "".concat(i), { defIds: n.defIds, idSuffix:
|
|
27
|
+
var n = t.icon, i = t.id, r = t.className, s = t.extend, a = $t(t, ["icon", "id", "className", "extend"]), d = "univerjs-icon univerjs-icon-".concat(i, " ").concat(r || "").trim(), c = H("_".concat(jt()));
|
|
28
|
+
return ye(n, "".concat(i), { defIds: n.defIds, idSuffix: c.current }, g({ ref: e, className: d }, a), s);
|
|
29
29
|
});
|
|
30
30
|
function ye(t, e, n, i, r) {
|
|
31
31
|
return be(t.tag, g(g({ key: e }, At(t, n, r)), i), (Lt(t, n).children || []).map(function(s, a) {
|
|
@@ -37,8 +37,8 @@ function At(t, e, n) {
|
|
|
37
37
|
n != null && n.colorChannel1 && i.fill === "colorChannel1" && (i.fill = n.colorChannel1);
|
|
38
38
|
var r = e.defIds;
|
|
39
39
|
return !r || r.length === 0 || (t.tag === "use" && i["xlink:href"] && (i["xlink:href"] = i["xlink:href"] + e.idSuffix), Object.entries(i).forEach(function(s) {
|
|
40
|
-
var a = s[0],
|
|
41
|
-
typeof
|
|
40
|
+
var a = s[0], d = s[1];
|
|
41
|
+
typeof d == "string" && (i[a] = d.replace(/url\(#(.*)\)/, "url(#$1".concat(e.idSuffix, ")")));
|
|
42
42
|
})), i;
|
|
43
43
|
}
|
|
44
44
|
function Lt(t, e) {
|
|
@@ -74,14 +74,14 @@ function Wt(t) {
|
|
|
74
74
|
let J = class extends X {
|
|
75
75
|
constructor(e, n, i) {
|
|
76
76
|
super();
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
l(this, "currentMatch$", new P(null));
|
|
78
|
+
l(this, "replaceables$", new P([]));
|
|
79
79
|
/** All find models returned by providers. */
|
|
80
|
-
|
|
80
|
+
l(this, "_findModels", []);
|
|
81
81
|
/** The find model that the current match is from. */
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
l(this, "_matchingModel", null);
|
|
83
|
+
l(this, "_matches", []);
|
|
84
|
+
l(this, "_currentSearchingDisposables", null);
|
|
85
85
|
this._state = e, this._providers = n, this._univerInstanceService = i, this.disposeWithMe(
|
|
86
86
|
this._state.stateUpdates$.pipe(bt(200, void 0, { leading: !0, trailing: !0 })).subscribe(async (r) => {
|
|
87
87
|
const s = this._state.state;
|
|
@@ -134,7 +134,7 @@ let J = class extends X {
|
|
|
134
134
|
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([]));
|
|
135
135
|
});
|
|
136
136
|
e.forEach((r) => n.add($(r.activelyChangingMatch$.subscribe((s) => {
|
|
137
|
-
const a = this._matches.findIndex((
|
|
137
|
+
const a = this._matches.findIndex((d) => d === s);
|
|
138
138
|
this._state.changeState({ matchesPosition: a + 1 });
|
|
139
139
|
})))), n.add($(i));
|
|
140
140
|
}
|
|
@@ -157,25 +157,23 @@ let J = class extends X {
|
|
|
157
157
|
return;
|
|
158
158
|
const e = this._findModels.length === 1, n = this._matchingModel.moveToNextMatch({ loop: e });
|
|
159
159
|
if (n)
|
|
160
|
-
this._markMatch(n);
|
|
161
|
-
|
|
160
|
+
return this._markMatch(n), n;
|
|
161
|
+
{
|
|
162
162
|
const i = this._findModels.findIndex((r) => r === this._matchingModel);
|
|
163
|
-
this._moveToNextUnitMatch(i);
|
|
163
|
+
return this._moveToNextUnitMatch(i);
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
166
|
_moveToNextUnitMatch(e) {
|
|
167
167
|
const n = this._findModels.length;
|
|
168
168
|
for (let i = (e + 1) % n; i !== e; ) {
|
|
169
169
|
const r = this._findModels[i], s = r.moveToNextMatch({ ignoreSelection: !0 });
|
|
170
|
-
if (s)
|
|
171
|
-
this._matchingModel = r, this._markMatch(s);
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
170
|
+
if (s)
|
|
171
|
+
return this._matchingModel = r, this._markMatch(s), s;
|
|
174
172
|
i = (i + 1) % n;
|
|
175
173
|
}
|
|
176
174
|
if (this._matchingModel) {
|
|
177
175
|
const i = this._matchingModel.moveToNextMatch({ ignoreSelection: !0 });
|
|
178
|
-
i && this._markMatch(i);
|
|
176
|
+
return i && this._markMatch(i), i;
|
|
179
177
|
}
|
|
180
178
|
}
|
|
181
179
|
moveToPreviousMatch() {
|
|
@@ -184,19 +182,17 @@ let J = class extends X {
|
|
|
184
182
|
const e = this._findModels.length === 1, n = this._matchingModel.moveToPreviousMatch({ loop: e });
|
|
185
183
|
if (n) {
|
|
186
184
|
const i = this._matches.findIndex((r) => r === n);
|
|
187
|
-
this.currentMatch$.next(n), this._state.changeState({ matchesPosition: i + 1 });
|
|
185
|
+
return this.currentMatch$.next(n), this._state.changeState({ matchesPosition: i + 1 }), n;
|
|
188
186
|
} else {
|
|
189
187
|
const i = this._findModels.length, r = this._findModels.findIndex((a) => a === this._matchingModel);
|
|
190
188
|
for (let a = (r - 1 + i) % i; a !== r; ) {
|
|
191
|
-
const
|
|
192
|
-
if (
|
|
193
|
-
this._matchingModel =
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
189
|
+
const d = this._findModels[a], c = d.moveToPreviousMatch({ ignoreSelection: !0 });
|
|
190
|
+
if (c)
|
|
191
|
+
return this._matchingModel = d, this._markMatch(c), c;
|
|
196
192
|
a = (a - 1) % i;
|
|
197
193
|
}
|
|
198
194
|
const s = this._matchingModel.moveToPreviousMatch({ ignoreSelection: !0 });
|
|
199
|
-
s && this._markMatch(s);
|
|
195
|
+
return s && this._markMatch(s), s;
|
|
200
196
|
}
|
|
201
197
|
}
|
|
202
198
|
_moveToInitialMatch(e, n = !1) {
|
|
@@ -237,23 +233,23 @@ function ne() {
|
|
|
237
233
|
}
|
|
238
234
|
class Gt {
|
|
239
235
|
constructor() {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
236
|
+
l(this, "_stateUpdates$", new Me());
|
|
237
|
+
l(this, "stateUpdates$", this._stateUpdates$.asObservable());
|
|
238
|
+
l(this, "_state$", new P(ne()));
|
|
239
|
+
l(this, "state$", this._state$.asObservable());
|
|
240
|
+
l(this, "_findString", "");
|
|
241
|
+
l(this, "_inputtingFindString", "");
|
|
242
|
+
l(this, "_replaceString", "");
|
|
243
|
+
l(this, "_revealed", !1);
|
|
244
|
+
l(this, "_replaceRevealed", !1);
|
|
245
|
+
l(this, "_matchesPosition", 0);
|
|
246
|
+
l(this, "_matchesCount", 0);
|
|
247
|
+
l(this, "_caseSensitive", !0);
|
|
248
|
+
l(this, "_matchesTheWholeCell", !1);
|
|
249
|
+
l(this, "_findDirection", "row");
|
|
250
|
+
l(this, "_findScope", "subunit");
|
|
251
|
+
l(this, "_findBy", "value");
|
|
252
|
+
l(this, "_findCompleted", !1);
|
|
257
253
|
}
|
|
258
254
|
get state() {
|
|
259
255
|
return this._state$.getValue();
|
|
@@ -320,15 +316,15 @@ class Gt {
|
|
|
320
316
|
let Z = class extends X {
|
|
321
317
|
constructor(e, n) {
|
|
322
318
|
super();
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
319
|
+
l(this, "_providers", /* @__PURE__ */ new Set());
|
|
320
|
+
l(this, "_state", new Gt());
|
|
321
|
+
l(this, "_model");
|
|
322
|
+
l(this, "_currentMatch$", new P(null));
|
|
323
|
+
l(this, "currentMatch$", this._currentMatch$.asObservable());
|
|
324
|
+
l(this, "_replaceables$", new P([]));
|
|
325
|
+
l(this, "replaceables$", this._replaceables$.asObservable());
|
|
326
|
+
l(this, "_focusSignal$", new Me());
|
|
327
|
+
l(this, "focusSignal$", this._focusSignal$.asObservable());
|
|
332
328
|
this._injector = e, this._contextService = n;
|
|
333
329
|
}
|
|
334
330
|
get stateUpdates$() {
|
|
@@ -346,6 +342,9 @@ let Z = class extends X {
|
|
|
346
342
|
dispose() {
|
|
347
343
|
super.dispose(), this._currentMatch$.next(null), this._currentMatch$.complete(), this._replaceables$.next([]), this._replaceables$.complete(), this._focusSignal$.complete();
|
|
348
344
|
}
|
|
345
|
+
getProviders() {
|
|
346
|
+
return this._providers;
|
|
347
|
+
}
|
|
349
348
|
getCurrentMatch() {
|
|
350
349
|
var e;
|
|
351
350
|
return (e = this._model) == null ? void 0 : e.getCurrentMatch();
|
|
@@ -445,13 +444,13 @@ const Te = {
|
|
|
445
444
|
confirmText: n.t("button.confirm")
|
|
446
445
|
}))
|
|
447
446
|
return !1;
|
|
448
|
-
const s = await t.get(m).replaceAll(), { success: a, failure:
|
|
449
|
-
return
|
|
447
|
+
const s = await t.get(m).replaceAll(), { success: a, failure: d } = s;
|
|
448
|
+
return d > 0 ? (a === 0 ? i.show({
|
|
450
449
|
type: E.Error,
|
|
451
450
|
content: n.t("find-replace.replace.all-failure")
|
|
452
451
|
}) : i.show({
|
|
453
452
|
type: E.Warning,
|
|
454
|
-
content: n.t("find-replace.replace.partial-success", `${a}`, `${
|
|
453
|
+
content: n.t("find-replace.replace.partial-success", `${a}`, `${d}`)
|
|
455
454
|
}), !1) : (i.show({
|
|
456
455
|
type: E.Success,
|
|
457
456
|
content: n.t("find-replace.replace.all-success", `${a}`)
|
|
@@ -490,23 +489,23 @@ var k = { exports: {} }, I = {};
|
|
|
490
489
|
* This source code is licensed under the MIT license found in the
|
|
491
490
|
* LICENSE file in the root directory of this source tree.
|
|
492
491
|
*/
|
|
493
|
-
var
|
|
492
|
+
var ue;
|
|
494
493
|
function Vt() {
|
|
495
|
-
if (
|
|
496
|
-
|
|
494
|
+
if (ue) return I;
|
|
495
|
+
ue = 1;
|
|
497
496
|
var t = Tt, e = Symbol.for("react.element"), n = Symbol.for("react.fragment"), i = Object.prototype.hasOwnProperty, r = t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, s = { key: !0, ref: !0, __self: !0, __source: !0 };
|
|
498
|
-
function a(
|
|
499
|
-
var
|
|
500
|
-
_ !== void 0 && (R = "" + _),
|
|
501
|
-
for (
|
|
502
|
-
if (
|
|
503
|
-
return { $$typeof: e, type:
|
|
497
|
+
function a(d, c, _) {
|
|
498
|
+
var u, h = {}, R = null, v = null;
|
|
499
|
+
_ !== void 0 && (R = "" + _), c.key !== void 0 && (R = "" + c.key), c.ref !== void 0 && (v = c.ref);
|
|
500
|
+
for (u in c) i.call(c, u) && !s.hasOwnProperty(u) && (h[u] = c[u]);
|
|
501
|
+
if (d && d.defaultProps) for (u in c = d.defaultProps, c) h[u] === void 0 && (h[u] = c[u]);
|
|
502
|
+
return { $$typeof: e, type: d, key: R, ref: v, props: h, _owner: r.current };
|
|
504
503
|
}
|
|
505
504
|
return I.Fragment = n, I.jsx = a, I.jsxs = a, I;
|
|
506
505
|
}
|
|
507
|
-
var
|
|
506
|
+
var he;
|
|
508
507
|
function Ht() {
|
|
509
|
-
return
|
|
508
|
+
return he || (he = 1, k.exports = Vt()), k.exports;
|
|
510
509
|
}
|
|
511
510
|
var o = Ht();
|
|
512
511
|
const qt = "univer-find-replace-dialog-container", Jt = "univer-find-replace-expand-container", Kt = "univer-button-text", zt = "univer-find-replace-buttons-group", Yt = "univer-find-replace-buttons-group-right", L = {
|
|
@@ -517,7 +516,7 @@ const qt = "univer-find-replace-dialog-container", Jt = "univer-find-replace-exp
|
|
|
517
516
|
findReplaceButtonsGroupRight: Yt
|
|
518
517
|
};
|
|
519
518
|
function Ae(t) {
|
|
520
|
-
const { findCompleted: e, localeService: n, matchesCount: i, matchesPosition: r, findString: s, findReplaceService: a, onChange:
|
|
519
|
+
const { findCompleted: e, localeService: n, matchesCount: i, matchesPosition: r, findString: s, findReplaceService: a, onChange: d, ...c } = t, u = e && i === 0 ? n.t("find-replace.dialog.no-result") : i === 0 ? " " : void 0;
|
|
521
520
|
return /* @__PURE__ */ o.jsx(
|
|
522
521
|
Ft,
|
|
523
522
|
{
|
|
@@ -527,17 +526,17 @@ function Ae(t) {
|
|
|
527
526
|
Dt,
|
|
528
527
|
{
|
|
529
528
|
loop: !0,
|
|
530
|
-
text:
|
|
529
|
+
text: u,
|
|
531
530
|
value: r,
|
|
532
531
|
total: i,
|
|
533
|
-
onChange: (
|
|
534
|
-
r === i &&
|
|
532
|
+
onChange: (h) => {
|
|
533
|
+
r === i && h === 1 ? a.moveToNextMatch() : r === 1 && h === i || h < r ? a.moveToPreviousMatch() : a.moveToNextMatch();
|
|
535
534
|
}
|
|
536
535
|
}
|
|
537
536
|
),
|
|
538
537
|
value: s,
|
|
539
|
-
onChange: (
|
|
540
|
-
...
|
|
538
|
+
onChange: (h) => d == null ? void 0 : d(h),
|
|
539
|
+
...c
|
|
541
540
|
}
|
|
542
541
|
);
|
|
543
542
|
}
|
|
@@ -555,29 +554,29 @@ function Le(t, e) {
|
|
|
555
554
|
}, [t, n]), { focus: n, selectHasFocus: i };
|
|
556
555
|
}
|
|
557
556
|
const Zt = U(function(e, n) {
|
|
558
|
-
const i = C(w), r = C(m), s = C(te), a = D(r.state$, void 0, !0), { findCompleted:
|
|
557
|
+
const i = C(w), r = C(m), s = C(te), a = D(r.state$, void 0, !0), { findCompleted: d, findString: c, matchesCount: _, matchesPosition: u } = a, h = p(() => {
|
|
559
558
|
s.executeCommand(re.id);
|
|
560
559
|
}, [s]), R = p((v) => r.changeFindString(v), [r]);
|
|
561
560
|
return Le(r, n), /* @__PURE__ */ o.jsxs(o.Fragment, { children: [
|
|
562
561
|
/* @__PURE__ */ o.jsx(
|
|
563
562
|
Ae,
|
|
564
563
|
{
|
|
565
|
-
findCompleted:
|
|
564
|
+
findCompleted: d,
|
|
566
565
|
className: "univer-find-input",
|
|
567
566
|
matchesCount: _,
|
|
568
|
-
matchesPosition:
|
|
567
|
+
matchesPosition: u,
|
|
569
568
|
findReplaceService: r,
|
|
570
569
|
localeService: i,
|
|
571
|
-
findString:
|
|
570
|
+
findString: c,
|
|
572
571
|
onChange: R
|
|
573
572
|
}
|
|
574
573
|
),
|
|
575
|
-
/* @__PURE__ */ o.jsx("div", { className: L.findReplaceExpandContainer, children: /* @__PURE__ */ o.jsx(N, { type: "text", size: "small", onClick:
|
|
574
|
+
/* @__PURE__ */ o.jsx("div", { className: L.findReplaceExpandContainer, children: /* @__PURE__ */ o.jsx(N, { type: "text", size: "small", onClick: h, children: i.t("find-replace.dialog.advanced-finding") }) })
|
|
576
575
|
] });
|
|
577
576
|
}), Qt = U(function(e, n) {
|
|
578
|
-
const i = C(m), r = C(w), s = C(te), a = C(Se),
|
|
579
|
-
matchesCount:
|
|
580
|
-
matchesPosition:
|
|
577
|
+
const i = C(m), r = C(w), s = C(te), a = C(Se), d = D(i.currentMatch$, void 0, !0), c = D(i.replaceables$, void 0, !0), _ = D(i.state$, void 0, !0), {
|
|
578
|
+
matchesCount: u,
|
|
579
|
+
matchesPosition: h,
|
|
581
580
|
findString: R,
|
|
582
581
|
inputtingFindString: v,
|
|
583
582
|
replaceString: Ue,
|
|
@@ -587,7 +586,7 @@ const Zt = U(function(e, n) {
|
|
|
587
586
|
findScope: ke,
|
|
588
587
|
findBy: Ve,
|
|
589
588
|
findCompleted: W
|
|
590
|
-
} = _, He = v.length === 0, qe =
|
|
589
|
+
} = _, He = v.length === 0, qe = u === 0 || !(d != null && d.replaceable), Je = c.length === 0, Ke = p(
|
|
591
590
|
(f) => i.changeInputtingFindString(f),
|
|
592
591
|
[i]
|
|
593
592
|
), ze = p(
|
|
@@ -605,19 +604,19 @@ const Zt = U(function(e, n) {
|
|
|
605
604
|
i.changeFindBy(f);
|
|
606
605
|
}, [i]), nt = ei(r), rt = ti(r), st = ii(r);
|
|
607
606
|
return A(() => {
|
|
608
|
-
W &&
|
|
607
|
+
W && u === 0 && a.show({
|
|
609
608
|
content: r.t("find-replace.dialog.no-match"),
|
|
610
609
|
type: E.Warning,
|
|
611
610
|
duration: 5e3
|
|
612
611
|
});
|
|
613
|
-
}, [W,
|
|
612
|
+
}, [W, u, a, r]), /* @__PURE__ */ o.jsxs(o.Fragment, { children: [
|
|
614
613
|
/* @__PURE__ */ o.jsx(M, { label: r.t("find-replace.dialog.find"), children: /* @__PURE__ */ o.jsx(
|
|
615
614
|
Ae,
|
|
616
615
|
{
|
|
617
616
|
findCompleted: W,
|
|
618
617
|
className: "univer-find-input",
|
|
619
|
-
matchesCount:
|
|
620
|
-
matchesPosition:
|
|
618
|
+
matchesCount: u,
|
|
619
|
+
matchesPosition: h,
|
|
621
620
|
findReplaceService: i,
|
|
622
621
|
localeService: r,
|
|
623
622
|
findString: v,
|
|
@@ -671,26 +670,26 @@ const Zt = U(function(e, n) {
|
|
|
671
670
|
function Xt() {
|
|
672
671
|
const t = C(m), e = C(Ce), n = C(ee), i = D(t.state$, void 0, !0), r = H(null);
|
|
673
672
|
A(() => {
|
|
674
|
-
let
|
|
675
|
-
return r.current && (
|
|
673
|
+
let c;
|
|
674
|
+
return r.current && (c = e.registerContainerElement(r.current)), () => c == null ? void 0 : c.dispose();
|
|
676
675
|
}, [e]);
|
|
677
676
|
const s = H(null), a = p(
|
|
678
|
-
(
|
|
677
|
+
(c) => n.setContextValue(De, c),
|
|
679
678
|
[n]
|
|
680
|
-
),
|
|
681
|
-
(
|
|
679
|
+
), d = p(
|
|
680
|
+
(c) => n.setContextValue(Fe, c),
|
|
682
681
|
[n]
|
|
683
682
|
);
|
|
684
683
|
return A(() => {
|
|
685
684
|
var _;
|
|
686
|
-
const
|
|
687
|
-
var
|
|
688
|
-
|
|
685
|
+
const c = yt(document, "focusin").subscribe((u) => {
|
|
686
|
+
var h;
|
|
687
|
+
u.target && ((h = r.current) != null && h.contains(u.target)) ? a(!0) : a(!1), !s.current || !s.current.selectHasFocus() ? d(!0) : d(!1);
|
|
689
688
|
});
|
|
690
|
-
return (_ = s.current) == null || _.focus(), a(!0),
|
|
691
|
-
|
|
689
|
+
return (_ = s.current) == null || _.focus(), a(!0), d(!0), () => {
|
|
690
|
+
c.unsubscribe(), a(!1);
|
|
692
691
|
};
|
|
693
|
-
}, [a,
|
|
692
|
+
}, [a, d]), /* @__PURE__ */ o.jsx("div", { className: L.findReplaceDialogContainer, ref: r, children: i.replaceRevealed ? /* @__PURE__ */ o.jsx(Qt, { ref: s }) : /* @__PURE__ */ o.jsx(Zt, { ref: s }) });
|
|
694
693
|
}
|
|
695
694
|
function ei(t) {
|
|
696
695
|
const e = t.getCurrentLocale();
|
|
@@ -795,17 +794,17 @@ const di = {
|
|
|
795
794
|
}
|
|
796
795
|
}
|
|
797
796
|
};
|
|
798
|
-
var
|
|
799
|
-
for (var r = i > 1 ? void 0 : i ?
|
|
797
|
+
var ui = Object.defineProperty, hi = Object.getOwnPropertyDescriptor, fi = (t, e, n, i) => {
|
|
798
|
+
for (var r = i > 1 ? void 0 : i ? hi(e, n) : e, s = t.length - 1, a; s >= 0; s--)
|
|
800
799
|
(a = t[s]) && (r = (i ? a(e, n, r) : a(r)) || r);
|
|
801
|
-
return i && r &&
|
|
800
|
+
return i && r && ui(e, n, r), r;
|
|
802
801
|
}, S = (t, e) => (n, i) => e(n, i, t);
|
|
803
802
|
const fe = "DESKTOP_FIND_REPLACE_DIALOG", we = 350, pi = 20, _i = -90;
|
|
804
|
-
let j = class extends
|
|
805
|
-
constructor(e, n, i, r, s, a,
|
|
803
|
+
let j = class extends ut {
|
|
804
|
+
constructor(e, n, i, r, s, a, d, c, _, u) {
|
|
806
805
|
super();
|
|
807
|
-
|
|
808
|
-
this._univerInstanceService = e, this._menuManagerService = n, this._shortcutService = i, this._commandService = r, this._findReplaceService = s, this._dialogService = a, this._layoutService =
|
|
806
|
+
l(this, "_closingListenerDisposable");
|
|
807
|
+
this._univerInstanceService = e, this._menuManagerService = n, this._shortcutService = i, this._commandService = r, this._findReplaceService = s, this._dialogService = a, this._layoutService = d, this._localeService = c, this._componentManager = _, this._injector = u, this._initCommands(), this._initUI(), this._initShortcuts();
|
|
809
808
|
}
|
|
810
809
|
dispose() {
|
|
811
810
|
var e;
|
|
@@ -879,7 +878,7 @@ var mi = Object.defineProperty, vi = Object.getOwnPropertyDescriptor, Si = (t, e
|
|
|
879
878
|
}, pe = (t, e) => (n, i) => e(n, i, t);
|
|
880
879
|
const Ci = "UNIVER_FIND_REPLACE_PLUGIN";
|
|
881
880
|
var V;
|
|
882
|
-
let _e = (V = class extends
|
|
881
|
+
let _e = (V = class extends ht {
|
|
883
882
|
constructor(t = de, e, n) {
|
|
884
883
|
super(), this._config = t, this._injector = e, this._configService = n;
|
|
885
884
|
const { ...i } = ft(
|
|
@@ -898,7 +897,7 @@ let _e = (V = class extends ut {
|
|
|
898
897
|
onRendered() {
|
|
899
898
|
this._injector.get(j);
|
|
900
899
|
}
|
|
901
|
-
},
|
|
900
|
+
}, l(V, "pluginName", Ci), V);
|
|
902
901
|
_e = Si([
|
|
903
902
|
pe(1, F(Q)),
|
|
904
903
|
pe(2, pt)
|
|
@@ -908,6 +907,8 @@ export {
|
|
|
908
907
|
K as FindDirection,
|
|
909
908
|
Di as FindModel,
|
|
910
909
|
j as FindReplaceController,
|
|
910
|
+
J as FindReplaceModel,
|
|
911
|
+
Gt as FindReplaceState,
|
|
911
912
|
Y as FindScope,
|
|
912
913
|
Ne as GoToNextMatchOperation,
|
|
913
914
|
$e as GoToPreviousMatchOperation,
|
|
@@ -916,5 +917,6 @@ export {
|
|
|
916
917
|
re as OpenReplaceDialogOperation,
|
|
917
918
|
Ee as ReplaceAllMatchesCommand,
|
|
918
919
|
Te as ReplaceCurrentMatchCommand,
|
|
919
|
-
_e as UniverFindReplacePlugin
|
|
920
|
+
_e as UniverFindReplacePlugin,
|
|
921
|
+
ne as createInitFindReplaceState
|
|
920
922
|
};
|
package/lib/types/index.d.ts
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
import './global.css';
|
|
17
17
|
export { UniverFindReplacePlugin } from './plugin';
|
|
18
18
|
export { FindReplaceController } from './controllers/find-replace.controller';
|
|
19
|
-
export type { IFindComplete, IFindMatch, IFindMoveParams, IFindQuery, IFindReplaceProvider, IReplaceAllResult, } from './services/find-replace.service';
|
|
20
|
-
export { FindBy, FindDirection, FindModel, FindScope, IFindReplaceService } from './services/find-replace.service';
|
|
19
|
+
export type { IFindComplete, IFindMatch, IFindMoveParams, IFindQuery, IFindReplaceProvider, IFindReplaceState, IReplaceAllResult, } from './services/find-replace.service';
|
|
20
|
+
export { createInitFindReplaceState, FindBy, FindDirection, FindModel, FindReplaceModel, FindReplaceState, FindScope, IFindReplaceService } from './services/find-replace.service';
|
|
21
21
|
export { ReplaceAllMatchesCommand, ReplaceCurrentMatchCommand } from './commands/commands/replace.command';
|
|
22
22
|
export { GoToNextMatchOperation, GoToPreviousMatchOperation, OpenFindDialogOperation, OpenReplaceDialogOperation } from './commands/operations/find-replace.operation';
|
|
@@ -71,7 +71,6 @@ export interface IFindReplaceService {
|
|
|
71
71
|
/**
|
|
72
72
|
* Register a find replace provider to the service. The provider is the actual bearer to
|
|
73
73
|
* perform the find in different kinds of documents or different environments.
|
|
74
|
-
*
|
|
75
74
|
* @param provider the find replace provider
|
|
76
75
|
*/
|
|
77
76
|
registerFindReplaceProvider(provider: IFindReplaceProvider): IDisposable;
|
|
@@ -81,7 +80,6 @@ export interface IFindReplaceService {
|
|
|
81
80
|
getFindString(): string;
|
|
82
81
|
/**
|
|
83
82
|
* Start a find & replace session.
|
|
84
|
-
*
|
|
85
83
|
* @returns execution result
|
|
86
84
|
*/
|
|
87
85
|
start(revealReplace?: boolean): boolean;
|
|
@@ -107,6 +105,7 @@ export interface IFindReplaceService {
|
|
|
107
105
|
moveToPreviousMatch(): void;
|
|
108
106
|
replace(): Promise<boolean>;
|
|
109
107
|
replaceAll(): Promise<IReplaceAllResult>;
|
|
108
|
+
getProviders(): Set<IFindReplaceProvider>;
|
|
110
109
|
}
|
|
111
110
|
export declare const IFindReplaceService: import('@wendellhu/redi').IdentifierDecorator<IFindReplaceService>;
|
|
112
111
|
/**
|
|
@@ -145,9 +144,9 @@ export declare class FindReplaceModel extends Disposable {
|
|
|
145
144
|
replaceAll(): Promise<IReplaceAllResult>;
|
|
146
145
|
getCurrentMatch(): Nullable<IFindMatch>;
|
|
147
146
|
private _markMatch;
|
|
148
|
-
moveToNextMatch():
|
|
147
|
+
moveToNextMatch(): IFindMatch<unknown> | null | undefined;
|
|
149
148
|
private _moveToNextUnitMatch;
|
|
150
|
-
moveToPreviousMatch():
|
|
149
|
+
moveToPreviousMatch(): IFindMatch<unknown> | null | undefined;
|
|
151
150
|
private _moveToInitialMatch;
|
|
152
151
|
}
|
|
153
152
|
export declare enum FindDirection {
|
|
@@ -185,6 +184,10 @@ export interface IFindReplaceState {
|
|
|
185
184
|
findScope: FindScope;
|
|
186
185
|
findBy: FindBy;
|
|
187
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
*
|
|
189
|
+
*/
|
|
190
|
+
export declare function createInitFindReplaceState(): IFindReplaceState;
|
|
188
191
|
/**
|
|
189
192
|
* This class stores find replace options state. These state are stored
|
|
190
193
|
* here instead of the React component so we can change state from
|
|
@@ -242,6 +245,7 @@ export declare class FindReplaceService extends Disposable implements IFindRepla
|
|
|
242
245
|
get replaceRevealed(): boolean;
|
|
243
246
|
constructor(_injector: Injector, _contextService: IContextService);
|
|
244
247
|
dispose(): void;
|
|
248
|
+
getProviders(): Set<IFindReplaceProvider>;
|
|
245
249
|
getCurrentMatch(): Nullable<IFindMatch>;
|
|
246
250
|
getFindString(): string;
|
|
247
251
|
changeFindString(findString: string): void;
|
package/lib/umd/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(l,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/design"),require("@univerjs/engine-render"),require("react")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/ui","rxjs","@univerjs/design","@univerjs/engine-render","react"],a):(l=typeof globalThis<"u"?globalThis:l||self,a(l.UniverFindReplace={},l.UniverCore,l.UniverUi,l.rxjs,l.UniverDesign,l.UniverEngineRender,l.React))})(this,function(l,a,d,S,_,de,p){"use strict";var gt=Object.defineProperty;var mt=(l,a,d)=>a in l?gt(l,a,{enumerable:!0,configurable:!0,writable:!0,value:d}):l[a]=d;var u=(l,a,d)=>mt(l,typeof a!="symbol"?a+"":a,d);var $;const ue="find-replace.config",z={};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 s in e)Object.prototype.hasOwnProperty.call(e,s)&&(n[s]=e[s])}return n},C.apply(this,arguments)},he=function(n,e){var i={};for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&e.indexOf(t)<0&&(i[t]=n[t]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,t=Object.getOwnPropertySymbols(n);s<t.length;s++)e.indexOf(t[s])<0&&Object.prototype.propertyIsEnumerable.call(n,t[s])&&(i[t[s]]=n[t[s]]);return i},Y=p.forwardRef(function(n,e){var i=n.icon,t=n.id,s=n.className,r=n.extend,o=he(n,["icon","id","className","extend"]),h="univerjs-icon univerjs-icon-".concat(t," ").concat(s||"").trim(),f=p.useRef("_".concat(_e()));return Z(i,"".concat(t),{defIds:i.defIds,idSuffix:f.current},C({ref:e,className:h},o),r)});function Z(n,e,i,t,s){return p.createElement(n.tag,C(C({key:e},fe(n,i,s)),t),(pe(n,i).children||[]).map(function(r,o){return Z(r,"".concat(e,"-").concat(n.tag,"-").concat(o),i,void 0,s)}))}function fe(n,e,i){var t=C({},n.attrs);i!=null&&i.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=i.colorChannel1);var s=e.defIds;return!s||s.length===0||(n.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+e.idSuffix),Object.entries(t).forEach(function(r){var o=r[0],h=r[1];typeof h=="string"&&(t[o]=h.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)?C(C({},n),{children:n.children.map(function(s){return typeof s.attrs.id=="string"&&t&&t.indexOf(s.attrs.id)>-1?C(C({},s),{attrs:C(C({},s.attrs),{id:s.attrs.id+e.idSuffix})}):s})}):n}function _e(){return Math.random().toString(36).substring(2,8)}Y.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"}}]}]},Q=p.forwardRef(function(n,e){return p.createElement(Y,Object.assign({},n,{id:"search-single-16",ref:e,icon:ge}))});Q.displayName="SearchSingle16";const X="FIND_REPLACE_INPUT_FOCUS",q="FIND_REPLACE_DIALOG_FOCUS",ee="FIND_REPLACE_REPLACE_REVEALED";var me=Object.defineProperty,ve=Object.getOwnPropertyDescriptor,te=(n,e,i,t)=>{for(var s=t>1?void 0:t?ve(e,i):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(t?o(e,i,s):o(s))||s);return t&&s&&me(e,i,s),s},j=(n,e)=>(i,t)=>e(i,t,n);class Se extends a.Disposable{}const R=a.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 A=class extends a.Disposable{constructor(e,i,t){super();u(this,"currentMatch$",new S.BehaviorSubject(null));u(this,"replaceables$",new S.BehaviorSubject([]));u(this,"_findModels",[]);u(this,"_matchingModel",null);u(this,"_matches",[]);u(this,"_currentSearchingDisposables",null);this._state=e,this._providers=i,this._univerInstanceService=t,this.disposeWithMe(this._state.stateUpdates$.pipe(S.throttleTime(200,void 0,{leading:!0,trailing:!0})).subscribe(async s=>{const r=this._state.state;Ce(s)&&(r.findString!==""&&!r.replaceRevealed?(await this._startSearching(),this._state.changeState({findCompleted:!0})):s.replaceRevealed!==!0&&this._stopSearching())}))}get searched(){return this._findModels.length>0}dispose(){super.dispose(),this._stopSearching(),this.currentMatch$.complete(),this.replaceables$.complete(),this._state.changeState({...U(),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(s=>s.find({findString:this._state.findString,findDirection:this._state.findDirection,findScope:this._state.findScope,findBy:this._state.findBy,replaceRevealed:this._state.replaceRevealed,caseSensitive:this._state.caseSensitive,matchesTheWholeCell:this._state.matchesTheWholeCell})))).flat();this._subscribeToModelsChanges(i);const t=this._matches=i.map(s=>s.getMatches()).flat();return this.replaceables$.next(t.filter(s=>s.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 a.DisposableCollection,t=S.combineLatest(e.map(s=>s.matchesUpdate$)).pipe(S.debounceTime(220)).subscribe(([...s])=>{const r=this._matches=s.flat();r.length?(this._moveToInitialMatch(this._findModels,!0),this._state.changeState({matchesCount:r.length}),this.replaceables$.next(r.filter(o=>o.replaceable))):(this._state.changeState({matchesCount:0,matchesPosition:0}),this.replaceables$.next([]))});e.forEach(s=>i.add(a.toDisposable(s.activelyChangingMatch$.subscribe(r=>{const o=this._matches.findIndex(h=>h===r);this._state.changeState({matchesPosition:o+1})})))),i.add(a.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,s)=>(t.success+=s.success,t.failure+=s.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(s=>s===this._matchingModel);this._moveToNextUnitMatch(t)}}_moveToNextUnitMatch(e){const i=this._findModels.length;for(let t=(e+1)%i;t!==e;){const s=this._findModels[t],r=s.moveToNextMatch({ignoreSelection:!0});if(r){this._matchingModel=s,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(s=>s===i);this.currentMatch$.next(i),this._state.changeState({matchesPosition:t+1})}else{const t=this._findModels.length,s=this._findModels.findIndex(o=>o===this._matchingModel);for(let o=(s-1+t)%t;o!==s;){const h=this._findModels[o],f=h.moveToPreviousMatch({ignoreSelection:!0});if(f){this._matchingModel=h,this._markMatch(f);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 s=e.findIndex(o=>o.unitId===t);if(s!==-1){this._matchingModel=e[s];const o=this._matchingModel.moveToNextMatch({stayIfOnMatch:!0,noFocus:i});if(o)return this._markMatch(o),s}return this._moveToNextUnitMatch(s),0}};A=te([j(2,a.IUniverInstanceService)],A);var T=(n=>(n.ROW="row",n.COLUMN="column",n))(T||{}),O=(n=>(n.VALUE="value",n.FORMULA="formula",n))(O||{}),P=(n=>(n.SUBUNIT="subunit",n.UNIT="unit",n))(P||{});function U(){return{caseSensitive:!1,findBy:"value",findCompleted:!1,findDirection:"row",findScope:"subunit",findString:"",inputtingFindString:"",matchesCount:0,matchesPosition:0,matchesTheWholeCell:!1,replaceRevealed:!1,replaceString:"",revealed:!0}}class Re{constructor(){u(this,"_stateUpdates$",new S.Subject);u(this,"stateUpdates$",this._stateUpdates$.asObservable());u(this,"_state$",new S.BehaviorSubject(U()));u(this,"state$",this._state$.asObservable());u(this,"_findString","");u(this,"_inputtingFindString","");u(this,"_replaceString","");u(this,"_revealed",!1);u(this,"_replaceRevealed",!1);u(this,"_matchesPosition",0);u(this,"_matchesCount",0);u(this,"_caseSensitive",!0);u(this,"_matchesTheWholeCell",!1);u(this,"_findDirection","row");u(this,"_findScope","subunit");u(this,"_findBy","value");u(this,"_findCompleted",!1)}get state(){return this._state$.getValue()}get inputtingFindString(){return this._inputtingFindString}get findString(){return this._findString}get revealed(){return this._revealed}get replaceRevealed(){return this._replaceRevealed}get matchesPosition(){return this._matchesPosition}get matchesCount(){return this._matchesCount}get replaceString(){return this._replaceString}get caseSensitive(){return this._caseSensitive}get matchesTheWholeCell(){return this._matchesTheWholeCell}get findDirection(){return this._findDirection}get findScope(){return this._findScope}get findBy(){return this._findBy}get findCompleted(){return this._findCompleted}changeState(e){let i=!1;const 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 a.Disposable{constructor(e,i){super();u(this,"_providers",new Set);u(this,"_state",new Re);u(this,"_model");u(this,"_currentMatch$",new S.BehaviorSubject(null));u(this,"currentMatch$",this._currentMatch$.asObservable());u(this,"_replaceables$",new S.BehaviorSubject([]));u(this,"replaceables$",this._replaceables$.asObservable());u(this,"_focusSignal$",new S.Subject);u(this,"focusSignal$",this._focusSignal$.asObservable());this._injector=e,this._contextService=i}get stateUpdates$(){return this._state.stateUpdates$}get state$(){return this._state.state$}get revealed(){return this._state.revealed}get replaceRevealed(){return this._state.replaceRevealed}dispose(){super.dispose(),this._currentMatch$.next(null),this._currentMatch$.complete(),this._replaceables$.next([]),this._replaceables$.complete(),this._focusSignal$.complete()}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(A,this._state,this._providers),this._model.currentMatch$.subscribe(t=>this._currentMatch$.next(t)),this._model.replaceables$.subscribe(t=>this._replaceables$.next(t));const i=U();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),a.toDisposable(()=>this._providers.delete(e))}_toggleRevealReplace(e){this._contextService.setContextValue(ee,e)}_toggleDisplayRawFormula(e){this._contextService.setContextValue(de.RENDER_RAW_FORMULA_KEY,e)}};w=te([j(0,a.Inject(a.Injector)),j(1,a.IContextService)],w);const B={id:"ui.command.replace-current-match",type:a.CommandType.COMMAND,handler:n=>n.get(R).replace()},be="CONFIRM_REPLACE_ALL",k={id:"ui.command.replace-all-matches",type:a.CommandType.COMMAND,handler:async n=>{const e=n.get(d.IConfirmService),i=n.get(a.LocaleService),t=n.get(d.IMessageService);if(!await e.confirm({id:be,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:h}=r;return h>0?(o===0?t.show({type:_.MessageType.Error,content:i.t("find-replace.replace.all-failure")}):t.show({type:_.MessageType.Warning,content:i.t("find-replace.replace.partial-success",`${o}`,`${h}`)}),!1):(t.show({type:_.MessageType.Success,content:i.t("find-replace.replace.all-success",`${o}`)}),!0)}},F={id:"ui.operation.open-find-dialog",type:a.CommandType.OPERATION,handler:n=>{const e=n.get(R);return e.revealed?e.focusFindInput():e.start(),!0}},E={id:"ui.operation.open-replace-dialog",type:a.CommandType.OPERATION,handler:n=>{const e=n.get(R);return e.revealed?e.replaceRevealed?e.focusFindInput():e.revealReplace():e.start(!0),!0}},W={type:a.CommandType.OPERATION,id:"ui.operation.go-to-next-match",handler:n=>(n.get(R).moveToNextMatch(),!0)},G={type:a.CommandType.OPERATION,id:"ui.operation.go-to-previous-match",handler:n=>(n.get(R).moveToPreviousMatch(),!0)};var V={exports:{}},D={};/**
|
|
1
|
+
(function(l,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("@univerjs/core"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/design"),require("@univerjs/engine-render"),require("react")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/ui","rxjs","@univerjs/design","@univerjs/engine-render","react"],r):(l=typeof globalThis<"u"?globalThis:l||self,r(l.UniverFindReplace={},l.UniverCore,l.UniverUi,l.rxjs,l.UniverDesign,l.UniverEngineRender,l.React))})(this,function(l,r,h,C,_,de,p){"use strict";var _t=Object.defineProperty;var gt=(l,r,h)=>r in l?_t(l,r,{enumerable:!0,configurable:!0,writable:!0,value:h}):l[r]=h;var f=(l,r,h)=>gt(l,typeof r!="symbol"?r+"":r,h);var K;const ue="find-replace.config",J={};var R=function(){return R=Object.assign||function(n){for(var e,i=1,t=arguments.length;i<t;i++){e=arguments[i];for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&(n[s]=e[s])}return n},R.apply(this,arguments)},he=function(n,e){var i={};for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&e.indexOf(t)<0&&(i[t]=n[t]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,t=Object.getOwnPropertySymbols(n);s<t.length;s++)e.indexOf(t[s])<0&&Object.prototype.propertyIsEnumerable.call(n,t[s])&&(i[t[s]]=n[t[s]]);return i},z=p.forwardRef(function(n,e){var i=n.icon,t=n.id,s=n.className,a=n.extend,o=he(n,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(t," ").concat(s||"").trim(),u=p.useRef("_".concat(_e()));return Y(i,"".concat(t),{defIds:i.defIds,idSuffix:u.current},R({ref:e,className:c},o),a)});function Y(n,e,i,t,s){return p.createElement(n.tag,R(R({key:e},fe(n,i,s)),t),(pe(n,i).children||[]).map(function(a,o){return Y(a,"".concat(e,"-").concat(n.tag,"-").concat(o),i,void 0,s)}))}function fe(n,e,i){var t=R({},n.attrs);i!=null&&i.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=i.colorChannel1);var s=e.defIds;return!s||s.length===0||(n.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+e.idSuffix),Object.entries(t).forEach(function(a){var o=a[0],c=a[1];typeof c=="string"&&(t[o]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),t}function pe(n,e){var i,t=e.defIds;return!t||t.length===0?n:n.tag==="defs"&&(!((i=n.children)===null||i===void 0)&&i.length)?R(R({},n),{children:n.children.map(function(s){return typeof s.attrs.id=="string"&&t&&t.indexOf(s.attrs.id)>-1?R(R({},s),{attrs:R(R({},s.attrs),{id:s.attrs.id+e.idSuffix})}):s})}):n}function _e(){return Math.random().toString(36).substring(2,8)}z.displayName="UniverIcon";var ge={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_217_40",style:{maskType:"alpha"},width:17,height:17,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#D9D9D9",d:"M0.9 0.09H16.9V16.09H0.9z"}}]},{tag:"g",attrs:{mask:"url(#mask0_217_40)"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.39551 7.37266C2.39551 4.18105 4.98281 1.59375 8.17441 1.59375C11.366 1.59375 13.9533 4.18105 13.9533 7.37266C13.9533 8.72342 13.4898 9.96603 12.7133 10.95L15.1964 13.4331C15.4619 13.6986 15.4619 14.1291 15.1964 14.3946C14.9309 14.6601 14.5004 14.6601 14.2349 14.3946L11.7518 11.9115C10.7678 12.6881 9.52525 13.1516 8.17441 13.1516C4.98281 13.1516 2.39551 10.5642 2.39551 7.37266ZM8.17441 2.95349C5.73378 2.95349 3.75525 4.93202 3.75525 7.37266C3.75525 9.81333 5.73378 11.7918 8.17441 11.7918C10.6151 11.7918 12.5936 9.81333 12.5936 7.37266C12.5936 4.93202 10.6151 2.95349 8.17441 2.95349Z",fillRule:"evenodd",clipRule:"evenodd"}}]}]},Z=p.forwardRef(function(n,e){return p.createElement(z,Object.assign({},n,{id:"search-single-16",ref:e,icon:ge}))});Z.displayName="SearchSingle16";const Q="FIND_REPLACE_INPUT_FOCUS",X="FIND_REPLACE_DIALOG_FOCUS",q="FIND_REPLACE_REPLACE_REVEALED";var me=Object.defineProperty,ve=Object.getOwnPropertyDescriptor,ee=(n,e,i,t)=>{for(var s=t>1?void 0:t?ve(e,i):e,a=n.length-1,o;a>=0;a--)(o=n[a])&&(s=(t?o(e,i,s):o(s))||s);return t&&s&&me(e,i,s),s},A=(n,e)=>(i,t)=>e(i,t,n);class Se extends r.Disposable{}const b=r.createIdentifier("find-replace.service");function Ce(n){return typeof n.findString<"u"||typeof n.inputtingFindString<"u"||typeof n.findDirection<"u"||typeof n.matchesTheWholeCell<"u"||typeof n.caseSensitive<"u"||typeof n.findScope<"u"||typeof n.findBy<"u"}l.FindReplaceModel=class extends r.Disposable{constructor(i,t,s){super();f(this,"currentMatch$",new C.BehaviorSubject(null));f(this,"replaceables$",new C.BehaviorSubject([]));f(this,"_findModels",[]);f(this,"_matchingModel",null);f(this,"_matches",[]);f(this,"_currentSearchingDisposables",null);this._state=i,this._providers=t,this._univerInstanceService=s,this.disposeWithMe(this._state.stateUpdates$.pipe(C.throttleTime(200,void 0,{leading:!0,trailing:!0})).subscribe(async a=>{const o=this._state.state;Ce(a)&&(o.findString!==""&&!o.replaceRevealed?(await this._startSearching(),this._state.changeState({findCompleted:!0})):a.replaceRevealed!==!0&&this._stopSearching())}))}get searched(){return this._findModels.length>0}dispose(){super.dispose(),this._stopSearching(),this.currentMatch$.complete(),this.replaceables$.complete(),this._state.changeState({...E(),revealed:!1})}async start(){if(!this._state.findString)return{results:[]};const i=await this._startSearching();return this._state.changeState({findCompleted:!0}),i}async _startSearching(){if(!this._state.findString)return{results:[]};const i=Array.from(this._providers),t=this._findModels=(await Promise.all(i.map(a=>a.find({findString:this._state.findString,findDirection:this._state.findDirection,findScope:this._state.findScope,findBy:this._state.findBy,replaceRevealed:this._state.replaceRevealed,caseSensitive:this._state.caseSensitive,matchesTheWholeCell:this._state.matchesTheWholeCell})))).flat();this._subscribeToModelsChanges(t);const s=this._matches=t.map(a=>a.getMatches()).flat();return this.replaceables$.next(s.filter(a=>a.replaceable)),s.length?(this._moveToInitialMatch(t),this._state.changeState({matchesCount:s.length}),{results:s}):(this._state.changeState({matchesCount:0,matchesPosition:0}),{results:[]})}_stopSearching(){var i;this._providers.forEach(t=>t.terminate()),this._findModels=[],this._matches=[],this._matchingModel=null,(i=this._currentSearchingDisposables)==null||i.dispose(),this._currentSearchingDisposables=null,this.currentMatch$.next(null),this.replaceables$.next([]),this._state.changeState({findCompleted:!1,matchesCount:0,matchesPosition:0})}_subscribeToModelsChanges(i){const t=this._currentSearchingDisposables=new r.DisposableCollection,s=C.combineLatest(i.map(a=>a.matchesUpdate$)).pipe(C.debounceTime(220)).subscribe(([...a])=>{const o=this._matches=a.flat();o.length?(this._moveToInitialMatch(this._findModels,!0),this._state.changeState({matchesCount:o.length}),this.replaceables$.next(o.filter(c=>c.replaceable))):(this._state.changeState({matchesCount:0,matchesPosition:0}),this.replaceables$.next([]))});i.forEach(a=>t.add(r.toDisposable(a.activelyChangingMatch$.subscribe(o=>{const c=this._matches.findIndex(u=>u===o);this._state.changeState({matchesPosition:c+1})})))),t.add(r.toDisposable(s))}async replace(){return this._matchingModel?this._matchingModel.replace(this._state.replaceString):!1}async replaceAll(){const i=await Promise.all(this._findModels.map(t=>t.replaceAll(this._state.replaceString))).then(t=>t.reduce((s,a)=>(s.success+=a.success,s.failure+=a.failure,s),{success:0,failure:0}));return i.failure===0&&this._stopSearching(),i}getCurrentMatch(){return this._state.matchesPosition>0?this._matches[this._state.matchesPosition-1]:null}_markMatch(i){const t=this._matches.findIndex(s=>s===i);this.currentMatch$.next(i),this._state.changeState({matchesPosition:t+1})}moveToNextMatch(){if(!this._matchingModel)return;const i=this._findModels.length===1,t=this._matchingModel.moveToNextMatch({loop:i});if(t)return this._markMatch(t),t;{const s=this._findModels.findIndex(a=>a===this._matchingModel);return this._moveToNextUnitMatch(s)}}_moveToNextUnitMatch(i){const t=this._findModels.length;for(let s=(i+1)%t;s!==i;){const a=this._findModels[s],o=a.moveToNextMatch({ignoreSelection:!0});if(o)return this._matchingModel=a,this._markMatch(o),o;s=(s+1)%t}if(this._matchingModel){const s=this._matchingModel.moveToNextMatch({ignoreSelection:!0});return s&&this._markMatch(s),s}}moveToPreviousMatch(){if(!this._matchingModel)return;const i=this._findModels.length===1,t=this._matchingModel.moveToPreviousMatch({loop:i});if(t){const s=this._matches.findIndex(a=>a===t);return this.currentMatch$.next(t),this._state.changeState({matchesPosition:s+1}),t}else{const s=this._findModels.length,a=this._findModels.findIndex(c=>c===this._matchingModel);for(let c=(a-1+s)%s;c!==a;){const u=this._findModels[c],v=u.moveToPreviousMatch({ignoreSelection:!0});if(v)return this._matchingModel=u,this._markMatch(v),v;c=(c-1)%s}const o=this._matchingModel.moveToPreviousMatch({ignoreSelection:!0});return o&&this._markMatch(o),o}}_moveToInitialMatch(i,t=!1){var o;const s=(o=this._univerInstanceService.getFocusedUnit())==null?void 0:o.getUnitId();if(!s)return-1;const a=i.findIndex(c=>c.unitId===s);if(a!==-1){this._matchingModel=i[a];const c=this._matchingModel.moveToNextMatch({stayIfOnMatch:!0,noFocus:t});if(c)return this._markMatch(c),a}return this._moveToNextUnitMatch(a),0}},l.FindReplaceModel=ee([A(2,r.IUniverInstanceService)],l.FindReplaceModel);var x=(n=>(n.ROW="row",n.COLUMN="column",n))(x||{}),O=(n=>(n.VALUE="value",n.FORMULA="formula",n))(O||{}),P=(n=>(n.SUBUNIT="subunit",n.UNIT="unit",n))(P||{});function E(){return{caseSensitive:!1,findBy:"value",findCompleted:!1,findDirection:"row",findScope:"subunit",findString:"",inputtingFindString:"",matchesCount:0,matchesPosition:0,matchesTheWholeCell:!1,replaceRevealed:!1,replaceString:"",revealed:!0}}class te{constructor(){f(this,"_stateUpdates$",new C.Subject);f(this,"stateUpdates$",this._stateUpdates$.asObservable());f(this,"_state$",new C.BehaviorSubject(E()));f(this,"state$",this._state$.asObservable());f(this,"_findString","");f(this,"_inputtingFindString","");f(this,"_replaceString","");f(this,"_revealed",!1);f(this,"_replaceRevealed",!1);f(this,"_matchesPosition",0);f(this,"_matchesCount",0);f(this,"_caseSensitive",!0);f(this,"_matchesTheWholeCell",!1);f(this,"_findDirection","row");f(this,"_findScope","subunit");f(this,"_findBy","value");f(this,"_findCompleted",!1)}get state(){return this._state$.getValue()}get inputtingFindString(){return this._inputtingFindString}get findString(){return this._findString}get revealed(){return this._revealed}get replaceRevealed(){return this._replaceRevealed}get matchesPosition(){return this._matchesPosition}get matchesCount(){return this._matchesCount}get replaceString(){return this._replaceString}get caseSensitive(){return this._caseSensitive}get matchesTheWholeCell(){return this._matchesTheWholeCell}get findDirection(){return this._findDirection}get findScope(){return this._findScope}get findBy(){return this._findBy}get findCompleted(){return this._findCompleted}changeState(e){let i=!1;const t={};typeof e.findString<"u"&&e.findString!==this._findString&&(this._findString=e.findString,t.findString=this._findString,i=!0),typeof e.revealed<"u"&&e.revealed!==this._revealed&&(this._revealed=e.revealed,t.revealed=e.revealed,i=!0),typeof e.replaceRevealed<"u"&&e.replaceRevealed!==this._replaceRevealed&&(this._replaceRevealed=e.replaceRevealed,t.replaceRevealed=e.replaceRevealed,i=!0),typeof e.replaceString<"u"&&e.replaceString!==this._replaceString&&(this._replaceString=e.replaceString,t.replaceString=e.replaceString,i=!0),typeof e.matchesCount<"u"&&e.matchesCount!==this._matchesCount&&(this._matchesCount=e.matchesCount,t.matchesCount=e.matchesCount,i=!0),typeof e.matchesPosition<"u"&&e.matchesPosition!==this._matchesPosition&&(this._matchesPosition=e.matchesPosition,t.matchesPosition=e.matchesPosition,i=!0),typeof e.findBy<"u"&&e.findBy!==this._findBy&&(this._findBy=e.findBy,t.findBy=e.findBy,i=!0),typeof e.findScope<"u"&&e.findScope!==this._findScope&&(this._findScope=e.findScope,t.findScope=e.findScope,i=!0),typeof e.findDirection<"u"&&e.findDirection!==this._findDirection&&(this._findDirection=e.findDirection,t.findDirection=e.findDirection,i=!0),typeof e.caseSensitive<"u"&&e.caseSensitive!==this._caseSensitive&&(this._caseSensitive=e.caseSensitive,t.caseSensitive=e.caseSensitive,i=!0),typeof e.matchesTheWholeCell<"u"&&e.matchesTheWholeCell!==this._matchesTheWholeCell&&(this._matchesTheWholeCell=e.matchesTheWholeCell,t.matchesTheWholeCell=e.matchesTheWholeCell,i=!0),typeof e.inputtingFindString<"u"&&e.inputtingFindString!==this._inputtingFindString&&(this._inputtingFindString=e.inputtingFindString,t.inputtingFindString=e.inputtingFindString,i=!0),typeof e.findCompleted<"u"&&e.findCompleted!==this._findCompleted&&(this._findCompleted=e.findCompleted,t.findCompleted=e.findCompleted,i=!0),i&&(this._state$.next({caseSensitive:this._caseSensitive,findBy:this._findBy,findCompleted:this._findCompleted,findDirection:this._findDirection,findScope:this._findScope,findString:this._findString,inputtingFindString:this._inputtingFindString,matchesCount:this._matchesCount,matchesPosition:this._matchesPosition,matchesTheWholeCell:this._matchesTheWholeCell,replaceRevealed:this._replaceRevealed,revealed:this._revealed}),this._stateUpdates$.next(t))}}let U=class extends r.Disposable{constructor(e,i){super();f(this,"_providers",new Set);f(this,"_state",new te);f(this,"_model");f(this,"_currentMatch$",new C.BehaviorSubject(null));f(this,"currentMatch$",this._currentMatch$.asObservable());f(this,"_replaceables$",new C.BehaviorSubject([]));f(this,"replaceables$",this._replaceables$.asObservable());f(this,"_focusSignal$",new C.Subject);f(this,"focusSignal$",this._focusSignal$.asObservable());this._injector=e,this._contextService=i}get stateUpdates$(){return this._state.stateUpdates$}get state$(){return this._state.state$}get revealed(){return this._state.revealed}get replaceRevealed(){return this._state.replaceRevealed}dispose(){super.dispose(),this._currentMatch$.next(null),this._currentMatch$.complete(),this._replaceables$.next([]),this._replaceables$.complete(),this._focusSignal$.complete()}getProviders(){return this._providers}getCurrentMatch(){var e;return(e=this._model)==null?void 0:e.getCurrentMatch()}getFindString(){return this._state.findString}changeFindString(e){this._state.changeState({findString:e})}focusFindInput(){this._focusSignal$.next()}changeInputtingFindString(e){e?this._state.changeState({inputtingFindString:e}):this._state.changeState({inputtingFindString:"",findString:""})}changeReplaceString(e){this._state.changeState({replaceString:e})}changeMatchesTheWholeCell(e){this._state.changeState({matchesTheWholeCell:e})}changeCaseSensitive(e){this._state.changeState({caseSensitive:e})}changeFindBy(e){this._state.changeState({findBy:e}),this._toggleDisplayRawFormula(e==="formula")}changeFindScope(e){this._state.changeState({findScope:e})}changeFindDirection(e){this._state.changeState({findDirection:e})}moveToNextMatch(){this._model&&(this._state.replaceRevealed&&!this._model.searched?(this._state.changeState({findString:this._state.inputtingFindString}),this._model.start()):this._model.moveToNextMatch(),this._focusSignal$.next())}moveToPreviousMatch(){this._model&&(this._state.replaceRevealed&&!this._model.searched?(this._state.changeState({findString:this._state.inputtingFindString}),this._model.start()):this._model.moveToPreviousMatch(),this._focusSignal$.next())}async replace(){return this._model?this._model.replace():!1}async replaceAll(){if(!this._model)throw new Error("[FindReplaceService] replaceAll: model is not initialized!");return this._model.replaceAll()}revealReplace(){this._state.changeState({replaceRevealed:!0,inputtingFindString:this._state.findString}),this._toggleRevealReplace(!0)}start(e=!1){if(this._providers.size===0)return!1;this._model=this._injector.createInstance(l.FindReplaceModel,this._state,this._providers),this._model.currentMatch$.subscribe(t=>this._currentMatch$.next(t)),this._model.replaceables$.subscribe(t=>this._replaceables$.next(t));const i=E();return e&&(i.replaceRevealed=!0),this._state.changeState(i),this._toggleRevealReplace(e),!0}find(){var e;(e=this._model)==null||e.start()}terminate(){var e;(e=this._model)==null||e.dispose(),this._model=null,this._toggleDisplayRawFormula(!1),this._toggleRevealReplace(!1)}registerFindReplaceProvider(e){return this._providers.add(e),r.toDisposable(()=>this._providers.delete(e))}_toggleRevealReplace(e){this._contextService.setContextValue(q,e)}_toggleDisplayRawFormula(e){this._contextService.setContextValue(de.RENDER_RAW_FORMULA_KEY,e)}};U=ee([A(0,r.Inject(r.Injector)),A(1,r.IContextService)],U);const w={id:"ui.command.replace-current-match",type:r.CommandType.COMMAND,handler:n=>n.get(b).replace()},Re="CONFIRM_REPLACE_ALL",B={id:"ui.command.replace-all-matches",type:r.CommandType.COMMAND,handler:async n=>{const e=n.get(h.IConfirmService),i=n.get(r.LocaleService),t=n.get(h.IMessageService);if(!await e.confirm({id:Re,title:{title:i.t("find-replace.replace.confirm.title")},cancelText:i.t("button.cancel"),confirmText:i.t("button.confirm")}))return!1;const a=await n.get(b).replaceAll(),{success:o,failure:c}=a;return c>0?(o===0?t.show({type:_.MessageType.Error,content:i.t("find-replace.replace.all-failure")}):t.show({type:_.MessageType.Warning,content:i.t("find-replace.replace.partial-success",`${o}`,`${c}`)}),!1):(t.show({type:_.MessageType.Success,content:i.t("find-replace.replace.all-success",`${o}`)}),!0)}},F={id:"ui.operation.open-find-dialog",type:r.CommandType.OPERATION,handler:n=>{const e=n.get(b);return e.revealed?e.focusFindInput():e.start(),!0}},N={id:"ui.operation.open-replace-dialog",type:r.CommandType.OPERATION,handler:n=>{const e=n.get(b);return e.revealed?e.replaceRevealed?e.focusFindInput():e.revealReplace():e.start(!0),!0}},k={type:r.CommandType.OPERATION,id:"ui.operation.go-to-next-match",handler:n=>(n.get(b).moveToNextMatch(),!0)},W={type:r.CommandType.OPERATION,id:"ui.operation.go-to-previous-match",handler:n=>(n.get(b).moveToPreviousMatch(),!0)};var G={exports:{}},D={};/**
|
|
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 ne;function Me(){if(ne)return D;ne=1;var n=p,e=Symbol.for("react.element"),i=Symbol.for("react.fragment"),t=Object.prototype.hasOwnProperty,s=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,r={key:!0,ref:!0,__self:!0,__source:!0};function o(h,f,b){var g,m={},I=null,y=null;b!==void 0&&(I=""+b),f.key!==void 0&&(I=""+f.key),f.ref!==void 0&&(y=f.ref);for(g in f)t.call(f,g)&&!r.hasOwnProperty(g)&&(m[g]=f[g]);if(h&&h.defaultProps)for(g in f=h.defaultProps,f)m[g]===void 0&&(m[g]=f[g]);return{$$typeof:e,type:h,key:I,ref:y,props:m,_owner:s.current}}return D.Fragment=i,D.jsx=o,D.jsxs=o,D}var ie;function ye(){return ie||(ie=1,V.exports=Me()),V.exports}var c=ye();const N={findReplaceDialogContainer:"univer-find-replace-dialog-container",findReplaceExpandContainer:"univer-find-replace-expand-container",buttonText:"univer-button-text",findReplaceButtonsGroup:"univer-find-replace-buttons-group",findReplaceButtonsGroupRight:"univer-find-replace-buttons-group-right"};function se(n){const{findCompleted:e,localeService:i,matchesCount:t,matchesPosition:s,findString:r,findReplaceService:o,onChange:h,...f}=n,g=e&&t===0?i.t("find-replace.dialog.no-result"):t===0?" ":void 0;return c.jsx(_.InputWithSlot,{autoFocus:!0,placeholder:i.t("find-replace.dialog.find-placeholder"),slot:c.jsx(_.Pager,{loop:!0,text:g,value:s,total:t,onChange:m=>{s===t&&m===1?o.moveToNextMatch():s===1&&m===t||m<s?o.moveToPreviousMatch():o.moveToNextMatch()}}),value:r,onChange:m=>h==null?void 0:h(m),...f})}function ae(n,e){const i=p.useCallback(()=>{var s;(s=document.querySelector(".univer-find-input input"))==null||s.focus()},[]),t=p.useCallback(()=>{const s=document.querySelectorAll(".univer-find-replace-dialog-container .univer-select-selection-search-input");return Array.from(s).some(r=>r===document.activeElement)},[]);return p.useImperativeHandle(e,()=>({focus:i,selectHasFocus:t})),p.useEffect(()=>{const s=n.focusSignal$.subscribe(()=>i());return()=>s.unsubscribe()},[n,i]),{focus:i,selectHasFocus:t}}const Ie=p.forwardRef(function(e,i){const t=a.useDependency(a.LocaleService),s=a.useDependency(R),r=a.useDependency(a.ICommandService),o=d.useObservable(s.state$,void 0,!0),{findCompleted:h,findString:f,matchesCount:b,matchesPosition:g}=o,m=p.useCallback(()=>{r.executeCommand(E.id)},[r]),I=p.useCallback(y=>s.changeFindString(y),[s]);return ae(s,i),c.jsxs(c.Fragment,{children:[c.jsx(se,{findCompleted:h,className:"univer-find-input",matchesCount:b,matchesPosition:g,findReplaceService:s,localeService:t,findString:f,onChange:I}),c.jsx("div",{className:N.findReplaceExpandContainer,children:c.jsx(_.Button,{type:"text",size:"small",onClick:m,children:t.t("find-replace.dialog.advanced-finding")})})]})}),Fe=p.forwardRef(function(e,i){const t=a.useDependency(R),s=a.useDependency(a.LocaleService),r=a.useDependency(a.ICommandService),o=a.useDependency(d.IMessageService),h=d.useObservable(t.currentMatch$,void 0,!0),f=d.useObservable(t.replaceables$,void 0,!0),b=d.useObservable(t.state$,void 0,!0),{matchesCount:g,matchesPosition:m,findString:I,inputtingFindString:y,replaceString:Ye,caseSensitive:Ze,matchesTheWholeCell:Qe,findDirection:Xe,findScope:qe,findBy:et,findCompleted:J}=b,tt=y.length===0,nt=g===0||!(h!=null&&h.replaceable),it=f.length===0,st=p.useCallback(v=>t.changeInputtingFindString(v),[t]),at=p.useCallback(v=>t.changeReplaceString(v),[t]),{focus:rt}=ae(t,i),ot=p.useCallback(()=>{I===y?t.moveToNextMatch():(t.changeFindString(y),t.find())},[I,y,t]),ct=p.useCallback(()=>r.executeCommand(B.id),[r]),lt=p.useCallback(async()=>{await r.executeCommand(k.id),rt()},[r]),dt=p.useCallback(v=>{t.changeFindDirection(v)},[t]),ut=p.useCallback(v=>{t.changeFindScope(v)},[t]),ht=p.useCallback(v=>{t.changeFindBy(v)},[t]),ft=xe(s),pt=Te(s),_t=Oe(s);return p.useEffect(()=>{J&&g===0&&o.show({content:s.t("find-replace.dialog.no-match"),type:_.MessageType.Warning,duration:5e3})},[J,g,o,s]),c.jsxs(c.Fragment,{children:[c.jsx(_.FormLayout,{label:s.t("find-replace.dialog.find"),children:c.jsx(se,{findCompleted:J,className:"univer-find-input",matchesCount:g,matchesPosition:m,findReplaceService:t,localeService:s,findString:y,onChange:st})}),c.jsx(_.FormLayout,{label:s.t("find-replace.dialog.replace"),children:c.jsx(_.Input,{placeholder:s.t("find-replace.dialog.replace-placeholder"),value:Ye,onChange:v=>at(v)})}),c.jsx(_.FormLayout,{label:s.t("find-replace.dialog.find-direction.title"),children:c.jsx(_.Select,{value:Xe,options:pt,onChange:dt})}),c.jsx(_.FormDualColumnLayout,{children:c.jsxs(c.Fragment,{children:[c.jsx(_.FormLayout,{label:s.t("find-replace.dialog.find-scope.title"),children:c.jsx(_.Select,{value:qe,options:ft,onChange:ut})}),c.jsx(_.FormLayout,{label:s.t("find-replace.dialog.find-by.title"),children:c.jsx(_.Select,{value:et,options:_t,onChange:ht})})]})}),c.jsx(_.FormDualColumnLayout,{children:c.jsxs(c.Fragment,{children:[c.jsx(_.FormLayout,{children:c.jsx(_.Checkbox,{checked:Ze,onChange:v=>{t.changeCaseSensitive(v)},children:s.t("find-replace.dialog.case-sensitive")})}),c.jsx(_.FormLayout,{children:c.jsx(_.Checkbox,{checked:Qe,onChange:v=>{t.changeMatchesTheWholeCell(v)},children:s.t("find-replace.dialog.match-the-whole-cell")})})]})}),c.jsxs("div",{className:N.findReplaceButtonsGroup,children:[c.jsx(_.Button,{type:"primary",onClick:ot,disabled:tt,children:s.t("find-replace.dialog.find")}),c.jsxs("span",{className:N.findReplaceButtonsGroupRight,children:[c.jsx(_.Button,{disabled:nt,onClick:ct,children:s.t("find-replace.dialog.replace")}),c.jsx(_.Button,{disabled:it,onClick:lt,children:s.t("find-replace.dialog.replace-all")})]})]})]})});function De(){const n=a.useDependency(R),e=a.useDependency(d.ILayoutService),i=a.useDependency(a.IContextService),t=d.useObservable(n.state$,void 0,!0),s=p.useRef(null);p.useEffect(()=>{let f;return s.current&&(f=e.registerContainerElement(s.current)),()=>f==null?void 0:f.dispose()},[e]);const r=p.useRef(null),o=p.useCallback(f=>i.setContextValue(q,f),[i]),h=p.useCallback(f=>i.setContextValue(X,f),[i]);return p.useEffect(()=>{var b;const f=S.fromEvent(document,"focusin").subscribe(g=>{var m;g.target&&((m=s.current)!=null&&m.contains(g.target))?o(!0):o(!1),!r.current||!r.current.selectHasFocus()?h(!0):h(!1)});return(b=r.current)==null||b.focus(),o(!0),h(!0),()=>{f.unsubscribe(),o(!1)}},[o,h]),c.jsx("div",{className:N.findReplaceDialogContainer,ref:s,children:t.replaceRevealed?c.jsx(Fe,{ref:r}):c.jsx(Ie,{ref:r})})}function xe(n){const e=n.getCurrentLocale();return p.useMemo(()=>[{label:n.t("find-replace.dialog.find-scope.current-sheet"),value:P.SUBUNIT},{label:n.t("find-replace.dialog.find-scope.workbook"),value:P.UNIT}],[e])}function Te(n){const e=n.getCurrentLocale();return p.useMemo(()=>[{label:n.t("find-replace.dialog.find-direction.row"),value:T.ROW},{label:n.t("find-replace.dialog.find-direction.column"),value:T.COLUMN}],[e])}function Oe(n){const e=n.getCurrentLocale();return p.useMemo(()=>[{label:n.t("find-replace.dialog.find-by.value"),value:O.VALUE},{label:n.t("find-replace.dialog.find-by.formula"),value:O.FORMULA}],[e])}function x(n){return n.getContextValue(q)}function Pe(n){return n.getContextValue(ee)}function re(n){return n.getContextValue(X)}const L="7_find-replace-shortcuts";function H(n){return n.getContextValue(a.FOCUSING_SHEET)}function K(n){return!n.getContextValue(a.EDITOR_ACTIVATED)}const Ee={id:F.id,description:"find-replace.shortcut.open-find-dialog",binding:d.KeyCode.F|d.MetaKeys.CTRL_COMMAND,group:L,preconditions(n){return!x(n)&&H(n)&&K(n)}},Ne={id:F.id,description:"find-replace.shortcut.open-find-dialog",binding:d.KeyCode.F|d.MetaKeys.CTRL_COMMAND,mac:d.KeyCode.F|d.MetaKeys.MAC_CTRL,preconditions(n){return!x(n)&&H(n)&&K(n)}},Le={id:E.id,description:"find-replace.shortcut.open-replace-dialog",binding:d.KeyCode.H|d.MetaKeys.CTRL_COMMAND,mac:d.KeyCode.H|d.MetaKeys.MAC_CTRL,group:L,preconditions(n){return H(n)&&K(n)&&(!x(n)||!Pe(n))}},je={id:W.id,description:"find-replace.shortcut.go-to-next-match",binding:d.KeyCode.ENTER,group:L,priority:1e3,preconditions(n){return re(n)&&x(n)}},Ae={id:G.id,description:"find-replace.shortcut.go-to-previous-match",binding:d.KeyCode.ENTER|d.MetaKeys.SHIFT,group:L,priority:1e3,preconditions(n){return re(n)&&x(n)}};function Ue(n){const e=n.get(a.IContextService);return{id:F.id,icon:"SearchIcon",tooltip:"find-replace.toolbar",type:d.MenuItemType.BUTTON,hidden$:d.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:S.combineLatest([e.subscribeContextValue$(a.EDITOR_ACTIVATED),e.subscribeContextValue$(a.FOCUSING_SHEET)]).pipe(S.map(([i,t])=>i||!t))}}const we={[d.RibbonStartGroup.OTHERS]:{[F.id]:{order:2,menuItemFactory:Ue}}};var Be=Object.defineProperty,ke=Object.getOwnPropertyDescriptor,We=(n,e,i,t)=>{for(var s=t>1?void 0:t?ke(e,i):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(t?o(e,i,s):o(s))||s);return t&&s&&Be(e,i,s),s},M=(n,e)=>(i,t)=>e(i,t,n);const oe="DESKTOP_FIND_REPLACE_DIALOG",ce=350,Ge=20,Ve=-90;l.FindReplaceController=class extends a.RxDisposable{constructor(i,t,s,r,o,h,f,b,g,m){super();u(this,"_closingListenerDisposable");this._univerInstanceService=i,this._menuManagerService=t,this._shortcutService=s,this._commandService=r,this._findReplaceService=o,this._dialogService=h,this._layoutService=f,this._localeService=b,this._componentManager=g,this._injector=m,this._initCommands(),this._initUI(),this._initShortcuts()}dispose(){var i;super.dispose(),(i=this._closingListenerDisposable)==null||i.dispose(),this._closingListenerDisposable=null}_initCommands(){[F,E,W,G,k,B].forEach(i=>{this.disposeWithMe(this._commandService.registerCommand(i))})}_initShortcuts(){[Le,Ee,Ne,Ae,je].forEach(i=>this.disposeWithMe(this._shortcutService.registerShortcut(i)))}_initUI(){this.disposeWithMe(this._componentManager.register("FindReplaceDialog",De)),this.disposeWithMe(this._componentManager.register("SearchIcon",Q)),this._menuManagerService.mergeMenu(we),this._findReplaceService.stateUpdates$.pipe(S.takeUntil(this.dispose$)).subscribe(i=>{i.revealed===!0&&this._openPanel()})}_openPanel(){this._dialogService.open({id:oe,draggable:!0,width:ce,title:{title:this._localeService.t("find-replace.dialog.title")},children:{label:"FindReplaceDialog"},destroyOnClose:!0,defaultPosition:He(),preservePositionOnDestroy:!0,onClose:()=>this.closePanel()}),this._closingListenerDisposable=a.toDisposable(this._univerInstanceService.focused$.pipe(S.takeUntil(this.dispose$)).subscribe(i=>{(!i||!this._univerInstanceService.getUniverSheetInstance(i))&&this.closePanel()}))}closePanel(){this._closingListenerDisposable&&(this._closingListenerDisposable.dispose(),this._closingListenerDisposable=null,this._dialogService.close(oe),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus()))}},l.FindReplaceController=We([M(0,a.IUniverInstanceService),M(1,d.IMenuManagerService),M(2,d.IShortcutService),M(3,a.ICommandService),M(4,R),M(5,d.IDialogService),M(6,d.ILayoutService),M(7,a.Inject(a.LocaleService)),M(8,a.Inject(d.ComponentManager)),M(9,a.Inject(a.Injector))],l.FindReplaceController);function He(){const{innerWidth:n}=window;return{x:(n-ce)/2-Ge,y:Ve}}var Ke=Object.defineProperty,$e=Object.getOwnPropertyDescriptor,Je=(n,e,i,t)=>{for(var s=t>1?void 0:t?$e(e,i):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(t?o(e,i,s):o(s))||s);return t&&s&&Ke(e,i,s),s},le=(n,e)=>(i,t)=>e(i,t,n);const ze="UNIVER_FIND_REPLACE_PLUGIN";l.UniverFindReplacePlugin=($=class extends a.Plugin{constructor(e=z,i,t){super(),this._config=e,this._injector=i,this._configService=t;const{...s}=a.merge({},z,this._config);this._configService.setConfig(ue,s)}onStarting(){[[l.FindReplaceController],[R,{useClass:w}]].forEach(e=>this._injector.add(e))}onRendered(){this._injector.get(l.FindReplaceController)}},u($,"pluginName",ze),$),l.UniverFindReplacePlugin=Je([le(1,a.Inject(a.Injector)),le(2,a.IConfigService)],l.UniverFindReplacePlugin),l.FindBy=O,l.FindDirection=T,l.FindModel=Se,l.FindScope=P,l.GoToNextMatchOperation=W,l.GoToPreviousMatchOperation=G,l.IFindReplaceService=R,l.OpenFindDialogOperation=F,l.OpenReplaceDialogOperation=E,l.ReplaceAllMatchesCommand=k,l.ReplaceCurrentMatchCommand=B,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
|
|
9
|
+
*/var ne;function be(){if(ne)return D;ne=1;var n=p,e=Symbol.for("react.element"),i=Symbol.for("react.fragment"),t=Object.prototype.hasOwnProperty,s=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,a={key:!0,ref:!0,__self:!0,__source:!0};function o(c,u,v){var g,m={},I=null,y=null;v!==void 0&&(I=""+v),u.key!==void 0&&(I=""+u.key),u.ref!==void 0&&(y=u.ref);for(g in u)t.call(u,g)&&!a.hasOwnProperty(g)&&(m[g]=u[g]);if(c&&c.defaultProps)for(g in u=c.defaultProps,u)m[g]===void 0&&(m[g]=u[g]);return{$$typeof:e,type:c,key:I,ref:y,props:m,_owner:s.current}}return D.Fragment=i,D.jsx=o,D.jsxs=o,D}var ie;function Me(){return ie||(ie=1,G.exports=be()),G.exports}var d=Me();const L={findReplaceDialogContainer:"univer-find-replace-dialog-container",findReplaceExpandContainer:"univer-find-replace-expand-container",buttonText:"univer-button-text",findReplaceButtonsGroup:"univer-find-replace-buttons-group",findReplaceButtonsGroupRight:"univer-find-replace-buttons-group-right"};function se(n){const{findCompleted:e,localeService:i,matchesCount:t,matchesPosition:s,findString:a,findReplaceService:o,onChange:c,...u}=n,g=e&&t===0?i.t("find-replace.dialog.no-result"):t===0?" ":void 0;return d.jsx(_.InputWithSlot,{autoFocus:!0,placeholder:i.t("find-replace.dialog.find-placeholder"),slot:d.jsx(_.Pager,{loop:!0,text:g,value:s,total:t,onChange:m=>{s===t&&m===1?o.moveToNextMatch():s===1&&m===t||m<s?o.moveToPreviousMatch():o.moveToNextMatch()}}),value:a,onChange:m=>c==null?void 0:c(m),...u})}function ae(n,e){const i=p.useCallback(()=>{var s;(s=document.querySelector(".univer-find-input input"))==null||s.focus()},[]),t=p.useCallback(()=>{const s=document.querySelectorAll(".univer-find-replace-dialog-container .univer-select-selection-search-input");return Array.from(s).some(a=>a===document.activeElement)},[]);return p.useImperativeHandle(e,()=>({focus:i,selectHasFocus:t})),p.useEffect(()=>{const s=n.focusSignal$.subscribe(()=>i());return()=>s.unsubscribe()},[n,i]),{focus:i,selectHasFocus:t}}const ye=p.forwardRef(function(e,i){const t=r.useDependency(r.LocaleService),s=r.useDependency(b),a=r.useDependency(r.ICommandService),o=h.useObservable(s.state$,void 0,!0),{findCompleted:c,findString:u,matchesCount:v,matchesPosition:g}=o,m=p.useCallback(()=>{a.executeCommand(N.id)},[a]),I=p.useCallback(y=>s.changeFindString(y),[s]);return ae(s,i),d.jsxs(d.Fragment,{children:[d.jsx(se,{findCompleted:c,className:"univer-find-input",matchesCount:v,matchesPosition:g,findReplaceService:s,localeService:t,findString:u,onChange:I}),d.jsx("div",{className:L.findReplaceExpandContainer,children:d.jsx(_.Button,{type:"text",size:"small",onClick:m,children:t.t("find-replace.dialog.advanced-finding")})})]})}),Ie=p.forwardRef(function(e,i){const t=r.useDependency(b),s=r.useDependency(r.LocaleService),a=r.useDependency(r.ICommandService),o=r.useDependency(h.IMessageService),c=h.useObservable(t.currentMatch$,void 0,!0),u=h.useObservable(t.replaceables$,void 0,!0),v=h.useObservable(t.state$,void 0,!0),{matchesCount:g,matchesPosition:m,findString:I,inputtingFindString:y,replaceString:ze,caseSensitive:Ye,matchesTheWholeCell:Ze,findDirection:Qe,findScope:Xe,findBy:qe,findCompleted:$}=v,et=y.length===0,tt=g===0||!(c!=null&&c.replaceable),nt=u.length===0,it=p.useCallback(S=>t.changeInputtingFindString(S),[t]),st=p.useCallback(S=>t.changeReplaceString(S),[t]),{focus:at}=ae(t,i),rt=p.useCallback(()=>{I===y?t.moveToNextMatch():(t.changeFindString(y),t.find())},[I,y,t]),ot=p.useCallback(()=>a.executeCommand(w.id),[a]),ct=p.useCallback(async()=>{await a.executeCommand(B.id),at()},[a]),lt=p.useCallback(S=>{t.changeFindDirection(S)},[t]),dt=p.useCallback(S=>{t.changeFindScope(S)},[t]),ut=p.useCallback(S=>{t.changeFindBy(S)},[t]),ht=De(s),ft=Te(s),pt=xe(s);return p.useEffect(()=>{$&&g===0&&o.show({content:s.t("find-replace.dialog.no-match"),type:_.MessageType.Warning,duration:5e3})},[$,g,o,s]),d.jsxs(d.Fragment,{children:[d.jsx(_.FormLayout,{label:s.t("find-replace.dialog.find"),children:d.jsx(se,{findCompleted:$,className:"univer-find-input",matchesCount:g,matchesPosition:m,findReplaceService:t,localeService:s,findString:y,onChange:it})}),d.jsx(_.FormLayout,{label:s.t("find-replace.dialog.replace"),children:d.jsx(_.Input,{placeholder:s.t("find-replace.dialog.replace-placeholder"),value:ze,onChange:S=>st(S)})}),d.jsx(_.FormLayout,{label:s.t("find-replace.dialog.find-direction.title"),children:d.jsx(_.Select,{value:Qe,options:ft,onChange:lt})}),d.jsx(_.FormDualColumnLayout,{children:d.jsxs(d.Fragment,{children:[d.jsx(_.FormLayout,{label:s.t("find-replace.dialog.find-scope.title"),children:d.jsx(_.Select,{value:Xe,options:ht,onChange:dt})}),d.jsx(_.FormLayout,{label:s.t("find-replace.dialog.find-by.title"),children:d.jsx(_.Select,{value:qe,options:pt,onChange:ut})})]})}),d.jsx(_.FormDualColumnLayout,{children:d.jsxs(d.Fragment,{children:[d.jsx(_.FormLayout,{children:d.jsx(_.Checkbox,{checked:Ye,onChange:S=>{t.changeCaseSensitive(S)},children:s.t("find-replace.dialog.case-sensitive")})}),d.jsx(_.FormLayout,{children:d.jsx(_.Checkbox,{checked:Ze,onChange:S=>{t.changeMatchesTheWholeCell(S)},children:s.t("find-replace.dialog.match-the-whole-cell")})})]})}),d.jsxs("div",{className:L.findReplaceButtonsGroup,children:[d.jsx(_.Button,{type:"primary",onClick:rt,disabled:et,children:s.t("find-replace.dialog.find")}),d.jsxs("span",{className:L.findReplaceButtonsGroupRight,children:[d.jsx(_.Button,{disabled:tt,onClick:ot,children:s.t("find-replace.dialog.replace")}),d.jsx(_.Button,{disabled:nt,onClick:ct,children:s.t("find-replace.dialog.replace-all")})]})]})]})});function Fe(){const n=r.useDependency(b),e=r.useDependency(h.ILayoutService),i=r.useDependency(r.IContextService),t=h.useObservable(n.state$,void 0,!0),s=p.useRef(null);p.useEffect(()=>{let u;return s.current&&(u=e.registerContainerElement(s.current)),()=>u==null?void 0:u.dispose()},[e]);const a=p.useRef(null),o=p.useCallback(u=>i.setContextValue(X,u),[i]),c=p.useCallback(u=>i.setContextValue(Q,u),[i]);return p.useEffect(()=>{var v;const u=C.fromEvent(document,"focusin").subscribe(g=>{var m;g.target&&((m=s.current)!=null&&m.contains(g.target))?o(!0):o(!1),!a.current||!a.current.selectHasFocus()?c(!0):c(!1)});return(v=a.current)==null||v.focus(),o(!0),c(!0),()=>{u.unsubscribe(),o(!1)}},[o,c]),d.jsx("div",{className:L.findReplaceDialogContainer,ref:s,children:t.replaceRevealed?d.jsx(Ie,{ref:a}):d.jsx(ye,{ref:a})})}function De(n){const e=n.getCurrentLocale();return p.useMemo(()=>[{label:n.t("find-replace.dialog.find-scope.current-sheet"),value:P.SUBUNIT},{label:n.t("find-replace.dialog.find-scope.workbook"),value:P.UNIT}],[e])}function Te(n){const e=n.getCurrentLocale();return p.useMemo(()=>[{label:n.t("find-replace.dialog.find-direction.row"),value:x.ROW},{label:n.t("find-replace.dialog.find-direction.column"),value:x.COLUMN}],[e])}function xe(n){const e=n.getCurrentLocale();return p.useMemo(()=>[{label:n.t("find-replace.dialog.find-by.value"),value:O.VALUE},{label:n.t("find-replace.dialog.find-by.formula"),value:O.FORMULA}],[e])}function T(n){return n.getContextValue(X)}function Oe(n){return n.getContextValue(q)}function re(n){return n.getContextValue(Q)}const j="7_find-replace-shortcuts";function V(n){return n.getContextValue(r.FOCUSING_SHEET)}function H(n){return!n.getContextValue(r.EDITOR_ACTIVATED)}const Pe={id:F.id,description:"find-replace.shortcut.open-find-dialog",binding:h.KeyCode.F|h.MetaKeys.CTRL_COMMAND,group:j,preconditions(n){return!T(n)&&V(n)&&H(n)}},Ee={id:F.id,description:"find-replace.shortcut.open-find-dialog",binding:h.KeyCode.F|h.MetaKeys.CTRL_COMMAND,mac:h.KeyCode.F|h.MetaKeys.MAC_CTRL,preconditions(n){return!T(n)&&V(n)&&H(n)}},Ne={id:N.id,description:"find-replace.shortcut.open-replace-dialog",binding:h.KeyCode.H|h.MetaKeys.CTRL_COMMAND,mac:h.KeyCode.H|h.MetaKeys.MAC_CTRL,group:j,preconditions(n){return V(n)&&H(n)&&(!T(n)||!Oe(n))}},Le={id:k.id,description:"find-replace.shortcut.go-to-next-match",binding:h.KeyCode.ENTER,group:j,priority:1e3,preconditions(n){return re(n)&&T(n)}},je={id:W.id,description:"find-replace.shortcut.go-to-previous-match",binding:h.KeyCode.ENTER|h.MetaKeys.SHIFT,group:j,priority:1e3,preconditions(n){return re(n)&&T(n)}};function Ae(n){const e=n.get(r.IContextService);return{id:F.id,icon:"SearchIcon",tooltip:"find-replace.toolbar",type:h.MenuItemType.BUTTON,hidden$:h.getMenuHiddenObservable(n,r.UniverInstanceType.UNIVER_SHEET),disabled$:C.combineLatest([e.subscribeContextValue$(r.EDITOR_ACTIVATED),e.subscribeContextValue$(r.FOCUSING_SHEET)]).pipe(C.map(([i,t])=>i||!t))}}const Ue={[h.RibbonStartGroup.OTHERS]:{[F.id]:{order:2,menuItemFactory:Ae}}};var we=Object.defineProperty,Be=Object.getOwnPropertyDescriptor,ke=(n,e,i,t)=>{for(var s=t>1?void 0:t?Be(e,i):e,a=n.length-1,o;a>=0;a--)(o=n[a])&&(s=(t?o(e,i,s):o(s))||s);return t&&s&&we(e,i,s),s},M=(n,e)=>(i,t)=>e(i,t,n);const oe="DESKTOP_FIND_REPLACE_DIALOG",ce=350,We=20,Ge=-90;l.FindReplaceController=class extends r.RxDisposable{constructor(i,t,s,a,o,c,u,v,g,m){super();f(this,"_closingListenerDisposable");this._univerInstanceService=i,this._menuManagerService=t,this._shortcutService=s,this._commandService=a,this._findReplaceService=o,this._dialogService=c,this._layoutService=u,this._localeService=v,this._componentManager=g,this._injector=m,this._initCommands(),this._initUI(),this._initShortcuts()}dispose(){var i;super.dispose(),(i=this._closingListenerDisposable)==null||i.dispose(),this._closingListenerDisposable=null}_initCommands(){[F,N,k,W,B,w].forEach(i=>{this.disposeWithMe(this._commandService.registerCommand(i))})}_initShortcuts(){[Ne,Pe,Ee,je,Le].forEach(i=>this.disposeWithMe(this._shortcutService.registerShortcut(i)))}_initUI(){this.disposeWithMe(this._componentManager.register("FindReplaceDialog",Fe)),this.disposeWithMe(this._componentManager.register("SearchIcon",Z)),this._menuManagerService.mergeMenu(Ue),this._findReplaceService.stateUpdates$.pipe(C.takeUntil(this.dispose$)).subscribe(i=>{i.revealed===!0&&this._openPanel()})}_openPanel(){this._dialogService.open({id:oe,draggable:!0,width:ce,title:{title:this._localeService.t("find-replace.dialog.title")},children:{label:"FindReplaceDialog"},destroyOnClose:!0,defaultPosition:Ve(),preservePositionOnDestroy:!0,onClose:()=>this.closePanel()}),this._closingListenerDisposable=r.toDisposable(this._univerInstanceService.focused$.pipe(C.takeUntil(this.dispose$)).subscribe(i=>{(!i||!this._univerInstanceService.getUniverSheetInstance(i))&&this.closePanel()}))}closePanel(){this._closingListenerDisposable&&(this._closingListenerDisposable.dispose(),this._closingListenerDisposable=null,this._dialogService.close(oe),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus()))}},l.FindReplaceController=ke([M(0,r.IUniverInstanceService),M(1,h.IMenuManagerService),M(2,h.IShortcutService),M(3,r.ICommandService),M(4,b),M(5,h.IDialogService),M(6,h.ILayoutService),M(7,r.Inject(r.LocaleService)),M(8,r.Inject(h.ComponentManager)),M(9,r.Inject(r.Injector))],l.FindReplaceController);function Ve(){const{innerWidth:n}=window;return{x:(n-ce)/2-We,y:Ge}}var He=Object.defineProperty,Ke=Object.getOwnPropertyDescriptor,$e=(n,e,i,t)=>{for(var s=t>1?void 0:t?Ke(e,i):e,a=n.length-1,o;a>=0;a--)(o=n[a])&&(s=(t?o(e,i,s):o(s))||s);return t&&s&&He(e,i,s),s},le=(n,e)=>(i,t)=>e(i,t,n);const Je="UNIVER_FIND_REPLACE_PLUGIN";l.UniverFindReplacePlugin=(K=class extends r.Plugin{constructor(e=J,i,t){super(),this._config=e,this._injector=i,this._configService=t;const{...s}=r.merge({},J,this._config);this._configService.setConfig(ue,s)}onStarting(){[[l.FindReplaceController],[b,{useClass:U}]].forEach(e=>this._injector.add(e))}onRendered(){this._injector.get(l.FindReplaceController)}},f(K,"pluginName",Je),K),l.UniverFindReplacePlugin=$e([le(1,r.Inject(r.Injector)),le(2,r.IConfigService)],l.UniverFindReplacePlugin),l.FindBy=O,l.FindDirection=x,l.FindModel=Se,l.FindReplaceState=te,l.FindScope=P,l.GoToNextMatchOperation=k,l.GoToPreviousMatchOperation=W,l.IFindReplaceService=b,l.OpenFindDialogOperation=F,l.OpenReplaceDialogOperation=N,l.ReplaceAllMatchesCommand=B,l.ReplaceCurrentMatchCommand=w,l.createInitFindReplaceState=E,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/find-replace",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -54,21 +54,22 @@
|
|
|
54
54
|
"rxjs": ">=7.0.0"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@univerjs/icons": "^0.2.
|
|
58
|
-
"@univerjs/core": "0.5.
|
|
59
|
-
"@univerjs/design": "0.5.
|
|
60
|
-
"@univerjs/ui": "0.5.
|
|
61
|
-
"@univerjs/engine-render": "0.5.
|
|
57
|
+
"@univerjs/icons": "^0.2.12",
|
|
58
|
+
"@univerjs/core": "0.5.4",
|
|
59
|
+
"@univerjs/design": "0.5.4",
|
|
60
|
+
"@univerjs/ui": "0.5.4",
|
|
61
|
+
"@univerjs/engine-render": "0.5.4"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"less": "^4.2.1",
|
|
65
65
|
"postcss": "^8.4.49",
|
|
66
66
|
"react": "18.3.1",
|
|
67
67
|
"rxjs": "^7.8.1",
|
|
68
|
+
"tailwindcss": "^3.4.17",
|
|
68
69
|
"typescript": "^5.7.2",
|
|
69
|
-
"vite": "^6.0.
|
|
70
|
+
"vite": "^6.0.7",
|
|
70
71
|
"vitest": "^2.1.8",
|
|
71
|
-
"@univerjs-infra/shared": "0.5.
|
|
72
|
+
"@univerjs-infra/shared": "0.5.4"
|
|
72
73
|
},
|
|
73
74
|
"scripts": {
|
|
74
75
|
"test": "vitest run",
|