@univerjs/find-replace 0.1.16 → 0.1.17
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 +132 -133
- package/lib/types/services/find-replace.service.d.ts +2 -3
- package/lib/umd/index.js +2 -2
- package/package.json +11 -11
package/lib/cjs/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var Te=Object.defineProperty;var Ee=(t,e,n)=>e in t?Te(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var d=(t,e,n)=>Ee(t,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@univerjs/core"),y=require("@wendellhu/redi"),h=require("@univerjs/ui"),S=require("rxjs"),$e=require("@univerjs/engine-render"),l=require("react"),f=require("@univerjs/design"),M=require("@wendellhu/redi/react-bindings");var C=function(){return C=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++){e=arguments[n];for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=e[s])}return t},C.apply(this,arguments)},je=function(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,i=Object.getOwnPropertySymbols(t);s<i.length;s++)e.indexOf(i[s])<0&&Object.prototype.propertyIsEnumerable.call(t,i[s])&&(n[i[s]]=t[i[s]]);return n},q=l.forwardRef(function(t,e){var n=t.icon,i=t.id,s=t.className,r=t.extend,a=je(t,["icon","id","className","extend"]),o="univerjs-icon univerjs-icon-".concat(i," ").concat(s||"").trim(),p=l.useRef("_".concat(Ae()));return z(n,"".concat(i),{defIds:n.defIds,idSuffix:p.current},C({ref:e,className:o},a),r)});function z(t,e,n,i,s){return l.createElement(t.tag,C(C({key:e},Ne(t,n,s)),i),(Le(t,n).children||[]).map(function(r,a){return z(r,"".concat(e,"-").concat(t.tag,"-").concat(a),n,void 0,s)}))}function Ne(t,e,n){var i=C({},t.attrs);n!=null&&n.colorChannel1&&i.fill==="colorChannel1"&&(i.fill=n.colorChannel1);var s=e.defIds;return!s||s.length===0||(t.tag==="use"&&i["xlink:href"]&&(i["xlink:href"]=i["xlink:href"]+e.idSuffix),Object.entries(i).forEach(function(r){var a=r[0],o=r[1];typeof o=="string"&&(i[a]=o.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),i}function Le(t,e){var n,i=e.defIds;return!i||i.length===0?t:t.tag==="defs"&&(!((n=t.children)===null||n===void 0)&&n.length)?C(C({},t),{children:t.children.map(function(s){return typeof s.attrs.id=="string"&&i&&i.indexOf(s.attrs.id)>-1?C(C({},s),{attrs:C(C({},s.attrs),{id:s.attrs.id+e.idSuffix})}):s})}):t}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"}}]}]},Y=l.forwardRef(function(t,e){return l.createElement(q,Object.assign({},t,{id:"search-single-16",ref:e,icon:we}))});Y.displayName="SearchSingle16";const Z="FIND_REPLACE_INPUT_FOCUS",J="FIND_REPLACE_DIALOG_FOCUS",Q="FIND_REPLACE_REPLACE_REVEALED";var Ue=Object.defineProperty,Be=Object.getOwnPropertyDescriptor,X=(t,e,n,i)=>{for(var s=i>1?void 0:i?Be(e,n):e,r=t.length-1,a;r>=0;r--)(a=t[r])&&(s=(i?a(e,n,s):a(s))||s);return i&&s&&Ue(e,n,s),s},O=(t,e)=>(n,i)=>e(n,i,t);class We extends c.Disposable{}const R=y.createIdentifier("find-replace.service");function ke(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"}let U=class extends c.Disposable{constructor(e,n,i,s){super();d(this,"currentMatch$",new S.BehaviorSubject(null));d(this,"replaceables$",new S.BehaviorSubject([]));d(this,"_findModels",[]);d(this,"_matchingModel",null);d(this,"_matches",[]);d(this,"_currentSearchingDisposables",null);this._state=e,this._providers=n,this._univerInstanceService=i,this._logService=s,this.disposeWithMe(this._state.stateUpdates$.pipe(S.throttleTime(200,void 0,{leading:!0,trailing:!0})).subscribe(async r=>{const a=this._state.state;ke(r)&&(a.findString!==""&&!a.replaceRevealed?(await this._startSearching(),this._state.changeState({findCompleted:!0})):r.replaceRevealed!==!0&&this._stopSearching())}))}get searched(){return this._findModels.length>0}dispose(){super.dispose(),this._stopSearching(),this.currentMatch$.complete(),this.replaceables$.complete(),this._state.changeState({...W(),revealed:!1})}async start(){if(!this._state.findString)return{results:[]};const e=await this._startSearching();return this._state.changeState({findCompleted:!0}),e}async _startSearching(){if(!this._state.findString)return{results:[]};const e=Array.from(this._providers),n=this._findModels=(await Promise.all(e.map(r=>r.find({findString:this._state.findString,findDirection:this._state.findDirection,findScope:this._state.findScope,findBy:this._state.findBy,replaceRevealed:this._state.replaceRevealed,caseSensitive:this._state.caseSensitive,matchesTheWholeCell:this._state.matchesTheWholeCell})))).flat();this._subscribeToModelsChanges(n);const i=this._matches=n.map(r=>r.getMatches()).flat();if(this.replaceables$.next(i.filter(r=>r.replaceable)),!i.length)return this._state.changeState({matchesCount:0,matchesPosition:0}),{results:[]};const s=this._moveToInitialMatch(n,i);return this._state.changeState({matchesCount:i.length,matchesPosition:s+1}),{results:i}}_stopSearching(){var e;this._providers.forEach(n=>n.terminate()),this._findModels=[],this._matches=[],this._matchingModel=null,(e=this._currentSearchingDisposables)==null||e.dispose(),this._currentSearchingDisposables=null,this.currentMatch$.next(null),this.replaceables$.next([]),this._state.changeState({findCompleted:!1,matchesCount:0,matchesPosition:0})}_subscribeToModelsChanges(e){const n=this._currentSearchingDisposables=new c.DisposableCollection,i=S.combineLatest(e.map(s=>s.matchesUpdate$)).pipe(S.debounceTime(220)).subscribe(([...s])=>{const r=this._matches=s.flat();if(r.length){const a=this._moveToInitialMatch(this._findModels,r,!0);this._state.changeState({matchesCount:r.length,matchesPosition:a+1}),this.replaceables$.next(r.filter(o=>o.replaceable))}else this._state.changeState({matchesCount:0,matchesPosition:0}),this.replaceables$.next([])});e.forEach(s=>n.add(c.toDisposable(s.activelyChangingMatch$.subscribe(r=>{const a=this._matches.findIndex(o=>o===r);this._state.changeState({matchesPosition:a+1})})))),n.add(c.toDisposable(i))}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((i,s)=>(i.success+=s.success,i.failure+=s.failure,i),{success:0,failure:0}));return e.failure===0&&this._stopSearching(),e}getCurrentMatch(){return this._state.matchesPosition>0?this._matches[this._state.matchesPosition-1]:null}moveToNextMatch(){if(!this._matchingModel)return;const e=this._findModels.length===1,n=this._matchingModel.moveToNextMatch({loop:e});if(n){const i=this._matches.findIndex(s=>s===n);this.currentMatch$.next(n),this._state.changeState({matchesPosition:i+1})}else{const i=this._findModels.findIndex(o=>o===this._matchingModel),s=this._findModels[(i+1)%this._findModels.length],r=s.moveToNextMatch(),a=this._matches.findIndex(o=>o===r);this.currentMatch$.next(r),this._matchingModel=s,this._state.changeState({matchesPosition:a+1})}}moveToPreviousMatch(){if(!this._matchingModel)return;const e=this._findModels.length===1,n=this._matchingModel.moveToPreviousMatch({loop:e});if(n){const i=this._matches.findIndex(s=>s===n);this.currentMatch$.next(n),this._state.changeState({matchesPosition:i+1})}else{const i=this._findModels.findIndex(o=>o===this._matchingModel),s=this._findModels[(i-1+this._findModels.length)%this._findModels.length],r=s.moveToPreviousMatch(),a=this._matches.findIndex(o=>o===r);this.currentMatch$.next(r),this._matchingModel=s,this._state.changeState({matchesPosition:a+1})}}_moveToInitialMatch(e,n,i=!1){var p;const s=(p=this._univerInstanceService.getFocusedUnit())==null?void 0:p.getUnitId();if(!s)return-1;const r=e.find(g=>g.unitId===s);if(r){this._matchingModel=r;const g=r.moveToNextMatch({stayIfOnMatch:!0,noFocus:i}),v=n.findIndex(m=>m===g);return this.currentMatch$.next(g),v}this._matchingModel=e[0];const a=this._matchingModel.moveToNextMatch({noFocus:i}),o=this._matches.findIndex(g=>g===a);return this.currentMatch$.next(a),o}};U=X([O(2,c.IUniverInstanceService),O(3,c.ILogService)],U);var P=(t=>(t.ROW="row",t.COLUMN="column",t))(P||{}),T=(t=>(t.VALUE="value",t.FORMULA="formula",t))(T||{}),E=(t=>(t.SUBUNIT="subunit",t.UNIT="unit",t))(E||{});function W(){return{caseSensitive:!1,findBy:"value",findCompleted:!1,findDirection:"row",findScope:"subunit",findString:"",inputtingFindString:"",matchesCount:0,matchesPosition:0,matchesTheWholeCell:!1,replaceRevealed:!1,replaceString:"",revealed:!0}}class Ge{constructor(){d(this,"_stateUpdates$",new S.Subject);d(this,"stateUpdates$",this._stateUpdates$.asObservable());d(this,"_state$",new S.BehaviorSubject(W()));d(this,"state$",this._state$.asObservable());d(this,"_findString","");d(this,"_inputtingFindString","");d(this,"_replaceString","");d(this,"_revealed",!1);d(this,"_replaceRevealed",!1);d(this,"_matchesPosition",0);d(this,"_matchesCount",0);d(this,"_caseSensitive",!0);d(this,"_matchesTheWholeCell",!1);d(this,"_findDirection","row");d(this,"_findScope","subunit");d(this,"_findBy","value");d(this,"_findCompleted",!1)}get state(){return this._state$.getValue()}get inputtingFindString(){return this._inputtingFindString}get findString(){return this._findString}get revealed(){return this._revealed}get replaceRevealed(){return this._replaceRevealed}get matchesPosition(){return this._matchesPosition}get matchesCount(){return this._matchesCount}get replaceString(){return this._replaceString}get caseSensitive(){return this._caseSensitive}get matchesTheWholeCell(){return this._matchesTheWholeCell}get findDirection(){return this._findDirection}get findScope(){return this._findScope}get findBy(){return this._findBy}get findCompleted(){return this._findCompleted}changeState(e){let n=!1;const i={};typeof e.findString<"u"&&e.findString!==this._findString&&(this._findString=e.findString,i.findString=this._findString,n=!0),typeof e.revealed<"u"&&e.revealed!==this._revealed&&(this._revealed=e.revealed,i.revealed=e.revealed,n=!0),typeof e.replaceRevealed<"u"&&e.replaceRevealed!==this._replaceRevealed&&(this._replaceRevealed=e.replaceRevealed,i.replaceRevealed=e.replaceRevealed,n=!0),typeof e.replaceString<"u"&&e.replaceString!==this._replaceString&&(this._replaceString=e.replaceString,i.replaceString=e.replaceString,n=!0),typeof e.matchesCount<"u"&&e.matchesCount!==this._matchesCount&&(this._matchesCount=e.matchesCount,i.matchesCount=e.matchesCount,n=!0),typeof e.matchesPosition<"u"&&e.matchesPosition!==this._matchesPosition&&(this._matchesPosition=e.matchesPosition,i.matchesPosition=e.matchesPosition,n=!0),typeof e.findBy<"u"&&e.findBy!==this._findBy&&(this._findBy=e.findBy,i.findBy=e.findBy,n=!0),typeof e.findScope<"u"&&e.findScope!==this._findScope&&(this._findScope=e.findScope,i.findScope=e.findScope,n=!0),typeof e.findDirection<"u"&&e.findDirection!==this._findDirection&&(this._findDirection=e.findDirection,i.findDirection=e.findDirection,n=!0),typeof e.caseSensitive<"u"&&e.caseSensitive!==this._caseSensitive&&(this._caseSensitive=e.caseSensitive,i.caseSensitive=e.caseSensitive,n=!0),typeof e.matchesTheWholeCell<"u"&&e.matchesTheWholeCell!==this._matchesTheWholeCell&&(this._matchesTheWholeCell=e.matchesTheWholeCell,i.matchesTheWholeCell=e.matchesTheWholeCell,n=!0),typeof e.inputtingFindString<"u"&&e.inputtingFindString!==this._inputtingFindString&&(this._inputtingFindString=e.inputtingFindString,i.inputtingFindString=e.inputtingFindString,n=!0),typeof e.findCompleted<"u"&&e.findCompleted!==this._findCompleted&&(this._findCompleted=e.findCompleted,i.findCompleted=e.findCompleted,n=!0),n&&(this._state$.next({caseSensitive:this._caseSensitive,findBy:this._findBy,findCompleted:this._findCompleted,findDirection:this._findDirection,findScope:this._findScope,findString:this._findString,inputtingFindString:this._inputtingFindString,matchesCount:this._matchesCount,matchesPosition:this._matchesPosition,matchesTheWholeCell:this._matchesTheWholeCell,replaceRevealed:this._replaceRevealed,revealed:this._revealed}),this._stateUpdates$.next(i))}}let B=class extends c.Disposable{constructor(e,n){super();d(this,"_providers",new Set);d(this,"_state",new Ge);d(this,"_model");d(this,"_currentMatch$",new S.BehaviorSubject(null));d(this,"currentMatch$",this._currentMatch$.asObservable());d(this,"_replaceables$",new S.BehaviorSubject([]));d(this,"replaceables$",this._replaceables$.asObservable());d(this,"_focusSignal$",new S.Subject);d(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(U,this._state,this._providers),this._model.currentMatch$.subscribe(i=>this._currentMatch$.next(i)),this._model.replaceables$.subscribe(i=>this._replaceables$.next(i));const n=W();return e&&(n.replaceRevealed=!0),this._state.changeState(n),this._toggleRevealReplace(e),!0}find(){var e;(e=this._model)==null||e.start()}terminate(){var e;(e=this._model)==null||e.dispose(),this._model=null,this._toggleDisplayRawFormula(!1),this._toggleRevealReplace(!1)}registerFindReplaceProvider(e){return this._providers.add(e),c.toDisposable(()=>this._providers.delete(e))}_toggleRevealReplace(e){this._contextService.setContextValue(Q,e)}_toggleDisplayRawFormula(e){this._contextService.setContextValue($e.RENDER_RAW_FORMULA_KEY,e)}};B=X([O(0,y.Inject(y.Injector)),O(1,c.IContextService)],B);const j={id:"ui.operation.open-find-dialog",type:c.CommandType.OPERATION,handler:t=>{const e=t.get(R);return e.revealed?e.focusFindInput():e.start(),!0}},k={id:"ui.operation.open-replace-dialog",type:c.CommandType.OPERATION,handler:t=>{const e=t.get(R);return e.revealed?e.replaceRevealed?e.focusFindInput():e.revealReplace():e.start(!0),!0}},ee={type:c.CommandType.OPERATION,id:"ui.operation.go-to-next-match",handler:t=>(t.get(R).moveToNextMatch(),!0)},te={type:c.CommandType.OPERATION,id:"ui.operation.go-to-previous-match",handler:t=>(t.get(R).moveToPreviousMatch(),!0)};var ie={exports:{}},N={};/**
|
|
1
|
+
"use strict";var Te=Object.defineProperty;var Ee=(t,e,n)=>e in t?Te(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var d=(t,e,n)=>Ee(t,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@univerjs/core"),y=require("@wendellhu/redi"),h=require("@univerjs/ui"),S=require("rxjs"),$e=require("@univerjs/engine-render"),c=require("react"),f=require("@univerjs/design"),M=require("@wendellhu/redi/react-bindings");var C=function(){return C=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++){e=arguments[n];for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=e[s])}return t},C.apply(this,arguments)},je=function(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,i=Object.getOwnPropertySymbols(t);s<i.length;s++)e.indexOf(i[s])<0&&Object.prototype.propertyIsEnumerable.call(t,i[s])&&(n[i[s]]=t[i[s]]);return n},q=c.forwardRef(function(t,e){var n=t.icon,i=t.id,s=t.className,r=t.extend,a=je(t,["icon","id","className","extend"]),o="univerjs-icon univerjs-icon-".concat(i," ").concat(s||"").trim(),p=c.useRef("_".concat(Ae()));return z(n,"".concat(i),{defIds:n.defIds,idSuffix:p.current},C({ref:e,className:o},a),r)});function z(t,e,n,i,s){return c.createElement(t.tag,C(C({key:e},Ne(t,n,s)),i),(Le(t,n).children||[]).map(function(r,a){return z(r,"".concat(e,"-").concat(t.tag,"-").concat(a),n,void 0,s)}))}function Ne(t,e,n){var i=C({},t.attrs);n!=null&&n.colorChannel1&&i.fill==="colorChannel1"&&(i.fill=n.colorChannel1);var s=e.defIds;return!s||s.length===0||(t.tag==="use"&&i["xlink:href"]&&(i["xlink:href"]=i["xlink:href"]+e.idSuffix),Object.entries(i).forEach(function(r){var a=r[0],o=r[1];typeof o=="string"&&(i[a]=o.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),i}function Le(t,e){var n,i=e.defIds;return!i||i.length===0?t:t.tag==="defs"&&(!((n=t.children)===null||n===void 0)&&n.length)?C(C({},t),{children:t.children.map(function(s){return typeof s.attrs.id=="string"&&i&&i.indexOf(s.attrs.id)>-1?C(C({},s),{attrs:C(C({},s.attrs),{id:s.attrs.id+e.idSuffix})}):s})}):t}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"}}]}]},Y=c.forwardRef(function(t,e){return c.createElement(q,Object.assign({},t,{id:"search-single-16",ref:e,icon:we}))});Y.displayName="SearchSingle16";const Z="FIND_REPLACE_INPUT_FOCUS",J="FIND_REPLACE_DIALOG_FOCUS",Q="FIND_REPLACE_REPLACE_REVEALED";var Ue=Object.defineProperty,Be=Object.getOwnPropertyDescriptor,X=(t,e,n,i)=>{for(var s=i>1?void 0:i?Be(e,n):e,r=t.length-1,a;r>=0;r--)(a=t[r])&&(s=(i?a(e,n,s):a(s))||s);return i&&s&&Ue(e,n,s),s},w=(t,e)=>(n,i)=>e(n,i,t);class We extends l.Disposable{}const R=y.createIdentifier("find-replace.service");function ke(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"}let U=class extends l.Disposable{constructor(e,n,i){super();d(this,"currentMatch$",new S.BehaviorSubject(null));d(this,"replaceables$",new S.BehaviorSubject([]));d(this,"_findModels",[]);d(this,"_matchingModel",null);d(this,"_matches",[]);d(this,"_currentSearchingDisposables",null);this._state=e,this._providers=n,this._univerInstanceService=i,this.disposeWithMe(this._state.stateUpdates$.pipe(S.throttleTime(200,void 0,{leading:!0,trailing:!0})).subscribe(async s=>{const r=this._state.state;ke(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({...W(),revealed:!1})}async start(){if(!this._state.findString)return{results:[]};const e=await this._startSearching();return this._state.changeState({findCompleted:!0}),e}async _startSearching(){if(!this._state.findString)return{results:[]};const e=Array.from(this._providers),n=this._findModels=(await Promise.all(e.map(r=>r.find({findString:this._state.findString,findDirection:this._state.findDirection,findScope:this._state.findScope,findBy:this._state.findBy,replaceRevealed:this._state.replaceRevealed,caseSensitive:this._state.caseSensitive,matchesTheWholeCell:this._state.matchesTheWholeCell})))).flat();this._subscribeToModelsChanges(n);const i=this._matches=n.map(r=>r.getMatches()).flat();if(this.replaceables$.next(i.filter(r=>r.replaceable)),!i.length)return this._state.changeState({matchesCount:0,matchesPosition:0}),{results:[]};const s=this._moveToInitialMatch(n,i);return this._state.changeState({matchesCount:i.length,matchesPosition:s+1}),{results:i}}_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 l.DisposableCollection,i=S.combineLatest(e.map(s=>s.matchesUpdate$)).pipe(S.debounceTime(220)).subscribe(([...s])=>{const r=this._matches=s.flat();if(r.length){const a=this._moveToInitialMatch(this._findModels,r,!0);this._state.changeState({matchesCount:r.length,matchesPosition:a+1}),this.replaceables$.next(r.filter(o=>o.replaceable))}else this._state.changeState({matchesCount:0,matchesPosition:0}),this.replaceables$.next([])});e.forEach(s=>n.add(l.toDisposable(s.activelyChangingMatch$.subscribe(r=>{const a=this._matches.findIndex(o=>o===r);this._state.changeState({matchesPosition:a+1})})))),n.add(l.toDisposable(i))}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((i,s)=>(i.success+=s.success,i.failure+=s.failure,i),{success:0,failure:0}));return e.failure===0&&this._stopSearching(),e}getCurrentMatch(){return this._state.matchesPosition>0?this._matches[this._state.matchesPosition-1]:null}moveToNextMatch(){if(!this._matchingModel)return;const e=this._findModels.length===1,n=this._matchingModel.moveToNextMatch({loop:e});if(n){const i=this._matches.findIndex(s=>s===n);this.currentMatch$.next(n),this._state.changeState({matchesPosition:i+1})}else{const i=this._findModels.findIndex(o=>o===this._matchingModel),s=this._findModels[(i+1)%this._findModels.length],r=s.moveToNextMatch(),a=this._matches.findIndex(o=>o===r);this.currentMatch$.next(r),this._matchingModel=s,this._state.changeState({matchesPosition:a+1})}}moveToPreviousMatch(){if(!this._matchingModel)return;const e=this._findModels.length===1,n=this._matchingModel.moveToPreviousMatch({loop:e});if(n){const i=this._matches.findIndex(s=>s===n);this.currentMatch$.next(n),this._state.changeState({matchesPosition:i+1})}else{const i=this._findModels.findIndex(o=>o===this._matchingModel),s=this._findModels[(i-1+this._findModels.length)%this._findModels.length],r=s.moveToPreviousMatch(),a=this._matches.findIndex(o=>o===r);this.currentMatch$.next(r),this._matchingModel=s,this._state.changeState({matchesPosition:a+1})}}_moveToInitialMatch(e,n,i=!1){var p;const s=(p=this._univerInstanceService.getFocusedUnit())==null?void 0:p.getUnitId();if(!s)return-1;const r=e.find(g=>g.unitId===s);if(r){this._matchingModel=r;const g=r.moveToNextMatch({stayIfOnMatch:!0,noFocus:i}),v=n.findIndex(m=>m===g);return this.currentMatch$.next(g),v}this._matchingModel=e[0];const a=this._matchingModel.moveToNextMatch({noFocus:i}),o=this._matches.findIndex(g=>g===a);return this.currentMatch$.next(a),o}};U=X([w(2,l.IUniverInstanceService)],U);var O=(t=>(t.ROW="row",t.COLUMN="column",t))(O||{}),P=(t=>(t.VALUE="value",t.FORMULA="formula",t))(P||{}),T=(t=>(t.SUBUNIT="subunit",t.UNIT="unit",t))(T||{});function W(){return{caseSensitive:!1,findBy:"value",findCompleted:!1,findDirection:"row",findScope:"subunit",findString:"",inputtingFindString:"",matchesCount:0,matchesPosition:0,matchesTheWholeCell:!1,replaceRevealed:!1,replaceString:"",revealed:!0}}class Ge{constructor(){d(this,"_stateUpdates$",new S.Subject);d(this,"stateUpdates$",this._stateUpdates$.asObservable());d(this,"_state$",new S.BehaviorSubject(W()));d(this,"state$",this._state$.asObservable());d(this,"_findString","");d(this,"_inputtingFindString","");d(this,"_replaceString","");d(this,"_revealed",!1);d(this,"_replaceRevealed",!1);d(this,"_matchesPosition",0);d(this,"_matchesCount",0);d(this,"_caseSensitive",!0);d(this,"_matchesTheWholeCell",!1);d(this,"_findDirection","row");d(this,"_findScope","subunit");d(this,"_findBy","value");d(this,"_findCompleted",!1)}get state(){return this._state$.getValue()}get inputtingFindString(){return this._inputtingFindString}get findString(){return this._findString}get revealed(){return this._revealed}get replaceRevealed(){return this._replaceRevealed}get matchesPosition(){return this._matchesPosition}get matchesCount(){return this._matchesCount}get replaceString(){return this._replaceString}get caseSensitive(){return this._caseSensitive}get matchesTheWholeCell(){return this._matchesTheWholeCell}get findDirection(){return this._findDirection}get findScope(){return this._findScope}get findBy(){return this._findBy}get findCompleted(){return this._findCompleted}changeState(e){let n=!1;const i={};typeof e.findString<"u"&&e.findString!==this._findString&&(this._findString=e.findString,i.findString=this._findString,n=!0),typeof e.revealed<"u"&&e.revealed!==this._revealed&&(this._revealed=e.revealed,i.revealed=e.revealed,n=!0),typeof e.replaceRevealed<"u"&&e.replaceRevealed!==this._replaceRevealed&&(this._replaceRevealed=e.replaceRevealed,i.replaceRevealed=e.replaceRevealed,n=!0),typeof e.replaceString<"u"&&e.replaceString!==this._replaceString&&(this._replaceString=e.replaceString,i.replaceString=e.replaceString,n=!0),typeof e.matchesCount<"u"&&e.matchesCount!==this._matchesCount&&(this._matchesCount=e.matchesCount,i.matchesCount=e.matchesCount,n=!0),typeof e.matchesPosition<"u"&&e.matchesPosition!==this._matchesPosition&&(this._matchesPosition=e.matchesPosition,i.matchesPosition=e.matchesPosition,n=!0),typeof e.findBy<"u"&&e.findBy!==this._findBy&&(this._findBy=e.findBy,i.findBy=e.findBy,n=!0),typeof e.findScope<"u"&&e.findScope!==this._findScope&&(this._findScope=e.findScope,i.findScope=e.findScope,n=!0),typeof e.findDirection<"u"&&e.findDirection!==this._findDirection&&(this._findDirection=e.findDirection,i.findDirection=e.findDirection,n=!0),typeof e.caseSensitive<"u"&&e.caseSensitive!==this._caseSensitive&&(this._caseSensitive=e.caseSensitive,i.caseSensitive=e.caseSensitive,n=!0),typeof e.matchesTheWholeCell<"u"&&e.matchesTheWholeCell!==this._matchesTheWholeCell&&(this._matchesTheWholeCell=e.matchesTheWholeCell,i.matchesTheWholeCell=e.matchesTheWholeCell,n=!0),typeof e.inputtingFindString<"u"&&e.inputtingFindString!==this._inputtingFindString&&(this._inputtingFindString=e.inputtingFindString,i.inputtingFindString=e.inputtingFindString,n=!0),typeof e.findCompleted<"u"&&e.findCompleted!==this._findCompleted&&(this._findCompleted=e.findCompleted,i.findCompleted=e.findCompleted,n=!0),n&&(this._state$.next({caseSensitive:this._caseSensitive,findBy:this._findBy,findCompleted:this._findCompleted,findDirection:this._findDirection,findScope:this._findScope,findString:this._findString,inputtingFindString:this._inputtingFindString,matchesCount:this._matchesCount,matchesPosition:this._matchesPosition,matchesTheWholeCell:this._matchesTheWholeCell,replaceRevealed:this._replaceRevealed,revealed:this._revealed}),this._stateUpdates$.next(i))}}let B=class extends l.Disposable{constructor(e,n){super();d(this,"_providers",new Set);d(this,"_state",new Ge);d(this,"_model");d(this,"_currentMatch$",new S.BehaviorSubject(null));d(this,"currentMatch$",this._currentMatch$.asObservable());d(this,"_replaceables$",new S.BehaviorSubject([]));d(this,"replaceables$",this._replaceables$.asObservable());d(this,"_focusSignal$",new S.Subject);d(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(U,this._state,this._providers),this._model.currentMatch$.subscribe(i=>this._currentMatch$.next(i)),this._model.replaceables$.subscribe(i=>this._replaceables$.next(i));const n=W();return e&&(n.replaceRevealed=!0),this._state.changeState(n),this._toggleRevealReplace(e),!0}find(){var e;(e=this._model)==null||e.start()}terminate(){var e;(e=this._model)==null||e.dispose(),this._model=null,this._toggleDisplayRawFormula(!1),this._toggleRevealReplace(!1)}registerFindReplaceProvider(e){return this._providers.add(e),l.toDisposable(()=>this._providers.delete(e))}_toggleRevealReplace(e){this._contextService.setContextValue(Q,e)}_toggleDisplayRawFormula(e){this._contextService.setContextValue($e.RENDER_RAW_FORMULA_KEY,e)}};B=X([w(0,y.Inject(y.Injector)),w(1,l.IContextService)],B);const $={id:"ui.operation.open-find-dialog",type:l.CommandType.OPERATION,handler:t=>{const e=t.get(R);return e.revealed?e.focusFindInput():e.start(),!0}},k={id:"ui.operation.open-replace-dialog",type:l.CommandType.OPERATION,handler:t=>{const e=t.get(R);return e.revealed?e.replaceRevealed?e.focusFindInput():e.revealReplace():e.start(!0),!0}},ee={type:l.CommandType.OPERATION,id:"ui.operation.go-to-next-match",handler:t=>(t.get(R).moveToNextMatch(),!0)},te={type:l.CommandType.OPERATION,id:"ui.operation.go-to-previous-match",handler:t=>(t.get(R).moveToPreviousMatch(),!0)};var ie={exports:{}},j={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var Ve=l,He=Symbol.for("react.element"),Ke=Symbol.for("react.fragment"),qe=Object.prototype.hasOwnProperty,ze=Ve.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Ye={key:!0,ref:!0,__self:!0,__source:!0};function ne(t,e,n){var i,s={},r=null,a=null;n!==void 0&&(r=""+n),e.key!==void 0&&(r=""+e.key),e.ref!==void 0&&(a=e.ref);for(i in e)qe.call(e,i)&&!Ye.hasOwnProperty(i)&&(s[i]=e[i]);if(t&&t.defaultProps)for(i in e=t.defaultProps,e)s[i]===void 0&&(s[i]=e[i]);return{$$typeof:He,type:t,key:r,ref:a,props:s,_owner:ze.current}}N.Fragment=Ke;N.jsx=ne;N.jsxs=ne;ie.exports=N;var u=ie.exports;const se={id:"ui.command.replace-current-match",type:c.CommandType.COMMAND,handler:t=>t.get(R).replace()},Ze="CONFIRM_REPLACE_ALL",re={id:"ui.command.replace-all-matches",type:c.CommandType.COMMAND,handler:async t=>{const e=t.get(h.IConfirmService),n=t.get(c.LocaleService),i=t.get(h.IMessageService);if(!await e.confirm({id:Ze,title:{title:n.t("find-replace.replace.confirm.title")},cancelText:n.t("button.cancel"),confirmText:n.t("button.confirm")}))return!1;const r=await t.get(R).replaceAll(),{success:a,failure:o}=r;return o>0?(a===0?i.show({type:f.MessageType.Error,content:n.t("find-replace.replace.all-failure")}):i.show({type:f.MessageType.Warning,content:n.t("find-replace.replace.partial-success",`${a}`,`${o}`)}),!1):(i.show({type:f.MessageType.Success,content:n.t("find-replace.replace.all-success",`${a}`)}),!0)}};function ae(t){const{findCompleted:e,localeService:n,matchesCount:i,matchesPosition:s,findString:r,findReplaceService:a,onChange:o,...p}=t,v=e&&i===0?n.t("find-replace.dialog.no-result"):i===0?" ":void 0;return u.jsx(f.InputWithSlot,{autoFocus:!0,placeholder:n.t("find-replace.dialog.find-placeholder"),slot:u.jsx(f.Pager,{loop:!0,text:v,value:s,total:i,onChange:m=>{s===i&&m===1?a.moveToNextMatch():s===1&&m===i||m<s?a.moveToPreviousMatch():a.moveToNextMatch()}}),value:r,onChange:m=>o==null?void 0:o(m),...p})}const Je="univer-find-replace-dialog-container",Qe="univer-find-replace-expand-container",Xe="univer-button-text",et="univer-find-replace-buttons-group",tt="univer-find-replace-buttons-group-right",$={findReplaceDialogContainer:Je,findReplaceExpandContainer:Qe,buttonText:Xe,findReplaceButtonsGroup:et,findReplaceButtonsGroupRight:tt};function oe(t,e){const n=l.useCallback(()=>{var s;(s=document.querySelector(".univer-find-input input"))==null||s.focus()},[]),i=l.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 l.useImperativeHandle(e,()=>({focus:n,selectHasFocus:i})),l.useEffect(()=>{const s=t.focusSignal$.subscribe(()=>n());return()=>s.unsubscribe()},[t,n]),{focus:n,selectHasFocus:i}}const it=l.forwardRef(function(e,n){const i=M.useDependency(c.LocaleService),s=M.useDependency(R),r=M.useDependency(c.ICommandService),a=h.useObservable(s.state$,void 0,!0),{findCompleted:o,findString:p,matchesCount:g,matchesPosition:v}=a,m=l.useCallback(()=>{r.executeCommand(k.id)},[r]),F=l.useCallback(x=>s.changeFindString(x),[s]);return oe(s,n),u.jsxs(l.Fragment,{children:[u.jsx(ae,{findCompleted:o,className:"univer-find-input",matchesCount:g,matchesPosition:v,findReplaceService:s,localeService:i,findString:p,onChange:F}),u.jsx("div",{className:$.findReplaceExpandContainer,children:u.jsx(f.Button,{type:"text",size:"small",onClick:m,children:i.t("find-replace.dialog.advanced-finding")})})]})}),nt=l.forwardRef(function(e,n){const i=M.useDependency(R),s=M.useDependency(c.LocaleService),r=M.useDependency(c.ICommandService),a=M.useDependency(h.IMessageService),o=h.useObservable(i.currentMatch$,void 0,!0),p=h.useObservable(i.replaceables$,void 0,!0),g=h.useObservable(i.state$,void 0,!0),{matchesCount:v,matchesPosition:m,findString:F,inputtingFindString:x,replaceString:de,caseSensitive:ue,matchesTheWholeCell:he,findDirection:fe,findScope:pe,findBy:_e,findCompleted:A}=g,ge=x.length===0,me=v===0||!(o!=null&&o.replaceable),ve=p.length===0,Se=l.useCallback(_=>i.changeInputtingFindString(_),[i]),Ce=l.useCallback(_=>i.changeReplaceString(_),[i]),{focus:Re}=oe(i,n),be=l.useCallback(()=>{F===x?i.moveToNextMatch():(i.changeFindString(x),i.find())},[F,x,i]),ye=l.useCallback(()=>r.executeCommand(se.id),[r]),Me=l.useCallback(async()=>{await r.executeCommand(re.id),Re()},[r]),xe=l.useCallback(_=>{i.changeFindDirection(_)},[i]),Ie=l.useCallback(_=>{i.changeFindScope(_)},[i]),Fe=l.useCallback(_=>{i.changeFindBy(_)},[i]),De=rt(s),Oe=at(s),Pe=ot(s);return l.useEffect(()=>{const _=A&&v===0;let D=null;return _&&(D=a.show({content:s.t("find-replace.dialog.no-match"),type:f.MessageType.Warning,duration:5e3})),()=>D==null?void 0:D.dispose()},[A,v,a,s]),u.jsxs(l.Fragment,{children:[u.jsx(f.FormLayout,{label:s.t("find-replace.dialog.find"),children:u.jsx(ae,{findCompleted:A,className:"univer-find-input",matchesCount:v,matchesPosition:m,findReplaceService:i,localeService:s,findString:x,onChange:Se})}),u.jsx(f.FormLayout,{label:s.t("find-replace.dialog.replace"),children:u.jsx(f.Input,{placeholder:s.t("find-replace.dialog.replace-placeholder"),value:de,onChange:_=>Ce(_)})}),u.jsx(f.FormLayout,{label:s.t("find-replace.dialog.find-direction.title"),children:u.jsx(f.Select,{value:fe,options:Oe,onChange:xe})}),u.jsx(f.FormDualColumnLayout,{children:u.jsxs(l.Fragment,{children:[u.jsx(f.FormLayout,{label:s.t("find-replace.dialog.find-scope.title"),children:u.jsx(f.Select,{value:pe,options:De,onChange:Ie})}),u.jsx(f.FormLayout,{label:s.t("find-replace.dialog.find-by.title"),children:u.jsx(f.Select,{value:_e,options:Pe,onChange:Fe})})]})}),u.jsx(f.FormDualColumnLayout,{children:u.jsxs(l.Fragment,{children:[u.jsx(f.FormLayout,{children:u.jsx(f.Checkbox,{checked:ue,onChange:_=>{i.changeCaseSensitive(_)},children:s.t("find-replace.dialog.case-sensitive")})}),u.jsx(f.FormLayout,{children:u.jsx(f.Checkbox,{checked:he,onChange:_=>{i.changeMatchesTheWholeCell(_)},children:s.t("find-replace.dialog.match-the-whole-cell")})})]})}),u.jsxs("div",{className:$.findReplaceButtonsGroup,children:[u.jsx(f.Button,{type:"primary",onClick:be,disabled:ge,children:s.t("find-replace.dialog.find")}),u.jsxs("span",{className:$.findReplaceButtonsGroupRight,children:[u.jsx(f.Button,{disabled:me,onClick:ye,children:s.t("find-replace.dialog.replace")}),u.jsx(f.Button,{disabled:ve,onClick:Me,children:s.t("find-replace.dialog.replace-all")})]})]})]})});function st(){const t=M.useDependency(R),e=M.useDependency(h.ILayoutService),n=M.useDependency(c.IContextService),i=h.useObservable(t.state$,void 0,!0),s=l.useRef(null);l.useEffect(()=>{let p;return s.current&&(p=e.registerContainerElement(s.current)),()=>p==null?void 0:p.dispose()},[e]);const r=l.useRef(null),a=l.useCallback(p=>n.setContextValue(J,p),[n]),o=l.useCallback(p=>n.setContextValue(Z,p),[n]);return l.useEffect(()=>{var g;const p=S.fromEvent(document,"focusin").subscribe(v=>{var m;v.target&&((m=s.current)!=null&&m.contains(v.target))?a(!0):a(!1),!r.current||!r.current.selectHasFocus()?o(!0):o(!1)});return(g=r.current)==null||g.focus(),a(!0),o(!0),()=>{p.unsubscribe(),a(!1)}},[a,o]),u.jsx("div",{className:$.findReplaceDialogContainer,ref:s,children:i.replaceRevealed?u.jsx(nt,{ref:r}):u.jsx(it,{ref:r})})}function rt(t){const e=t.getCurrentLocale();return l.useMemo(()=>[{label:t.t("find-replace.dialog.find-scope.current-sheet"),value:E.SUBUNIT},{label:t.t("find-replace.dialog.find-scope.workbook"),value:E.UNIT}],[e])}function at(t){const e=t.getCurrentLocale();return l.useMemo(()=>[{label:t.t("find-replace.dialog.find-direction.row"),value:P.ROW},{label:t.t("find-replace.dialog.find-direction.column"),value:P.COLUMN}],[e])}function ot(t){const e=t.getCurrentLocale();return l.useMemo(()=>[{label:t.t("find-replace.dialog.find-by.value"),value:T.VALUE},{label:t.t("find-replace.dialog.find-by.formula"),value:T.FORMULA}],[e])}function I(t){return t.getContextValue(J)}function ct(t){return t.getContextValue(Q)}function ce(t){return t.getContextValue(Z)}const L="7_find-replace-shortcuts";function G(t){return t.getContextValue(c.FOCUSING_SHEET)}function V(t){return!t.getContextValue(c.EDITOR_ACTIVATED)}const lt={id:j.id,description:"find-replace.shortcut.open-find-dialog",binding:h.KeyCode.F|h.MetaKeys.CTRL_COMMAND,group:L,preconditions(t){return!I(t)&&G(t)&&V(t)}},dt={id:j.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(t){return!I(t)&&G(t)&&V(t)}},ut={id:k.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:L,preconditions(t){return G(t)&&V(t)&&(!I(t)||!ct(t))}},ht={id:ee.id,description:"find-replace.shortcut.go-to-next-match",binding:h.KeyCode.ENTER,group:L,priority:1e3,preconditions(t){return ce(t)&&I(t)}},ft={id:te.id,description:"find-replace.shortcut.go-to-previous-match",binding:h.KeyCode.ENTER|h.MetaKeys.SHIFT,group:L,priority:1e3,preconditions(t){return ce(t)&&I(t)}};function pt(t){const e=t.get(c.IContextService);return{id:j.id,icon:"SearchIcon",tooltip:"find-replace.toolbar",group:h.MenuGroup.TOOLBAR_OTHERS,type:h.MenuItemType.BUTTON,positions:[h.MenuPosition.TOOLBAR_START],hidden$:h.getMenuHiddenObservable(t,c.UniverInstanceType.UNIVER_SHEET),disabled$:S.combineLatest([e.subscribeContextValue$(c.EDITOR_ACTIVATED),e.subscribeContextValue$(c.FOCUSING_SHEET)]).pipe(S.map(([n,i])=>n||!i))}}var _t=Object.defineProperty,gt=Object.getOwnPropertyDescriptor,mt=(t,e,n,i)=>{for(var s=i>1?void 0:i?gt(e,n):e,r=t.length-1,a;r>=0;r--)(a=t[r])&&(s=(i?a(e,n,s):a(s))||s);return i&&s&&_t(e,n,s),s},b=(t,e)=>(n,i)=>e(n,i,t);const vt={},H="DESKTOP_FIND_REPLACE_DIALOG",le=350,St=20,Ct=-90;exports.FindReplaceController=class extends c.RxDisposable{constructor(e,n,i,s,r,a,o,p,g,v,m){super(),this._config=e,this._univerInstanceService=n,this._menuService=i,this._shortcutService=s,this._commandService=r,this._findReplaceService=a,this._dialogService=o,this._layoutService=p,this._localeService=g,this._componentManager=v,this._injector=m,this._initCommands(),this._initUI(),this._initShortcuts()}_initCommands(){[j,k,ee,te,re,se].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initShortcuts(){[ut,lt,dt,ft,ht].forEach(e=>this.disposeWithMe(this._shortcutService.registerShortcut(e)))}_initUI(){const{menu:e={}}=this._config;this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(pt),e)),this.disposeWithMe(this._componentManager.register("FindReplaceDialog",st)),this.disposeWithMe(this._componentManager.register("SearchIcon",Y)),this._findReplaceService.stateUpdates$.pipe(S.takeUntil(this.dispose$)).subscribe(n=>{n.revealed===!0&&this._openPanel()}),this.disposeWithMe(this._univerInstanceService.focused$.pipe(S.takeUntil(this.dispose$)).subscribe(n=>{(!n||!this._univerInstanceService.getUniverSheetInstance(n))&&this.closePanel()}))}_openPanel(){this._dialogService.open({id:H,draggable:!0,width:le,title:{title:this._localeService.t("find-replace.dialog.title")},children:{label:"FindReplaceDialog"},destroyOnClose:!0,defaultPosition:Rt(),preservePositionOnDestroy:!0,onClose:()=>this.closePanel()})}closePanel(){this._dialogService.close(H),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus())}};exports.FindReplaceController=mt([c.OnLifecycle(c.LifecycleStages.Rendered,exports.FindReplaceController),b(1,c.IUniverInstanceService),b(2,h.IMenuService),b(3,h.IShortcutService),b(4,c.ICommandService),b(5,R),b(6,h.IDialogService),b(7,h.ILayoutService),b(8,y.Inject(c.LocaleService)),b(9,y.Inject(h.ComponentManager)),b(10,y.Inject(y.Injector))],exports.FindReplaceController);function Rt(){const{innerWidth:t}=window;return{x:(t-le)/2-St,y:Ct}}var bt=Object.defineProperty,yt=Object.getOwnPropertyDescriptor,Mt=(t,e,n,i)=>{for(var s=i>1?void 0:i?yt(e,n):e,r=t.length-1,a;r>=0;r--)(a=t[r])&&(s=(i?a(e,n,s):a(s))||s);return i&&s&&bt(e,n,s),s},K=(t,e)=>(n,i)=>e(n,i,t);const xt="FIND_REPLACE_PLUGIN";var w;exports.UniverFindReplacePlugin=(w=class extends c.Plugin{constructor(e={},n,i){super(),this._config=e,this._injector=n,this._localeService=i,this._config=c.Tools.deepMerge({},vt,this._config)}onStarting(e){[[exports.FindReplaceController,{useFactory:()=>this._injector.createInstance(exports.FindReplaceController,this._config)}],[R,{useClass:B}]].forEach(n=>{e.add(n)})}},d(w,"pluginName",xt),w);exports.UniverFindReplacePlugin=Mt([K(1,y.Inject(y.Injector)),K(2,y.Inject(c.LocaleService))],exports.UniverFindReplacePlugin);exports.FindBy=T;exports.FindDirection=P;exports.FindModel=We;exports.FindScope=E;exports.IFindReplaceService=R;
|
|
9
|
+
*/var Ve=c,He=Symbol.for("react.element"),Ke=Symbol.for("react.fragment"),qe=Object.prototype.hasOwnProperty,ze=Ve.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Ye={key:!0,ref:!0,__self:!0,__source:!0};function ne(t,e,n){var i,s={},r=null,a=null;n!==void 0&&(r=""+n),e.key!==void 0&&(r=""+e.key),e.ref!==void 0&&(a=e.ref);for(i in e)qe.call(e,i)&&!Ye.hasOwnProperty(i)&&(s[i]=e[i]);if(t&&t.defaultProps)for(i in e=t.defaultProps,e)s[i]===void 0&&(s[i]=e[i]);return{$$typeof:He,type:t,key:r,ref:a,props:s,_owner:ze.current}}j.Fragment=Ke;j.jsx=ne;j.jsxs=ne;ie.exports=j;var u=ie.exports;const se={id:"ui.command.replace-current-match",type:l.CommandType.COMMAND,handler:t=>t.get(R).replace()},Ze="CONFIRM_REPLACE_ALL",re={id:"ui.command.replace-all-matches",type:l.CommandType.COMMAND,handler:async t=>{const e=t.get(h.IConfirmService),n=t.get(l.LocaleService),i=t.get(h.IMessageService);if(!await e.confirm({id:Ze,title:{title:n.t("find-replace.replace.confirm.title")},cancelText:n.t("button.cancel"),confirmText:n.t("button.confirm")}))return!1;const r=await t.get(R).replaceAll(),{success:a,failure:o}=r;return o>0?(a===0?i.show({type:f.MessageType.Error,content:n.t("find-replace.replace.all-failure")}):i.show({type:f.MessageType.Warning,content:n.t("find-replace.replace.partial-success",`${a}`,`${o}`)}),!1):(i.show({type:f.MessageType.Success,content:n.t("find-replace.replace.all-success",`${a}`)}),!0)}};function ae(t){const{findCompleted:e,localeService:n,matchesCount:i,matchesPosition:s,findString:r,findReplaceService:a,onChange:o,...p}=t,v=e&&i===0?n.t("find-replace.dialog.no-result"):i===0?" ":void 0;return u.jsx(f.InputWithSlot,{autoFocus:!0,placeholder:n.t("find-replace.dialog.find-placeholder"),slot:u.jsx(f.Pager,{loop:!0,text:v,value:s,total:i,onChange:m=>{s===i&&m===1?a.moveToNextMatch():s===1&&m===i||m<s?a.moveToPreviousMatch():a.moveToNextMatch()}}),value:r,onChange:m=>o==null?void 0:o(m),...p})}const Je="univer-find-replace-dialog-container",Qe="univer-find-replace-expand-container",Xe="univer-button-text",et="univer-find-replace-buttons-group",tt="univer-find-replace-buttons-group-right",E={findReplaceDialogContainer:Je,findReplaceExpandContainer:Qe,buttonText:Xe,findReplaceButtonsGroup:et,findReplaceButtonsGroupRight:tt};function oe(t,e){const n=c.useCallback(()=>{var s;(s=document.querySelector(".univer-find-input input"))==null||s.focus()},[]),i=c.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 c.useImperativeHandle(e,()=>({focus:n,selectHasFocus:i})),c.useEffect(()=>{const s=t.focusSignal$.subscribe(()=>n());return()=>s.unsubscribe()},[t,n]),{focus:n,selectHasFocus:i}}const it=c.forwardRef(function(e,n){const i=M.useDependency(l.LocaleService),s=M.useDependency(R),r=M.useDependency(l.ICommandService),a=h.useObservable(s.state$,void 0,!0),{findCompleted:o,findString:p,matchesCount:g,matchesPosition:v}=a,m=c.useCallback(()=>{r.executeCommand(k.id)},[r]),F=c.useCallback(x=>s.changeFindString(x),[s]);return oe(s,n),u.jsxs(c.Fragment,{children:[u.jsx(ae,{findCompleted:o,className:"univer-find-input",matchesCount:g,matchesPosition:v,findReplaceService:s,localeService:i,findString:p,onChange:F}),u.jsx("div",{className:E.findReplaceExpandContainer,children:u.jsx(f.Button,{type:"text",size:"small",onClick:m,children:i.t("find-replace.dialog.advanced-finding")})})]})}),nt=c.forwardRef(function(e,n){const i=M.useDependency(R),s=M.useDependency(l.LocaleService),r=M.useDependency(l.ICommandService),a=M.useDependency(h.IMessageService),o=h.useObservable(i.currentMatch$,void 0,!0),p=h.useObservable(i.replaceables$,void 0,!0),g=h.useObservable(i.state$,void 0,!0),{matchesCount:v,matchesPosition:m,findString:F,inputtingFindString:x,replaceString:de,caseSensitive:ue,matchesTheWholeCell:he,findDirection:fe,findScope:pe,findBy:_e,findCompleted:L}=g,ge=x.length===0,me=v===0||!(o!=null&&o.replaceable),ve=p.length===0,Se=c.useCallback(_=>i.changeInputtingFindString(_),[i]),Ce=c.useCallback(_=>i.changeReplaceString(_),[i]),{focus:Re}=oe(i,n),be=c.useCallback(()=>{F===x?i.moveToNextMatch():(i.changeFindString(x),i.find())},[F,x,i]),ye=c.useCallback(()=>r.executeCommand(se.id),[r]),Me=c.useCallback(async()=>{await r.executeCommand(re.id),Re()},[r]),xe=c.useCallback(_=>{i.changeFindDirection(_)},[i]),Ie=c.useCallback(_=>{i.changeFindScope(_)},[i]),Fe=c.useCallback(_=>{i.changeFindBy(_)},[i]),De=rt(s),Oe=at(s),Pe=ot(s);return c.useEffect(()=>{const _=L&&v===0;let D=null;return _&&(D=a.show({content:s.t("find-replace.dialog.no-match"),type:f.MessageType.Warning,duration:5e3})),()=>D==null?void 0:D.dispose()},[L,v,a,s]),u.jsxs(c.Fragment,{children:[u.jsx(f.FormLayout,{label:s.t("find-replace.dialog.find"),children:u.jsx(ae,{findCompleted:L,className:"univer-find-input",matchesCount:v,matchesPosition:m,findReplaceService:i,localeService:s,findString:x,onChange:Se})}),u.jsx(f.FormLayout,{label:s.t("find-replace.dialog.replace"),children:u.jsx(f.Input,{placeholder:s.t("find-replace.dialog.replace-placeholder"),value:de,onChange:_=>Ce(_)})}),u.jsx(f.FormLayout,{label:s.t("find-replace.dialog.find-direction.title"),children:u.jsx(f.Select,{value:fe,options:Oe,onChange:xe})}),u.jsx(f.FormDualColumnLayout,{children:u.jsxs(c.Fragment,{children:[u.jsx(f.FormLayout,{label:s.t("find-replace.dialog.find-scope.title"),children:u.jsx(f.Select,{value:pe,options:De,onChange:Ie})}),u.jsx(f.FormLayout,{label:s.t("find-replace.dialog.find-by.title"),children:u.jsx(f.Select,{value:_e,options:Pe,onChange:Fe})})]})}),u.jsx(f.FormDualColumnLayout,{children:u.jsxs(c.Fragment,{children:[u.jsx(f.FormLayout,{children:u.jsx(f.Checkbox,{checked:ue,onChange:_=>{i.changeCaseSensitive(_)},children:s.t("find-replace.dialog.case-sensitive")})}),u.jsx(f.FormLayout,{children:u.jsx(f.Checkbox,{checked:he,onChange:_=>{i.changeMatchesTheWholeCell(_)},children:s.t("find-replace.dialog.match-the-whole-cell")})})]})}),u.jsxs("div",{className:E.findReplaceButtonsGroup,children:[u.jsx(f.Button,{type:"primary",onClick:be,disabled:ge,children:s.t("find-replace.dialog.find")}),u.jsxs("span",{className:E.findReplaceButtonsGroupRight,children:[u.jsx(f.Button,{disabled:me,onClick:ye,children:s.t("find-replace.dialog.replace")}),u.jsx(f.Button,{disabled:ve,onClick:Me,children:s.t("find-replace.dialog.replace-all")})]})]})]})});function st(){const t=M.useDependency(R),e=M.useDependency(h.ILayoutService),n=M.useDependency(l.IContextService),i=h.useObservable(t.state$,void 0,!0),s=c.useRef(null);c.useEffect(()=>{let p;return s.current&&(p=e.registerContainerElement(s.current)),()=>p==null?void 0:p.dispose()},[e]);const r=c.useRef(null),a=c.useCallback(p=>n.setContextValue(J,p),[n]),o=c.useCallback(p=>n.setContextValue(Z,p),[n]);return c.useEffect(()=>{var g;const p=S.fromEvent(document,"focusin").subscribe(v=>{var m;v.target&&((m=s.current)!=null&&m.contains(v.target))?a(!0):a(!1),!r.current||!r.current.selectHasFocus()?o(!0):o(!1)});return(g=r.current)==null||g.focus(),a(!0),o(!0),()=>{p.unsubscribe(),a(!1)}},[a,o]),u.jsx("div",{className:E.findReplaceDialogContainer,ref:s,children:i.replaceRevealed?u.jsx(nt,{ref:r}):u.jsx(it,{ref:r})})}function rt(t){const e=t.getCurrentLocale();return c.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 at(t){const e=t.getCurrentLocale();return c.useMemo(()=>[{label:t.t("find-replace.dialog.find-direction.row"),value:O.ROW},{label:t.t("find-replace.dialog.find-direction.column"),value:O.COLUMN}],[e])}function ot(t){const e=t.getCurrentLocale();return c.useMemo(()=>[{label:t.t("find-replace.dialog.find-by.value"),value:P.VALUE},{label:t.t("find-replace.dialog.find-by.formula"),value:P.FORMULA}],[e])}function I(t){return t.getContextValue(J)}function ct(t){return t.getContextValue(Q)}function ce(t){return t.getContextValue(Z)}const N="7_find-replace-shortcuts";function G(t){return t.getContextValue(l.FOCUSING_SHEET)}function V(t){return!t.getContextValue(l.EDITOR_ACTIVATED)}const lt={id:$.id,description:"find-replace.shortcut.open-find-dialog",binding:h.KeyCode.F|h.MetaKeys.CTRL_COMMAND,group:N,preconditions(t){return!I(t)&&G(t)&&V(t)}},dt={id:$.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(t){return!I(t)&&G(t)&&V(t)}},ut={id:k.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:N,preconditions(t){return G(t)&&V(t)&&(!I(t)||!ct(t))}},ht={id:ee.id,description:"find-replace.shortcut.go-to-next-match",binding:h.KeyCode.ENTER,group:N,priority:1e3,preconditions(t){return ce(t)&&I(t)}},ft={id:te.id,description:"find-replace.shortcut.go-to-previous-match",binding:h.KeyCode.ENTER|h.MetaKeys.SHIFT,group:N,priority:1e3,preconditions(t){return ce(t)&&I(t)}};function pt(t){const e=t.get(l.IContextService);return{id:$.id,icon:"SearchIcon",tooltip:"find-replace.toolbar",group:h.MenuGroup.TOOLBAR_OTHERS,type:h.MenuItemType.BUTTON,positions:[h.MenuPosition.TOOLBAR_START],hidden$:h.getMenuHiddenObservable(t,l.UniverInstanceType.UNIVER_SHEET),disabled$:S.combineLatest([e.subscribeContextValue$(l.EDITOR_ACTIVATED),e.subscribeContextValue$(l.FOCUSING_SHEET)]).pipe(S.map(([n,i])=>n||!i))}}var _t=Object.defineProperty,gt=Object.getOwnPropertyDescriptor,mt=(t,e,n,i)=>{for(var s=i>1?void 0:i?gt(e,n):e,r=t.length-1,a;r>=0;r--)(a=t[r])&&(s=(i?a(e,n,s):a(s))||s);return i&&s&&_t(e,n,s),s},b=(t,e)=>(n,i)=>e(n,i,t);const vt={},H="DESKTOP_FIND_REPLACE_DIALOG",le=350,St=20,Ct=-90;exports.FindReplaceController=class extends l.RxDisposable{constructor(e,n,i,s,r,a,o,p,g,v,m){super(),this._config=e,this._univerInstanceService=n,this._menuService=i,this._shortcutService=s,this._commandService=r,this._findReplaceService=a,this._dialogService=o,this._layoutService=p,this._localeService=g,this._componentManager=v,this._injector=m,this._initCommands(),this._initUI(),this._initShortcuts()}_initCommands(){[$,k,ee,te,re,se].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initShortcuts(){[ut,lt,dt,ft,ht].forEach(e=>this.disposeWithMe(this._shortcutService.registerShortcut(e)))}_initUI(){const{menu:e={}}=this._config;this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(pt),e)),this.disposeWithMe(this._componentManager.register("FindReplaceDialog",st)),this.disposeWithMe(this._componentManager.register("SearchIcon",Y)),this._findReplaceService.stateUpdates$.pipe(S.takeUntil(this.dispose$)).subscribe(n=>{n.revealed===!0&&this._openPanel()}),this.disposeWithMe(this._univerInstanceService.focused$.pipe(S.takeUntil(this.dispose$)).subscribe(n=>{(!n||!this._univerInstanceService.getUniverSheetInstance(n))&&this.closePanel()}))}_openPanel(){this._dialogService.open({id:H,draggable:!0,width:le,title:{title:this._localeService.t("find-replace.dialog.title")},children:{label:"FindReplaceDialog"},destroyOnClose:!0,defaultPosition:Rt(),preservePositionOnDestroy:!0,onClose:()=>this.closePanel()})}closePanel(){this._dialogService.close(H),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus())}};exports.FindReplaceController=mt([l.OnLifecycle(l.LifecycleStages.Rendered,exports.FindReplaceController),b(1,l.IUniverInstanceService),b(2,h.IMenuService),b(3,h.IShortcutService),b(4,l.ICommandService),b(5,R),b(6,h.IDialogService),b(7,h.ILayoutService),b(8,y.Inject(l.LocaleService)),b(9,y.Inject(h.ComponentManager)),b(10,y.Inject(y.Injector))],exports.FindReplaceController);function Rt(){const{innerWidth:t}=window;return{x:(t-le)/2-St,y:Ct}}var bt=Object.defineProperty,yt=Object.getOwnPropertyDescriptor,Mt=(t,e,n,i)=>{for(var s=i>1?void 0:i?yt(e,n):e,r=t.length-1,a;r>=0;r--)(a=t[r])&&(s=(i?a(e,n,s):a(s))||s);return i&&s&&bt(e,n,s),s},K=(t,e)=>(n,i)=>e(n,i,t);const xt="FIND_REPLACE_PLUGIN";var A;exports.UniverFindReplacePlugin=(A=class extends l.Plugin{constructor(e={},n,i){super(),this._config=e,this._injector=n,this._localeService=i,this._config=l.Tools.deepMerge({},vt,this._config)}onStarting(e){[[exports.FindReplaceController,{useFactory:()=>this._injector.createInstance(exports.FindReplaceController,this._config)}],[R,{useClass:B}]].forEach(n=>{e.add(n)})}},d(A,"pluginName",xt),A);exports.UniverFindReplacePlugin=Mt([K(1,y.Inject(y.Injector)),K(2,y.Inject(l.LocaleService))],exports.UniverFindReplacePlugin);exports.FindBy=P;exports.FindDirection=O;exports.FindModel=We;exports.FindScope=T;exports.IFindReplaceService=R;
|
package/lib/es/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
var at = Object.defineProperty;
|
|
2
2
|
var ot = (t, e, n) => e in t ? at(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
|
|
3
3
|
var c = (t, e, n) => ot(t, typeof e != "symbol" ? e + "" : e, n);
|
|
4
|
-
import { Disposable as X, IUniverInstanceService as pe,
|
|
5
|
-
import { createIdentifier as
|
|
6
|
-
import { IConfirmService as
|
|
7
|
-
import { BehaviorSubject as P, Subject as Se, throttleTime as
|
|
8
|
-
import { RENDER_RAW_FORMULA_KEY as
|
|
9
|
-
import
|
|
10
|
-
import { MessageType as N, InputWithSlot as
|
|
4
|
+
import { Disposable as X, IUniverInstanceService as pe, toDisposable as H, IContextService as ee, DisposableCollection as ct, CommandType as y, LocaleService as D, ICommandService as te, FOCUSING_SHEET as _e, EDITOR_ACTIVATED as ge, UniverInstanceType as lt, RxDisposable as dt, OnLifecycle as ht, LifecycleStages as ut, Plugin as ft, Tools as pt } from "@univerjs/core";
|
|
5
|
+
import { createIdentifier as _t, Inject as x, Injector as ie } from "@wendellhu/redi";
|
|
6
|
+
import { IConfirmService as gt, IMessageService as me, useObservable as I, ILayoutService as ve, KeyCode as M, MetaKeys as b, MenuGroup as mt, MenuItemType as vt, MenuPosition as St, getMenuHiddenObservable as Ct, ComponentManager as Rt, IMenuService as Mt, IShortcutService as xt, IDialogService as bt } from "@univerjs/ui";
|
|
7
|
+
import { BehaviorSubject as P, Subject as Se, throttleTime as yt, combineLatest as Ce, debounceTime as It, fromEvent as Ft, map as Pt, takeUntil as ce } from "rxjs";
|
|
8
|
+
import { RENDER_RAW_FORMULA_KEY as Dt } from "@univerjs/engine-render";
|
|
9
|
+
import Ot, { forwardRef as w, useRef as q, createElement as Re, useCallback as _, Fragment as $, useEffect as j, useMemo as ne, useImperativeHandle as Tt } from "react";
|
|
10
|
+
import { MessageType as N, InputWithSlot as Et, Pager as $t, Button as A, FormLayout as R, Input as Nt, Select as V, FormDualColumnLayout as le, Checkbox as de } from "@univerjs/design";
|
|
11
11
|
import { useDependency as S } from "@wendellhu/redi/react-bindings";
|
|
12
12
|
var g = function() {
|
|
13
13
|
return g = Object.assign || function(t) {
|
|
@@ -17,23 +17,23 @@ var g = function() {
|
|
|
17
17
|
}
|
|
18
18
|
return t;
|
|
19
19
|
}, g.apply(this, arguments);
|
|
20
|
-
},
|
|
20
|
+
}, At = function(t, e) {
|
|
21
21
|
var n = {};
|
|
22
22
|
for (var i in t) Object.prototype.hasOwnProperty.call(t, i) && e.indexOf(i) < 0 && (n[i] = t[i]);
|
|
23
23
|
if (t != null && typeof Object.getOwnPropertySymbols == "function")
|
|
24
24
|
for (var s = 0, i = Object.getOwnPropertySymbols(t); s < i.length; s++)
|
|
25
25
|
e.indexOf(i[s]) < 0 && Object.prototype.propertyIsEnumerable.call(t, i[s]) && (n[i[s]] = t[i[s]]);
|
|
26
26
|
return n;
|
|
27
|
-
}, Me =
|
|
28
|
-
var n = t.icon, i = t.id, s = t.className, r = t.extend, a =
|
|
27
|
+
}, Me = w(function(t, e) {
|
|
28
|
+
var n = t.icon, i = t.id, s = t.className, r = t.extend, a = At(t, ["icon", "id", "className", "extend"]), o = "univerjs-icon univerjs-icon-".concat(i, " ").concat(s || "").trim(), d = q("_".concat(wt()));
|
|
29
29
|
return xe(n, "".concat(i), { defIds: n.defIds, idSuffix: d.current }, g({ ref: e, className: o }, a), r);
|
|
30
30
|
});
|
|
31
31
|
function xe(t, e, n, i, s) {
|
|
32
|
-
return Re(t.tag, g(g({ key: e },
|
|
32
|
+
return Re(t.tag, g(g({ key: e }, jt(t, n, s)), i), (Lt(t, n).children || []).map(function(r, a) {
|
|
33
33
|
return xe(r, "".concat(e, "-").concat(t.tag, "-").concat(a), n, void 0, s);
|
|
34
34
|
}));
|
|
35
35
|
}
|
|
36
|
-
function
|
|
36
|
+
function jt(t, e, n) {
|
|
37
37
|
var i = g({}, t.attrs);
|
|
38
38
|
n != null && n.colorChannel1 && i.fill === "colorChannel1" && (i.fill = n.colorChannel1);
|
|
39
39
|
var s = e.defIds;
|
|
@@ -42,38 +42,38 @@ function Lt(t, e, n) {
|
|
|
42
42
|
typeof o == "string" && (i[a] = o.replace(/url\(#(.*)\)/, "url(#$1".concat(e.idSuffix, ")")));
|
|
43
43
|
})), i;
|
|
44
44
|
}
|
|
45
|
-
function
|
|
45
|
+
function Lt(t, e) {
|
|
46
46
|
var n, i = e.defIds;
|
|
47
47
|
return !i || i.length === 0 ? t : t.tag === "defs" && (!((n = t.children) === null || n === void 0) && n.length) ? g(g({}, t), { children: t.children.map(function(s) {
|
|
48
48
|
return typeof s.attrs.id == "string" && i && i.indexOf(s.attrs.id) > -1 ? g(g({}, s), { attrs: g(g({}, s.attrs), { id: s.attrs.id + e.idSuffix }) }) : s;
|
|
49
49
|
}) }) : t;
|
|
50
50
|
}
|
|
51
|
-
function
|
|
51
|
+
function wt() {
|
|
52
52
|
return Math.random().toString(36).substring(2, 8);
|
|
53
53
|
}
|
|
54
54
|
Me.displayName = "UniverIcon";
|
|
55
|
-
var
|
|
55
|
+
var Ut = { 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" } }] }] }, be = w(function(t, e) {
|
|
56
56
|
return Re(Me, Object.assign({}, t, {
|
|
57
57
|
id: "search-single-16",
|
|
58
58
|
ref: e,
|
|
59
|
-
icon:
|
|
59
|
+
icon: Ut
|
|
60
60
|
}));
|
|
61
61
|
});
|
|
62
62
|
be.displayName = "SearchSingle16";
|
|
63
63
|
const ye = "FIND_REPLACE_INPUT_FOCUS", Ie = "FIND_REPLACE_DIALOG_FOCUS", Fe = "FIND_REPLACE_REPLACE_REVEALED";
|
|
64
|
-
var
|
|
65
|
-
for (var s = i > 1 ? void 0 : i ?
|
|
64
|
+
var Bt = Object.defineProperty, Wt = Object.getOwnPropertyDescriptor, Pe = (t, e, n, i) => {
|
|
65
|
+
for (var s = i > 1 ? void 0 : i ? Wt(e, n) : e, r = t.length - 1, a; r >= 0; r--)
|
|
66
66
|
(a = t[r]) && (s = (i ? a(e, n, s) : a(s)) || s);
|
|
67
|
-
return i && s &&
|
|
68
|
-
},
|
|
69
|
-
class
|
|
67
|
+
return i && s && Bt(e, n, s), s;
|
|
68
|
+
}, z = (t, e) => (n, i) => e(n, i, t);
|
|
69
|
+
class Ai extends X {
|
|
70
70
|
}
|
|
71
|
-
const m =
|
|
72
|
-
function
|
|
71
|
+
const m = _t("find-replace.service");
|
|
72
|
+
function Gt(t) {
|
|
73
73
|
return typeof t.findString < "u" || typeof t.inputtingFindString < "u" || typeof t.findDirection < "u" || typeof t.matchesTheWholeCell < "u" || typeof t.caseSensitive < "u" || typeof t.findScope < "u" || typeof t.findBy < "u";
|
|
74
74
|
}
|
|
75
75
|
let K = class extends X {
|
|
76
|
-
constructor(e, n, i
|
|
76
|
+
constructor(e, n, i) {
|
|
77
77
|
super();
|
|
78
78
|
c(this, "currentMatch$", new P(null));
|
|
79
79
|
c(this, "replaceables$", new P([]));
|
|
@@ -83,10 +83,10 @@ let K = class extends X {
|
|
|
83
83
|
c(this, "_matchingModel", null);
|
|
84
84
|
c(this, "_matches", []);
|
|
85
85
|
c(this, "_currentSearchingDisposables", null);
|
|
86
|
-
this._state = e, this._providers = n, this._univerInstanceService = i, this.
|
|
87
|
-
this._state.stateUpdates$.pipe(
|
|
88
|
-
const
|
|
89
|
-
|
|
86
|
+
this._state = e, this._providers = n, this._univerInstanceService = i, this.disposeWithMe(
|
|
87
|
+
this._state.stateUpdates$.pipe(yt(200, void 0, { leading: !0, trailing: !0 })).subscribe(async (s) => {
|
|
88
|
+
const r = this._state.state;
|
|
89
|
+
Gt(s) && (r.findString !== "" && !r.replaceRevealed ? (await this._startSearching(), this._state.changeState({ findCompleted: !0 })) : s.replaceRevealed !== !0 && this._stopSearching());
|
|
90
90
|
})
|
|
91
91
|
);
|
|
92
92
|
}
|
|
@@ -137,7 +137,7 @@ let K = class extends X {
|
|
|
137
137
|
}
|
|
138
138
|
// When a document's content changes, we should reset all matches and try to move to the next match.
|
|
139
139
|
_subscribeToModelsChanges(e) {
|
|
140
|
-
const n = this._currentSearchingDisposables = new
|
|
140
|
+
const n = this._currentSearchingDisposables = new ct(), i = Ce(e.map((s) => s.matchesUpdate$)).pipe(It(220)).subscribe(([...s]) => {
|
|
141
141
|
const r = this._matches = s.flat();
|
|
142
142
|
if (r.length) {
|
|
143
143
|
const a = this._moveToInitialMatch(this._findModels, r, !0);
|
|
@@ -145,10 +145,10 @@ let K = class extends X {
|
|
|
145
145
|
} else
|
|
146
146
|
this._state.changeState({ matchesCount: 0, matchesPosition: 0 }), this.replaceables$.next([]);
|
|
147
147
|
});
|
|
148
|
-
e.forEach((s) => n.add(
|
|
148
|
+
e.forEach((s) => n.add(H(s.activelyChangingMatch$.subscribe((r) => {
|
|
149
149
|
const a = this._matches.findIndex((o) => o === r);
|
|
150
150
|
this._state.changeState({ matchesPosition: a + 1 });
|
|
151
|
-
})))), n.add(
|
|
151
|
+
})))), n.add(H(i));
|
|
152
152
|
}
|
|
153
153
|
async replace() {
|
|
154
154
|
return this._matchingModel ? this._matchingModel.replace(this._state.replaceString) : !1;
|
|
@@ -209,8 +209,7 @@ let K = class extends X {
|
|
|
209
209
|
}
|
|
210
210
|
};
|
|
211
211
|
K = Pe([
|
|
212
|
-
|
|
213
|
-
L(3, ct)
|
|
212
|
+
z(2, pe)
|
|
214
213
|
], K);
|
|
215
214
|
var Y = /* @__PURE__ */ ((t) => (t.ROW = "row", t.COLUMN = "column", t))(Y || {}), Z = /* @__PURE__ */ ((t) => (t.VALUE = "value", t.FORMULA = "formula", t))(Z || {}), J = /* @__PURE__ */ ((t) => (t.SUBUNIT = "subunit", t.UNIT = "unit", t))(J || {});
|
|
216
215
|
function se() {
|
|
@@ -230,7 +229,7 @@ function se() {
|
|
|
230
229
|
revealed: !0
|
|
231
230
|
};
|
|
232
231
|
}
|
|
233
|
-
class
|
|
232
|
+
class Vt {
|
|
234
233
|
constructor() {
|
|
235
234
|
c(this, "_stateUpdates$", new Se());
|
|
236
235
|
c(this, "stateUpdates$", this._stateUpdates$.asObservable());
|
|
@@ -315,7 +314,7 @@ let Q = class extends X {
|
|
|
315
314
|
constructor(e, n) {
|
|
316
315
|
super();
|
|
317
316
|
c(this, "_providers", /* @__PURE__ */ new Set());
|
|
318
|
-
c(this, "_state", new
|
|
317
|
+
c(this, "_state", new Vt());
|
|
319
318
|
c(this, "_model");
|
|
320
319
|
c(this, "_currentMatch$", new P(null));
|
|
321
320
|
c(this, "currentMatch$", this._currentMatch$.asObservable());
|
|
@@ -410,20 +409,20 @@ let Q = class extends X {
|
|
|
410
409
|
(e = this._model) == null || e.dispose(), this._model = null, this._toggleDisplayRawFormula(!1), this._toggleRevealReplace(!1);
|
|
411
410
|
}
|
|
412
411
|
registerFindReplaceProvider(e) {
|
|
413
|
-
return this._providers.add(e),
|
|
412
|
+
return this._providers.add(e), H(() => this._providers.delete(e));
|
|
414
413
|
}
|
|
415
414
|
_toggleRevealReplace(e) {
|
|
416
415
|
this._contextService.setContextValue(Fe, e);
|
|
417
416
|
}
|
|
418
417
|
_toggleDisplayRawFormula(e) {
|
|
419
|
-
this._contextService.setContextValue(
|
|
418
|
+
this._contextService.setContextValue(Dt, e);
|
|
420
419
|
}
|
|
421
420
|
};
|
|
422
421
|
Q = Pe([
|
|
423
|
-
|
|
424
|
-
|
|
422
|
+
z(0, x(ie)),
|
|
423
|
+
z(1, ee)
|
|
425
424
|
], Q);
|
|
426
|
-
const
|
|
425
|
+
const U = {
|
|
427
426
|
id: "ui.operation.open-find-dialog",
|
|
428
427
|
type: y.OPERATION,
|
|
429
428
|
handler: (t) => {
|
|
@@ -446,7 +445,7 @@ const B = {
|
|
|
446
445
|
id: "ui.operation.go-to-previous-match",
|
|
447
446
|
handler: (t) => (t.get(m).moveToPreviousMatch(), !0)
|
|
448
447
|
};
|
|
449
|
-
var Te = { exports: {} },
|
|
448
|
+
var Te = { exports: {} }, B = {};
|
|
450
449
|
/**
|
|
451
450
|
* @license React
|
|
452
451
|
* react-jsx-runtime.production.min.js
|
|
@@ -456,30 +455,30 @@ var Te = { exports: {} }, W = {};
|
|
|
456
455
|
* This source code is licensed under the MIT license found in the
|
|
457
456
|
* LICENSE file in the root directory of this source tree.
|
|
458
457
|
*/
|
|
459
|
-
var
|
|
458
|
+
var kt = Ot, Ht = Symbol.for("react.element"), qt = Symbol.for("react.fragment"), zt = Object.prototype.hasOwnProperty, Kt = kt.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, Yt = { key: !0, ref: !0, __self: !0, __source: !0 };
|
|
460
459
|
function Ee(t, e, n) {
|
|
461
460
|
var i, s = {}, r = null, a = null;
|
|
462
461
|
n !== void 0 && (r = "" + n), e.key !== void 0 && (r = "" + e.key), e.ref !== void 0 && (a = e.ref);
|
|
463
|
-
for (i in e)
|
|
462
|
+
for (i in e) zt.call(e, i) && !Yt.hasOwnProperty(i) && (s[i] = e[i]);
|
|
464
463
|
if (t && t.defaultProps) for (i in e = t.defaultProps, e) s[i] === void 0 && (s[i] = e[i]);
|
|
465
|
-
return { $$typeof:
|
|
464
|
+
return { $$typeof: Ht, type: t, key: r, ref: a, props: s, _owner: Kt.current };
|
|
466
465
|
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
Te.exports =
|
|
466
|
+
B.Fragment = qt;
|
|
467
|
+
B.jsx = Ee;
|
|
468
|
+
B.jsxs = Ee;
|
|
469
|
+
Te.exports = B;
|
|
471
470
|
var l = Te.exports;
|
|
472
471
|
const $e = {
|
|
473
472
|
id: "ui.command.replace-current-match",
|
|
474
473
|
type: y.COMMAND,
|
|
475
474
|
handler: (t) => t.get(m).replace()
|
|
476
|
-
},
|
|
475
|
+
}, Zt = "CONFIRM_REPLACE_ALL", Ne = {
|
|
477
476
|
id: "ui.command.replace-all-matches",
|
|
478
477
|
type: y.COMMAND,
|
|
479
478
|
handler: async (t) => {
|
|
480
|
-
const e = t.get(
|
|
479
|
+
const e = t.get(gt), n = t.get(D), i = t.get(me);
|
|
481
480
|
if (!await e.confirm({
|
|
482
|
-
id:
|
|
481
|
+
id: Zt,
|
|
483
482
|
title: { title: n.t("find-replace.replace.confirm.title") },
|
|
484
483
|
cancelText: n.t("button.cancel"),
|
|
485
484
|
confirmText: n.t("button.confirm")
|
|
@@ -501,12 +500,12 @@ const $e = {
|
|
|
501
500
|
function Ae(t) {
|
|
502
501
|
const { findCompleted: e, localeService: n, matchesCount: i, matchesPosition: s, findString: r, findReplaceService: a, onChange: o, ...d } = t, f = e && i === 0 ? n.t("find-replace.dialog.no-result") : i === 0 ? " " : void 0;
|
|
503
502
|
return /* @__PURE__ */ l.jsx(
|
|
504
|
-
|
|
503
|
+
Et,
|
|
505
504
|
{
|
|
506
505
|
autoFocus: !0,
|
|
507
506
|
placeholder: n.t("find-replace.dialog.find-placeholder"),
|
|
508
507
|
slot: /* @__PURE__ */ l.jsx(
|
|
509
|
-
|
|
508
|
+
$t,
|
|
510
509
|
{
|
|
511
510
|
loop: !0,
|
|
512
511
|
text: f,
|
|
@@ -523,12 +522,12 @@ function Ae(t) {
|
|
|
523
522
|
}
|
|
524
523
|
);
|
|
525
524
|
}
|
|
526
|
-
const
|
|
527
|
-
findReplaceDialogContainer:
|
|
528
|
-
findReplaceExpandContainer:
|
|
529
|
-
buttonText:
|
|
530
|
-
findReplaceButtonsGroup:
|
|
531
|
-
findReplaceButtonsGroupRight:
|
|
525
|
+
const Jt = "univer-find-replace-dialog-container", Qt = "univer-find-replace-expand-container", Xt = "univer-button-text", ei = "univer-find-replace-buttons-group", ti = "univer-find-replace-buttons-group-right", L = {
|
|
526
|
+
findReplaceDialogContainer: Jt,
|
|
527
|
+
findReplaceExpandContainer: Qt,
|
|
528
|
+
buttonText: Xt,
|
|
529
|
+
findReplaceButtonsGroup: ei,
|
|
530
|
+
findReplaceButtonsGroupRight: ti
|
|
532
531
|
};
|
|
533
532
|
function je(t, e) {
|
|
534
533
|
const n = _(() => {
|
|
@@ -538,12 +537,12 @@ function je(t, e) {
|
|
|
538
537
|
const s = document.querySelectorAll(".univer-find-replace-dialog-container .univer-select-selection-search-input");
|
|
539
538
|
return Array.from(s).some((r) => r === document.activeElement);
|
|
540
539
|
}, []);
|
|
541
|
-
return
|
|
540
|
+
return Tt(e, () => ({ focus: n, selectHasFocus: i })), j(() => {
|
|
542
541
|
const s = t.focusSignal$.subscribe(() => n());
|
|
543
542
|
return () => s.unsubscribe();
|
|
544
543
|
}, [t, n]), { focus: n, selectHasFocus: i };
|
|
545
544
|
}
|
|
546
|
-
const
|
|
545
|
+
const ii = w(function(e, n) {
|
|
547
546
|
const i = S(D), s = S(m), r = S(te), a = I(s.state$, void 0, !0), { findCompleted: o, findString: d, matchesCount: u, matchesPosition: f } = a, p = _(() => {
|
|
548
547
|
r.executeCommand(re.id);
|
|
549
548
|
}, [r]), T = _((C) => s.changeFindString(C), [s]);
|
|
@@ -561,9 +560,9 @@ const ni = U(function(e, n) {
|
|
|
561
560
|
onChange: T
|
|
562
561
|
}
|
|
563
562
|
),
|
|
564
|
-
/* @__PURE__ */ l.jsx("div", { className:
|
|
563
|
+
/* @__PURE__ */ l.jsx("div", { className: L.findReplaceExpandContainer, children: /* @__PURE__ */ l.jsx(A, { type: "text", size: "small", onClick: p, children: i.t("find-replace.dialog.advanced-finding") }) })
|
|
565
564
|
] });
|
|
566
|
-
}),
|
|
565
|
+
}), ni = w(function(e, n) {
|
|
567
566
|
const i = S(m), s = S(D), r = S(te), a = S(me), o = I(i.currentMatch$, void 0, !0), d = I(i.replaceables$, void 0, !0), u = I(i.state$, void 0, !0), {
|
|
568
567
|
matchesCount: f,
|
|
569
568
|
matchesPosition: p,
|
|
@@ -575,7 +574,7 @@ const ni = U(function(e, n) {
|
|
|
575
574
|
findDirection: Ge,
|
|
576
575
|
findScope: Ve,
|
|
577
576
|
findBy: ke,
|
|
578
|
-
findCompleted:
|
|
577
|
+
findCompleted: G
|
|
579
578
|
} = u, He = C.length === 0, qe = f === 0 || !(o != null && o.replaceable), ze = d.length === 0, Ke = _(
|
|
580
579
|
(h) => i.changeInputtingFindString(h),
|
|
581
580
|
[i]
|
|
@@ -592,20 +591,20 @@ const ni = U(function(e, n) {
|
|
|
592
591
|
i.changeFindScope(h);
|
|
593
592
|
}, [i]), it = _((h) => {
|
|
594
593
|
i.changeFindBy(h);
|
|
595
|
-
}, [i]), nt =
|
|
594
|
+
}, [i]), nt = ri(s), st = ai(s), rt = oi(s);
|
|
596
595
|
return j(() => {
|
|
597
|
-
const h =
|
|
596
|
+
const h = G && f === 0;
|
|
598
597
|
let E = null;
|
|
599
598
|
return h && (E = a.show({
|
|
600
599
|
content: s.t("find-replace.dialog.no-match"),
|
|
601
600
|
type: N.Warning,
|
|
602
601
|
duration: 5e3
|
|
603
602
|
})), () => E == null ? void 0 : E.dispose();
|
|
604
|
-
}, [
|
|
603
|
+
}, [G, f, a, s]), /* @__PURE__ */ l.jsxs($, { children: [
|
|
605
604
|
/* @__PURE__ */ l.jsx(R, { label: s.t("find-replace.dialog.find"), children: /* @__PURE__ */ l.jsx(
|
|
606
605
|
Ae,
|
|
607
606
|
{
|
|
608
|
-
findCompleted:
|
|
607
|
+
findCompleted: G,
|
|
609
608
|
className: "univer-find-input",
|
|
610
609
|
matchesCount: f,
|
|
611
610
|
matchesPosition: p,
|
|
@@ -616,17 +615,17 @@ const ni = U(function(e, n) {
|
|
|
616
615
|
}
|
|
617
616
|
) }),
|
|
618
617
|
/* @__PURE__ */ l.jsx(R, { label: s.t("find-replace.dialog.replace"), children: /* @__PURE__ */ l.jsx(
|
|
619
|
-
|
|
618
|
+
Nt,
|
|
620
619
|
{
|
|
621
620
|
placeholder: s.t("find-replace.dialog.replace-placeholder"),
|
|
622
621
|
value: Ue,
|
|
623
622
|
onChange: (h) => Ye(h)
|
|
624
623
|
}
|
|
625
624
|
) }),
|
|
626
|
-
/* @__PURE__ */ l.jsx(R, { label: s.t("find-replace.dialog.find-direction.title"), children: /* @__PURE__ */ l.jsx(
|
|
625
|
+
/* @__PURE__ */ l.jsx(R, { label: s.t("find-replace.dialog.find-direction.title"), children: /* @__PURE__ */ l.jsx(V, { value: Ge, options: st, onChange: et }) }),
|
|
627
626
|
/* @__PURE__ */ l.jsx(le, { children: /* @__PURE__ */ l.jsxs($, { children: [
|
|
628
|
-
/* @__PURE__ */ l.jsx(R, { label: s.t("find-replace.dialog.find-scope.title"), children: /* @__PURE__ */ l.jsx(
|
|
629
|
-
/* @__PURE__ */ l.jsx(R, { label: s.t("find-replace.dialog.find-by.title"), children: /* @__PURE__ */ l.jsx(
|
|
627
|
+
/* @__PURE__ */ l.jsx(R, { label: s.t("find-replace.dialog.find-scope.title"), children: /* @__PURE__ */ l.jsx(V, { value: Ve, options: nt, onChange: tt }) }),
|
|
628
|
+
/* @__PURE__ */ l.jsx(R, { label: s.t("find-replace.dialog.find-by.title"), children: /* @__PURE__ */ l.jsx(V, { value: ke, options: rt, onChange: it }) })
|
|
630
629
|
] }) }),
|
|
631
630
|
/* @__PURE__ */ l.jsx(le, { children: /* @__PURE__ */ l.jsxs($, { children: [
|
|
632
631
|
/* @__PURE__ */ l.jsx(R, { children: /* @__PURE__ */ l.jsx(
|
|
@@ -650,22 +649,22 @@ const ni = U(function(e, n) {
|
|
|
650
649
|
}
|
|
651
650
|
) })
|
|
652
651
|
] }) }),
|
|
653
|
-
/* @__PURE__ */ l.jsxs("div", { className:
|
|
652
|
+
/* @__PURE__ */ l.jsxs("div", { className: L.findReplaceButtonsGroup, children: [
|
|
654
653
|
/* @__PURE__ */ l.jsx(A, { type: "primary", onClick: Je, disabled: He, children: s.t("find-replace.dialog.find") }),
|
|
655
|
-
/* @__PURE__ */ l.jsxs("span", { className:
|
|
654
|
+
/* @__PURE__ */ l.jsxs("span", { className: L.findReplaceButtonsGroupRight, children: [
|
|
656
655
|
/* @__PURE__ */ l.jsx(A, { disabled: qe, onClick: Qe, children: s.t("find-replace.dialog.replace") }),
|
|
657
656
|
/* @__PURE__ */ l.jsx(A, { disabled: ze, onClick: Xe, children: s.t("find-replace.dialog.replace-all") })
|
|
658
657
|
] })
|
|
659
658
|
] })
|
|
660
659
|
] });
|
|
661
660
|
});
|
|
662
|
-
function
|
|
663
|
-
const t = S(m), e = S(ve), n = S(ee), i = I(t.state$, void 0, !0), s =
|
|
661
|
+
function si() {
|
|
662
|
+
const t = S(m), e = S(ve), n = S(ee), i = I(t.state$, void 0, !0), s = q(null);
|
|
664
663
|
j(() => {
|
|
665
664
|
let d;
|
|
666
665
|
return s.current && (d = e.registerContainerElement(s.current)), () => d == null ? void 0 : d.dispose();
|
|
667
666
|
}, [e]);
|
|
668
|
-
const r =
|
|
667
|
+
const r = q(null), a = _(
|
|
669
668
|
(d) => n.setContextValue(Ie, d),
|
|
670
669
|
[n]
|
|
671
670
|
), o = _(
|
|
@@ -674,30 +673,30 @@ function ri() {
|
|
|
674
673
|
);
|
|
675
674
|
return j(() => {
|
|
676
675
|
var u;
|
|
677
|
-
const d =
|
|
676
|
+
const d = Ft(document, "focusin").subscribe((f) => {
|
|
678
677
|
var p;
|
|
679
678
|
f.target && ((p = s.current) != null && p.contains(f.target)) ? a(!0) : a(!1), !r.current || !r.current.selectHasFocus() ? o(!0) : o(!1);
|
|
680
679
|
});
|
|
681
680
|
return (u = r.current) == null || u.focus(), a(!0), o(!0), () => {
|
|
682
681
|
d.unsubscribe(), a(!1);
|
|
683
682
|
};
|
|
684
|
-
}, [a, o]), /* @__PURE__ */ l.jsx("div", { className:
|
|
683
|
+
}, [a, o]), /* @__PURE__ */ l.jsx("div", { className: L.findReplaceDialogContainer, ref: s, children: i.replaceRevealed ? /* @__PURE__ */ l.jsx(ni, { ref: r }) : /* @__PURE__ */ l.jsx(ii, { ref: r }) });
|
|
685
684
|
}
|
|
686
|
-
function
|
|
685
|
+
function ri(t) {
|
|
687
686
|
const e = t.getCurrentLocale();
|
|
688
687
|
return ne(() => [
|
|
689
688
|
{ label: t.t("find-replace.dialog.find-scope.current-sheet"), value: J.SUBUNIT },
|
|
690
689
|
{ label: t.t("find-replace.dialog.find-scope.workbook"), value: J.UNIT }
|
|
691
690
|
], [e]);
|
|
692
691
|
}
|
|
693
|
-
function
|
|
692
|
+
function ai(t) {
|
|
694
693
|
const e = t.getCurrentLocale();
|
|
695
694
|
return ne(() => [
|
|
696
695
|
{ label: t.t("find-replace.dialog.find-direction.row"), value: Y.ROW },
|
|
697
696
|
{ label: t.t("find-replace.dialog.find-direction.column"), value: Y.COLUMN }
|
|
698
697
|
], [e]);
|
|
699
698
|
}
|
|
700
|
-
function
|
|
699
|
+
function oi(t) {
|
|
701
700
|
const e = t.getCurrentLocale();
|
|
702
701
|
return ne(() => [
|
|
703
702
|
{ label: t.t("find-replace.dialog.find-by.value"), value: Z.VALUE },
|
|
@@ -707,92 +706,92 @@ function ci(t) {
|
|
|
707
706
|
function O(t) {
|
|
708
707
|
return t.getContextValue(Ie);
|
|
709
708
|
}
|
|
710
|
-
function
|
|
709
|
+
function ci(t) {
|
|
711
710
|
return t.getContextValue(Fe);
|
|
712
711
|
}
|
|
713
712
|
function Le(t) {
|
|
714
713
|
return t.getContextValue(ye);
|
|
715
714
|
}
|
|
716
|
-
const
|
|
715
|
+
const W = "7_find-replace-shortcuts";
|
|
717
716
|
function ae(t) {
|
|
718
717
|
return t.getContextValue(_e);
|
|
719
718
|
}
|
|
720
719
|
function oe(t) {
|
|
721
720
|
return !t.getContextValue(ge);
|
|
722
721
|
}
|
|
723
|
-
const
|
|
724
|
-
id:
|
|
722
|
+
const li = {
|
|
723
|
+
id: U.id,
|
|
725
724
|
description: "find-replace.shortcut.open-find-dialog",
|
|
726
725
|
binding: M.F | b.CTRL_COMMAND,
|
|
727
|
-
group:
|
|
726
|
+
group: W,
|
|
728
727
|
preconditions(t) {
|
|
729
728
|
return !O(t) && ae(t) && oe(t);
|
|
730
729
|
}
|
|
731
|
-
},
|
|
732
|
-
id:
|
|
730
|
+
}, di = {
|
|
731
|
+
id: U.id,
|
|
733
732
|
description: "find-replace.shortcut.open-find-dialog",
|
|
734
733
|
binding: M.F | b.CTRL_COMMAND,
|
|
735
734
|
mac: M.F | b.MAC_CTRL,
|
|
736
735
|
preconditions(t) {
|
|
737
736
|
return !O(t) && ae(t) && oe(t);
|
|
738
737
|
}
|
|
739
|
-
},
|
|
738
|
+
}, hi = {
|
|
740
739
|
id: re.id,
|
|
741
740
|
description: "find-replace.shortcut.open-replace-dialog",
|
|
742
741
|
binding: M.H | b.CTRL_COMMAND,
|
|
743
742
|
mac: M.H | b.MAC_CTRL,
|
|
744
|
-
group:
|
|
743
|
+
group: W,
|
|
745
744
|
preconditions(t) {
|
|
746
|
-
return ae(t) && oe(t) && (!O(t) || !
|
|
745
|
+
return ae(t) && oe(t) && (!O(t) || !ci(t));
|
|
747
746
|
}
|
|
748
|
-
},
|
|
747
|
+
}, ui = {
|
|
749
748
|
id: De.id,
|
|
750
749
|
description: "find-replace.shortcut.go-to-next-match",
|
|
751
750
|
binding: M.ENTER,
|
|
752
|
-
group:
|
|
751
|
+
group: W,
|
|
753
752
|
priority: 1e3,
|
|
754
753
|
preconditions(t) {
|
|
755
754
|
return Le(t) && O(t);
|
|
756
755
|
}
|
|
757
|
-
},
|
|
756
|
+
}, fi = {
|
|
758
757
|
id: Oe.id,
|
|
759
758
|
description: "find-replace.shortcut.go-to-previous-match",
|
|
760
759
|
binding: M.ENTER | b.SHIFT,
|
|
761
|
-
group:
|
|
760
|
+
group: W,
|
|
762
761
|
priority: 1e3,
|
|
763
762
|
preconditions(t) {
|
|
764
763
|
return Le(t) && O(t);
|
|
765
764
|
}
|
|
766
765
|
};
|
|
767
|
-
function
|
|
766
|
+
function pi(t) {
|
|
768
767
|
const e = t.get(ee);
|
|
769
768
|
return {
|
|
770
|
-
id:
|
|
769
|
+
id: U.id,
|
|
771
770
|
icon: "SearchIcon",
|
|
772
771
|
tooltip: "find-replace.toolbar",
|
|
773
|
-
group:
|
|
774
|
-
type:
|
|
775
|
-
positions: [
|
|
776
|
-
hidden$:
|
|
772
|
+
group: mt.TOOLBAR_OTHERS,
|
|
773
|
+
type: vt.BUTTON,
|
|
774
|
+
positions: [St.TOOLBAR_START],
|
|
775
|
+
hidden$: Ct(t, lt.UNIVER_SHEET),
|
|
777
776
|
disabled$: Ce([
|
|
778
777
|
e.subscribeContextValue$(ge),
|
|
779
778
|
e.subscribeContextValue$(_e)
|
|
780
|
-
]).pipe(
|
|
779
|
+
]).pipe(Pt(([n, i]) => n || !i))
|
|
781
780
|
};
|
|
782
781
|
}
|
|
783
|
-
var
|
|
784
|
-
for (var s = i > 1 ? void 0 : i ?
|
|
782
|
+
var _i = Object.defineProperty, gi = Object.getOwnPropertyDescriptor, mi = (t, e, n, i) => {
|
|
783
|
+
for (var s = i > 1 ? void 0 : i ? gi(e, n) : e, r = t.length - 1, a; r >= 0; r--)
|
|
785
784
|
(a = t[r]) && (s = (i ? a(e, n, s) : a(s)) || s);
|
|
786
|
-
return i && s &&
|
|
785
|
+
return i && s && _i(e, n, s), s;
|
|
787
786
|
}, v = (t, e) => (n, i) => e(n, i, t);
|
|
788
|
-
const
|
|
789
|
-
let F = class extends
|
|
787
|
+
const vi = {}, he = "DESKTOP_FIND_REPLACE_DIALOG", we = 350, Si = 20, Ci = -90;
|
|
788
|
+
let F = class extends dt {
|
|
790
789
|
constructor(t, e, n, i, s, r, a, o, d, u, f) {
|
|
791
790
|
super(), this._config = t, this._univerInstanceService = e, this._menuService = n, this._shortcutService = i, this._commandService = s, this._findReplaceService = r, this._dialogService = a, this._layoutService = o, this._localeService = d, this._componentManager = u, this._injector = f, this._initCommands(), this._initUI(), this._initShortcuts();
|
|
792
791
|
}
|
|
793
792
|
_initCommands() {
|
|
794
793
|
[
|
|
795
|
-
|
|
794
|
+
U,
|
|
796
795
|
re,
|
|
797
796
|
De,
|
|
798
797
|
Oe,
|
|
@@ -804,16 +803,16 @@ let F = class extends ht {
|
|
|
804
803
|
}
|
|
805
804
|
_initShortcuts() {
|
|
806
805
|
[
|
|
807
|
-
ui,
|
|
808
|
-
di,
|
|
809
806
|
hi,
|
|
810
|
-
|
|
811
|
-
|
|
807
|
+
li,
|
|
808
|
+
di,
|
|
809
|
+
fi,
|
|
810
|
+
ui
|
|
812
811
|
].forEach((t) => this.disposeWithMe(this._shortcutService.registerShortcut(t)));
|
|
813
812
|
}
|
|
814
813
|
_initUI() {
|
|
815
814
|
const { menu: t = {} } = this._config;
|
|
816
|
-
this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(
|
|
815
|
+
this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(pi), t)), this.disposeWithMe(this._componentManager.register("FindReplaceDialog", si)), this.disposeWithMe(this._componentManager.register("SearchIcon", be)), this._findReplaceService.stateUpdates$.pipe(ce(this.dispose$)).subscribe((e) => {
|
|
817
816
|
e.revealed === !0 && this._openPanel();
|
|
818
817
|
}), this.disposeWithMe(
|
|
819
818
|
this._univerInstanceService.focused$.pipe(ce(this.dispose$)).subscribe((e) => {
|
|
@@ -829,7 +828,7 @@ let F = class extends ht {
|
|
|
829
828
|
title: { title: this._localeService.t("find-replace.dialog.title") },
|
|
830
829
|
children: { label: "FindReplaceDialog" },
|
|
831
830
|
destroyOnClose: !0,
|
|
832
|
-
defaultPosition:
|
|
831
|
+
defaultPosition: Ri(),
|
|
833
832
|
preservePositionOnDestroy: !0,
|
|
834
833
|
onClose: () => this.closePanel()
|
|
835
834
|
});
|
|
@@ -838,33 +837,33 @@ let F = class extends ht {
|
|
|
838
837
|
this._dialogService.close(he), this._findReplaceService.terminate(), queueMicrotask(() => this._layoutService.focus());
|
|
839
838
|
}
|
|
840
839
|
};
|
|
841
|
-
F =
|
|
842
|
-
ut
|
|
840
|
+
F = mi([
|
|
841
|
+
ht(ut.Rendered, F),
|
|
843
842
|
v(1, pe),
|
|
844
|
-
v(2,
|
|
845
|
-
v(3,
|
|
843
|
+
v(2, Mt),
|
|
844
|
+
v(3, xt),
|
|
846
845
|
v(4, te),
|
|
847
846
|
v(5, m),
|
|
848
|
-
v(6,
|
|
847
|
+
v(6, bt),
|
|
849
848
|
v(7, ve),
|
|
850
849
|
v(8, x(D)),
|
|
851
|
-
v(9, x(
|
|
850
|
+
v(9, x(Rt)),
|
|
852
851
|
v(10, x(ie))
|
|
853
852
|
], F);
|
|
854
|
-
function
|
|
853
|
+
function Ri() {
|
|
855
854
|
const { innerWidth: t } = window;
|
|
856
|
-
return { x: (t - we) / 2 -
|
|
855
|
+
return { x: (t - we) / 2 - Si, y: Ci };
|
|
857
856
|
}
|
|
858
|
-
var
|
|
859
|
-
for (var s = i > 1 ? void 0 : i ?
|
|
857
|
+
var Mi = Object.defineProperty, xi = Object.getOwnPropertyDescriptor, bi = (t, e, n, i) => {
|
|
858
|
+
for (var s = i > 1 ? void 0 : i ? xi(e, n) : e, r = t.length - 1, a; r >= 0; r--)
|
|
860
859
|
(a = t[r]) && (s = (i ? a(e, n, s) : a(s)) || s);
|
|
861
|
-
return i && s &&
|
|
860
|
+
return i && s && Mi(e, n, s), s;
|
|
862
861
|
}, ue = (t, e) => (n, i) => e(n, i, t);
|
|
863
|
-
const
|
|
864
|
-
var
|
|
865
|
-
let fe = (
|
|
862
|
+
const yi = "FIND_REPLACE_PLUGIN";
|
|
863
|
+
var k;
|
|
864
|
+
let fe = (k = class extends ft {
|
|
866
865
|
constructor(t = {}, e, n) {
|
|
867
|
-
super(), this._config = t, this._injector = e, this._localeService = n, this._config =
|
|
866
|
+
super(), this._config = t, this._injector = e, this._localeService = n, this._config = pt.deepMerge({}, vi, this._config);
|
|
868
867
|
}
|
|
869
868
|
onStarting(t) {
|
|
870
869
|
[
|
|
@@ -881,15 +880,15 @@ let fe = (H = class extends pt {
|
|
|
881
880
|
}
|
|
882
881
|
);
|
|
883
882
|
}
|
|
884
|
-
}, c(
|
|
885
|
-
fe =
|
|
883
|
+
}, c(k, "pluginName", yi), k);
|
|
884
|
+
fe = bi([
|
|
886
885
|
ue(1, x(ie)),
|
|
887
886
|
ue(2, x(D))
|
|
888
887
|
], fe);
|
|
889
888
|
export {
|
|
890
889
|
Z as FindBy,
|
|
891
890
|
Y as FindDirection,
|
|
892
|
-
|
|
891
|
+
Ai as FindModel,
|
|
893
892
|
F as FindReplaceController,
|
|
894
893
|
J as FindScope,
|
|
895
894
|
m as IFindReplaceService,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Nullable, Disposable, IContextService,
|
|
1
|
+
import { Nullable, Disposable, IContextService, IUniverInstanceService } from '@univerjs/core';
|
|
2
2
|
import { IDisposable, Injector } from '@wendellhu/redi';
|
|
3
3
|
import { Observable, BehaviorSubject } from 'rxjs';
|
|
4
4
|
|
|
@@ -124,7 +124,6 @@ export declare class FindReplaceModel extends Disposable {
|
|
|
124
124
|
private readonly _state;
|
|
125
125
|
private readonly _providers;
|
|
126
126
|
private readonly _univerInstanceService;
|
|
127
|
-
private readonly _logService;
|
|
128
127
|
readonly currentMatch$: BehaviorSubject<Nullable<IFindMatch<unknown>>>;
|
|
129
128
|
readonly replaceables$: BehaviorSubject<IReplaceableMatch[]>;
|
|
130
129
|
/** All find models returned by providers. */
|
|
@@ -134,7 +133,7 @@ export declare class FindReplaceModel extends Disposable {
|
|
|
134
133
|
private _matches;
|
|
135
134
|
private _currentSearchingDisposables;
|
|
136
135
|
get searched(): boolean;
|
|
137
|
-
constructor(_state: FindReplaceState, _providers: Set<IFindReplaceProvider>, _univerInstanceService: IUniverInstanceService
|
|
136
|
+
constructor(_state: FindReplaceState, _providers: Set<IFindReplaceProvider>, _univerInstanceService: IUniverInstanceService);
|
|
138
137
|
dispose(): void;
|
|
139
138
|
start(): Promise<IFindComplete>;
|
|
140
139
|
/** Call this method to start a `searching`. */
|
package/lib/umd/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(h,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/engine-render"),require("react"),require("@univerjs/design"),require("@wendellhu/redi/react-bindings")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","@univerjs/ui","rxjs","@univerjs/engine-render","react","@univerjs/design","@wendellhu/redi/react-bindings"],o):(h=typeof globalThis<"u"?globalThis:h||self,o(h.UniverFindReplace={},h.UniverCore,h["@wendellhu/redi"],h.UniverUi,h.rxjs,h.UniverEngineRender,h.React,h.UniverDesign,h["@wendellhu/redi/react-bindings"]))})(this,function(h,o,S,f,C,he,l,p,M){"use strict";var Ct=Object.defineProperty;var Rt=(h,o,S)=>o in h?Ct(h,o,{enumerable:!0,configurable:!0,writable:!0,value:S}):h[o]=S;var d=(h,o,S)=>Rt(h,typeof o!="symbol"?o+"":o,S);var H;var y=function(){return y=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},y.apply(this,arguments)},ue=function(n,e){var i={};for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&e.indexOf(t)<0&&(i[t]=n[t]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var 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},$=l.forwardRef(function(n,e){var i=n.icon,t=n.id,s=n.className,a=n.extend,r=ue(n,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(t," ").concat(s||"").trim(),_=l.useRef("_".concat(_e()));return z(i,"".concat(t),{defIds:i.defIds,idSuffix:_.current},y({ref:e,className:c},r),a)});function z(n,e,i,t,s){return l.createElement(n.tag,y(y({key:e},fe(n,i,s)),t),(pe(n,i).children||[]).map(function(a,r){return z(a,"".concat(e,"-").concat(n.tag,"-").concat(r),i,void 0,s)}))}function fe(n,e,i){var t=y({},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 r=a[0],c=a[1];typeof c=="string"&&(t[r]=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)?y(y({},n),{children:n.children.map(function(s){return typeof s.attrs.id=="string"&&t&&t.indexOf(s.attrs.id)>-1?y(y({},s),{attrs:y(y({},s.attrs),{id:s.attrs.id+e.idSuffix})}):s})}):n}function _e(){return Math.random().toString(36).substring(2,8)}$.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"}}]}]},Y=l.forwardRef(function(n,e){return l.createElement($,Object.assign({},n,{id:"search-single-16",ref:e,icon:ge}))});Y.displayName="SearchSingle16";const Z="FIND_REPLACE_INPUT_FOCUS",J="FIND_REPLACE_DIALOG_FOCUS",Q="FIND_REPLACE_REPLACE_REVEALED";var me=Object.defineProperty,ve=Object.getOwnPropertyDescriptor,X=(n,e,i,t)=>{for(var s=t>1?void 0:t?ve(e,i):e,a=n.length-1,r;a>=0;a--)(r=n[a])&&(s=(t?r(e,i,s):r(s))||s);return t&&s&&me(e,i,s),s},D=(n,e)=>(i,t)=>e(i,t,n);class Se extends o.Disposable{}const b=S.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 U=class extends o.Disposable{constructor(e,i,t,s){super();d(this,"currentMatch$",new C.BehaviorSubject(null));d(this,"replaceables$",new C.BehaviorSubject([]));d(this,"_findModels",[]);d(this,"_matchingModel",null);d(this,"_matches",[]);d(this,"_currentSearchingDisposables",null);this._state=e,this._providers=i,this._univerInstanceService=t,this._logService=s,this.disposeWithMe(this._state.stateUpdates$.pipe(C.throttleTime(200,void 0,{leading:!0,trailing:!0})).subscribe(async a=>{const r=this._state.state;Ce(a)&&(r.findString!==""&&!r.replaceRevealed?(await this._startSearching(),this._state.changeState({findCompleted:!0})):a.replaceRevealed!==!0&&this._stopSearching())}))}get searched(){return this._findModels.length>0}dispose(){super.dispose(),this._stopSearching(),this.currentMatch$.complete(),this.replaceables$.complete(),this._state.changeState({...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),i=this._findModels=(await Promise.all(e.map(a=>a.find({findString:this._state.findString,findDirection:this._state.findDirection,findScope:this._state.findScope,findBy:this._state.findBy,replaceRevealed:this._state.replaceRevealed,caseSensitive:this._state.caseSensitive,matchesTheWholeCell:this._state.matchesTheWholeCell})))).flat();this._subscribeToModelsChanges(i);const t=this._matches=i.map(a=>a.getMatches()).flat();if(this.replaceables$.next(t.filter(a=>a.replaceable)),!t.length)return this._state.changeState({matchesCount:0,matchesPosition:0}),{results:[]};const s=this._moveToInitialMatch(i,t);return this._state.changeState({matchesCount:t.length,matchesPosition:s+1}),{results:t}}_stopSearching(){var e;this._providers.forEach(i=>i.terminate()),this._findModels=[],this._matches=[],this._matchingModel=null,(e=this._currentSearchingDisposables)==null||e.dispose(),this._currentSearchingDisposables=null,this.currentMatch$.next(null),this.replaceables$.next([]),this._state.changeState({findCompleted:!1,matchesCount:0,matchesPosition:0})}_subscribeToModelsChanges(e){const i=this._currentSearchingDisposables=new o.DisposableCollection,t=C.combineLatest(e.map(s=>s.matchesUpdate$)).pipe(C.debounceTime(220)).subscribe(([...s])=>{const a=this._matches=s.flat();if(a.length){const r=this._moveToInitialMatch(this._findModels,a,!0);this._state.changeState({matchesCount:a.length,matchesPosition:r+1}),this.replaceables$.next(a.filter(c=>c.replaceable))}else this._state.changeState({matchesCount:0,matchesPosition:0}),this.replaceables$.next([])});e.forEach(s=>i.add(o.toDisposable(s.activelyChangingMatch$.subscribe(a=>{const r=this._matches.findIndex(c=>c===a);this._state.changeState({matchesPosition:r+1})})))),i.add(o.toDisposable(t))}async replace(){return this._matchingModel?this._matchingModel.replace(this._state.replaceString):!1}async replaceAll(){const e=await Promise.all(this._findModels.map(i=>i.replaceAll(this._state.replaceString))).then(i=>i.reduce((t,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}moveToNextMatch(){if(!this._matchingModel)return;const e=this._findModels.length===1,i=this._matchingModel.moveToNextMatch({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.findIndex(c=>c===this._matchingModel),s=this._findModels[(t+1)%this._findModels.length],a=s.moveToNextMatch(),r=this._matches.findIndex(c=>c===a);this.currentMatch$.next(a),this._matchingModel=s,this._state.changeState({matchesPosition:r+1})}}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.findIndex(c=>c===this._matchingModel),s=this._findModels[(t-1+this._findModels.length)%this._findModels.length],a=s.moveToPreviousMatch(),r=this._matches.findIndex(c=>c===a);this.currentMatch$.next(a),this._matchingModel=s,this._state.changeState({matchesPosition:r+1})}}_moveToInitialMatch(e,i,t=!1){var _;const s=(_=this._univerInstanceService.getFocusedUnit())==null?void 0:_.getUnitId();if(!s)return-1;const a=e.find(m=>m.unitId===s);if(a){this._matchingModel=a;const m=a.moveToNextMatch({stayIfOnMatch:!0,noFocus:t}),R=i.findIndex(v=>v===m);return this.currentMatch$.next(m),R}this._matchingModel=e[0];const r=this._matchingModel.moveToNextMatch({noFocus:t}),c=this._matches.findIndex(m=>m===r);return this.currentMatch$.next(r),c}};U=X([D(2,o.IUniverInstanceService),D(3,o.ILogService)],U);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 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 Re{constructor(){d(this,"_stateUpdates$",new C.Subject);d(this,"stateUpdates$",this._stateUpdates$.asObservable());d(this,"_state$",new C.BehaviorSubject(B()));d(this,"state$",this._state$.asObservable());d(this,"_findString","");d(this,"_inputtingFindString","");d(this,"_replaceString","");d(this,"_revealed",!1);d(this,"_replaceRevealed",!1);d(this,"_matchesPosition",0);d(this,"_matchesCount",0);d(this,"_caseSensitive",!0);d(this,"_matchesTheWholeCell",!1);d(this,"_findDirection","row");d(this,"_findScope","subunit");d(this,"_findBy","value");d(this,"_findCompleted",!1)}get state(){return this._state$.getValue()}get inputtingFindString(){return this._inputtingFindString}get findString(){return this._findString}get revealed(){return this._revealed}get replaceRevealed(){return this._replaceRevealed}get matchesPosition(){return this._matchesPosition}get matchesCount(){return this._matchesCount}get replaceString(){return this._replaceString}get caseSensitive(){return this._caseSensitive}get matchesTheWholeCell(){return this._matchesTheWholeCell}get findDirection(){return this._findDirection}get findScope(){return this._findScope}get findBy(){return this._findBy}get findCompleted(){return this._findCompleted}changeState(e){let i=!1;const t={};typeof e.findString<"u"&&e.findString!==this._findString&&(this._findString=e.findString,t.findString=this._findString,i=!0),typeof e.revealed<"u"&&e.revealed!==this._revealed&&(this._revealed=e.revealed,t.revealed=e.revealed,i=!0),typeof e.replaceRevealed<"u"&&e.replaceRevealed!==this._replaceRevealed&&(this._replaceRevealed=e.replaceRevealed,t.replaceRevealed=e.replaceRevealed,i=!0),typeof e.replaceString<"u"&&e.replaceString!==this._replaceString&&(this._replaceString=e.replaceString,t.replaceString=e.replaceString,i=!0),typeof e.matchesCount<"u"&&e.matchesCount!==this._matchesCount&&(this._matchesCount=e.matchesCount,t.matchesCount=e.matchesCount,i=!0),typeof e.matchesPosition<"u"&&e.matchesPosition!==this._matchesPosition&&(this._matchesPosition=e.matchesPosition,t.matchesPosition=e.matchesPosition,i=!0),typeof e.findBy<"u"&&e.findBy!==this._findBy&&(this._findBy=e.findBy,t.findBy=e.findBy,i=!0),typeof e.findScope<"u"&&e.findScope!==this._findScope&&(this._findScope=e.findScope,t.findScope=e.findScope,i=!0),typeof e.findDirection<"u"&&e.findDirection!==this._findDirection&&(this._findDirection=e.findDirection,t.findDirection=e.findDirection,i=!0),typeof e.caseSensitive<"u"&&e.caseSensitive!==this._caseSensitive&&(this._caseSensitive=e.caseSensitive,t.caseSensitive=e.caseSensitive,i=!0),typeof e.matchesTheWholeCell<"u"&&e.matchesTheWholeCell!==this._matchesTheWholeCell&&(this._matchesTheWholeCell=e.matchesTheWholeCell,t.matchesTheWholeCell=e.matchesTheWholeCell,i=!0),typeof e.inputtingFindString<"u"&&e.inputtingFindString!==this._inputtingFindString&&(this._inputtingFindString=e.inputtingFindString,t.inputtingFindString=e.inputtingFindString,i=!0),typeof e.findCompleted<"u"&&e.findCompleted!==this._findCompleted&&(this._findCompleted=e.findCompleted,t.findCompleted=e.findCompleted,i=!0),i&&(this._state$.next({caseSensitive:this._caseSensitive,findBy:this._findBy,findCompleted:this._findCompleted,findDirection:this._findDirection,findScope:this._findScope,findString:this._findString,inputtingFindString:this._inputtingFindString,matchesCount:this._matchesCount,matchesPosition:this._matchesPosition,matchesTheWholeCell:this._matchesTheWholeCell,replaceRevealed:this._replaceRevealed,revealed:this._revealed}),this._stateUpdates$.next(t))}}let W=class extends o.Disposable{constructor(e,i){super();d(this,"_providers",new Set);d(this,"_state",new Re);d(this,"_model");d(this,"_currentMatch$",new C.BehaviorSubject(null));d(this,"currentMatch$",this._currentMatch$.asObservable());d(this,"_replaceables$",new C.BehaviorSubject([]));d(this,"replaceables$",this._replaceables$.asObservable());d(this,"_focusSignal$",new C.Subject);d(this,"focusSignal$",this._focusSignal$.asObservable());this._injector=e,this._contextService=i}get stateUpdates$(){return this._state.stateUpdates$}get state$(){return this._state.state$}get revealed(){return this._state.revealed}get replaceRevealed(){return this._state.replaceRevealed}dispose(){super.dispose(),this._currentMatch$.next(null),this._currentMatch$.complete(),this._replaceables$.next([]),this._replaceables$.complete(),this._focusSignal$.complete()}getCurrentMatch(){var e;return(e=this._model)==null?void 0:e.getCurrentMatch()}getFindString(){return this._state.findString}changeFindString(e){this._state.changeState({findString:e})}focusFindInput(){this._focusSignal$.next()}changeInputtingFindString(e){e?this._state.changeState({inputtingFindString:e}):this._state.changeState({inputtingFindString:"",findString:""})}changeReplaceString(e){this._state.changeState({replaceString:e})}changeMatchesTheWholeCell(e){this._state.changeState({matchesTheWholeCell:e})}changeCaseSensitive(e){this._state.changeState({caseSensitive:e})}changeFindBy(e){this._state.changeState({findBy:e}),this._toggleDisplayRawFormula(e==="formula")}changeFindScope(e){this._state.changeState({findScope:e})}changeFindDirection(e){this._state.changeState({findDirection:e})}moveToNextMatch(){this._model&&(this._state.replaceRevealed&&!this._model.searched?(this._state.changeState({findString:this._state.inputtingFindString}),this._model.start()):this._model.moveToNextMatch(),this._focusSignal$.next())}moveToPreviousMatch(){this._model&&(this._state.replaceRevealed&&!this._model.searched?(this._state.changeState({findString:this._state.inputtingFindString}),this._model.start()):this._model.moveToPreviousMatch(),this._focusSignal$.next())}async replace(){return this._model?this._model.replace():!1}async replaceAll(){if(!this._model)throw new Error("[FindReplaceService] replaceAll: model is not initialized!");return this._model.replaceAll()}revealReplace(){this._state.changeState({replaceRevealed:!0,inputtingFindString:this._state.findString}),this._toggleRevealReplace(!0)}start(e=!1){if(this._providers.size===0)return!1;this._model=this._injector.createInstance(U,this._state,this._providers),this._model.currentMatch$.subscribe(t=>this._currentMatch$.next(t)),this._model.replaceables$.subscribe(t=>this._replaceables$.next(t));const i=B();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(Q,e)}_toggleDisplayRawFormula(e){this._contextService.setContextValue(he.RENDER_RAW_FORMULA_KEY,e)}};W=X([D(0,S.Inject(S.Injector)),D(1,o.IContextService)],W);const E={id:"ui.operation.open-find-dialog",type:o.CommandType.OPERATION,handler:n=>{const e=n.get(b);return e.revealed?e.focusFindInput():e.start(),!0}},k={id:"ui.operation.open-replace-dialog",type:o.CommandType.OPERATION,handler:n=>{const e=n.get(b);return e.revealed?e.replaceRevealed?e.focusFindInput():e.revealReplace():e.start(!0),!0}},q={type:o.CommandType.OPERATION,id:"ui.operation.go-to-next-match",handler:n=>(n.get(b).moveToNextMatch(),!0)},ee={type:o.CommandType.OPERATION,id:"ui.operation.go-to-previous-match",handler:n=>(n.get(b).moveToPreviousMatch(),!0)};var te={exports:{}},N={};/**
|
|
1
|
+
(function(h,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/engine-render"),require("react"),require("@univerjs/design"),require("@wendellhu/redi/react-bindings")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","@univerjs/ui","rxjs","@univerjs/engine-render","react","@univerjs/design","@wendellhu/redi/react-bindings"],o):(h=typeof globalThis<"u"?globalThis:h||self,o(h.UniverFindReplace={},h.UniverCore,h["@wendellhu/redi"],h.UniverUi,h.rxjs,h.UniverEngineRender,h.React,h.UniverDesign,h["@wendellhu/redi/react-bindings"]))})(this,function(h,o,S,f,C,he,l,p,M){"use strict";var Ct=Object.defineProperty;var Rt=(h,o,S)=>o in h?Ct(h,o,{enumerable:!0,configurable:!0,writable:!0,value:S}):h[o]=S;var d=(h,o,S)=>Rt(h,typeof o!="symbol"?o+"":o,S);var H;var y=function(){return y=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},y.apply(this,arguments)},ue=function(n,e){var i={};for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&e.indexOf(t)<0&&(i[t]=n[t]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var 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},$=l.forwardRef(function(n,e){var i=n.icon,t=n.id,s=n.className,a=n.extend,r=ue(n,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(t," ").concat(s||"").trim(),_=l.useRef("_".concat(_e()));return z(i,"".concat(t),{defIds:i.defIds,idSuffix:_.current},y({ref:e,className:c},r),a)});function z(n,e,i,t,s){return l.createElement(n.tag,y(y({key:e},fe(n,i,s)),t),(pe(n,i).children||[]).map(function(a,r){return z(a,"".concat(e,"-").concat(n.tag,"-").concat(r),i,void 0,s)}))}function fe(n,e,i){var t=y({},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 r=a[0],c=a[1];typeof c=="string"&&(t[r]=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)?y(y({},n),{children:n.children.map(function(s){return typeof s.attrs.id=="string"&&t&&t.indexOf(s.attrs.id)>-1?y(y({},s),{attrs:y(y({},s.attrs),{id:s.attrs.id+e.idSuffix})}):s})}):n}function _e(){return Math.random().toString(36).substring(2,8)}$.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"}}]}]},Y=l.forwardRef(function(n,e){return l.createElement($,Object.assign({},n,{id:"search-single-16",ref:e,icon:ge}))});Y.displayName="SearchSingle16";const Z="FIND_REPLACE_INPUT_FOCUS",J="FIND_REPLACE_DIALOG_FOCUS",Q="FIND_REPLACE_REPLACE_REVEALED";var me=Object.defineProperty,ve=Object.getOwnPropertyDescriptor,X=(n,e,i,t)=>{for(var s=t>1?void 0:t?ve(e,i):e,a=n.length-1,r;a>=0;a--)(r=n[a])&&(s=(t?r(e,i,s):r(s))||s);return t&&s&&me(e,i,s),s},w=(n,e)=>(i,t)=>e(i,t,n);class Se extends o.Disposable{}const b=S.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 U=class extends o.Disposable{constructor(e,i,t){super();d(this,"currentMatch$",new C.BehaviorSubject(null));d(this,"replaceables$",new C.BehaviorSubject([]));d(this,"_findModels",[]);d(this,"_matchingModel",null);d(this,"_matches",[]);d(this,"_currentSearchingDisposables",null);this._state=e,this._providers=i,this._univerInstanceService=t,this.disposeWithMe(this._state.stateUpdates$.pipe(C.throttleTime(200,void 0,{leading:!0,trailing:!0})).subscribe(async s=>{const a=this._state.state;Ce(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({...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),i=this._findModels=(await Promise.all(e.map(a=>a.find({findString:this._state.findString,findDirection:this._state.findDirection,findScope:this._state.findScope,findBy:this._state.findBy,replaceRevealed:this._state.replaceRevealed,caseSensitive:this._state.caseSensitive,matchesTheWholeCell:this._state.matchesTheWholeCell})))).flat();this._subscribeToModelsChanges(i);const t=this._matches=i.map(a=>a.getMatches()).flat();if(this.replaceables$.next(t.filter(a=>a.replaceable)),!t.length)return this._state.changeState({matchesCount:0,matchesPosition:0}),{results:[]};const s=this._moveToInitialMatch(i,t);return this._state.changeState({matchesCount:t.length,matchesPosition:s+1}),{results:t}}_stopSearching(){var e;this._providers.forEach(i=>i.terminate()),this._findModels=[],this._matches=[],this._matchingModel=null,(e=this._currentSearchingDisposables)==null||e.dispose(),this._currentSearchingDisposables=null,this.currentMatch$.next(null),this.replaceables$.next([]),this._state.changeState({findCompleted:!1,matchesCount:0,matchesPosition:0})}_subscribeToModelsChanges(e){const i=this._currentSearchingDisposables=new o.DisposableCollection,t=C.combineLatest(e.map(s=>s.matchesUpdate$)).pipe(C.debounceTime(220)).subscribe(([...s])=>{const a=this._matches=s.flat();if(a.length){const r=this._moveToInitialMatch(this._findModels,a,!0);this._state.changeState({matchesCount:a.length,matchesPosition:r+1}),this.replaceables$.next(a.filter(c=>c.replaceable))}else this._state.changeState({matchesCount:0,matchesPosition:0}),this.replaceables$.next([])});e.forEach(s=>i.add(o.toDisposable(s.activelyChangingMatch$.subscribe(a=>{const r=this._matches.findIndex(c=>c===a);this._state.changeState({matchesPosition:r+1})})))),i.add(o.toDisposable(t))}async replace(){return this._matchingModel?this._matchingModel.replace(this._state.replaceString):!1}async replaceAll(){const e=await Promise.all(this._findModels.map(i=>i.replaceAll(this._state.replaceString))).then(i=>i.reduce((t,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}moveToNextMatch(){if(!this._matchingModel)return;const e=this._findModels.length===1,i=this._matchingModel.moveToNextMatch({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.findIndex(c=>c===this._matchingModel),s=this._findModels[(t+1)%this._findModels.length],a=s.moveToNextMatch(),r=this._matches.findIndex(c=>c===a);this.currentMatch$.next(a),this._matchingModel=s,this._state.changeState({matchesPosition:r+1})}}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.findIndex(c=>c===this._matchingModel),s=this._findModels[(t-1+this._findModels.length)%this._findModels.length],a=s.moveToPreviousMatch(),r=this._matches.findIndex(c=>c===a);this.currentMatch$.next(a),this._matchingModel=s,this._state.changeState({matchesPosition:r+1})}}_moveToInitialMatch(e,i,t=!1){var _;const s=(_=this._univerInstanceService.getFocusedUnit())==null?void 0:_.getUnitId();if(!s)return-1;const a=e.find(m=>m.unitId===s);if(a){this._matchingModel=a;const m=a.moveToNextMatch({stayIfOnMatch:!0,noFocus:t}),R=i.findIndex(v=>v===m);return this.currentMatch$.next(m),R}this._matchingModel=e[0];const r=this._matchingModel.moveToNextMatch({noFocus:t}),c=this._matches.findIndex(m=>m===r);return this.currentMatch$.next(r),c}};U=X([w(2,o.IUniverInstanceService)],U);var D=(n=>(n.ROW="row",n.COLUMN="column",n))(D||{}),T=(n=>(n.VALUE="value",n.FORMULA="formula",n))(T||{}),O=(n=>(n.SUBUNIT="subunit",n.UNIT="unit",n))(O||{});function 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 Re{constructor(){d(this,"_stateUpdates$",new C.Subject);d(this,"stateUpdates$",this._stateUpdates$.asObservable());d(this,"_state$",new C.BehaviorSubject(B()));d(this,"state$",this._state$.asObservable());d(this,"_findString","");d(this,"_inputtingFindString","");d(this,"_replaceString","");d(this,"_revealed",!1);d(this,"_replaceRevealed",!1);d(this,"_matchesPosition",0);d(this,"_matchesCount",0);d(this,"_caseSensitive",!0);d(this,"_matchesTheWholeCell",!1);d(this,"_findDirection","row");d(this,"_findScope","subunit");d(this,"_findBy","value");d(this,"_findCompleted",!1)}get state(){return this._state$.getValue()}get inputtingFindString(){return this._inputtingFindString}get findString(){return this._findString}get revealed(){return this._revealed}get replaceRevealed(){return this._replaceRevealed}get matchesPosition(){return this._matchesPosition}get matchesCount(){return this._matchesCount}get replaceString(){return this._replaceString}get caseSensitive(){return this._caseSensitive}get matchesTheWholeCell(){return this._matchesTheWholeCell}get findDirection(){return this._findDirection}get findScope(){return this._findScope}get findBy(){return this._findBy}get findCompleted(){return this._findCompleted}changeState(e){let i=!1;const t={};typeof e.findString<"u"&&e.findString!==this._findString&&(this._findString=e.findString,t.findString=this._findString,i=!0),typeof e.revealed<"u"&&e.revealed!==this._revealed&&(this._revealed=e.revealed,t.revealed=e.revealed,i=!0),typeof e.replaceRevealed<"u"&&e.replaceRevealed!==this._replaceRevealed&&(this._replaceRevealed=e.replaceRevealed,t.replaceRevealed=e.replaceRevealed,i=!0),typeof e.replaceString<"u"&&e.replaceString!==this._replaceString&&(this._replaceString=e.replaceString,t.replaceString=e.replaceString,i=!0),typeof e.matchesCount<"u"&&e.matchesCount!==this._matchesCount&&(this._matchesCount=e.matchesCount,t.matchesCount=e.matchesCount,i=!0),typeof e.matchesPosition<"u"&&e.matchesPosition!==this._matchesPosition&&(this._matchesPosition=e.matchesPosition,t.matchesPosition=e.matchesPosition,i=!0),typeof e.findBy<"u"&&e.findBy!==this._findBy&&(this._findBy=e.findBy,t.findBy=e.findBy,i=!0),typeof e.findScope<"u"&&e.findScope!==this._findScope&&(this._findScope=e.findScope,t.findScope=e.findScope,i=!0),typeof e.findDirection<"u"&&e.findDirection!==this._findDirection&&(this._findDirection=e.findDirection,t.findDirection=e.findDirection,i=!0),typeof e.caseSensitive<"u"&&e.caseSensitive!==this._caseSensitive&&(this._caseSensitive=e.caseSensitive,t.caseSensitive=e.caseSensitive,i=!0),typeof e.matchesTheWholeCell<"u"&&e.matchesTheWholeCell!==this._matchesTheWholeCell&&(this._matchesTheWholeCell=e.matchesTheWholeCell,t.matchesTheWholeCell=e.matchesTheWholeCell,i=!0),typeof e.inputtingFindString<"u"&&e.inputtingFindString!==this._inputtingFindString&&(this._inputtingFindString=e.inputtingFindString,t.inputtingFindString=e.inputtingFindString,i=!0),typeof e.findCompleted<"u"&&e.findCompleted!==this._findCompleted&&(this._findCompleted=e.findCompleted,t.findCompleted=e.findCompleted,i=!0),i&&(this._state$.next({caseSensitive:this._caseSensitive,findBy:this._findBy,findCompleted:this._findCompleted,findDirection:this._findDirection,findScope:this._findScope,findString:this._findString,inputtingFindString:this._inputtingFindString,matchesCount:this._matchesCount,matchesPosition:this._matchesPosition,matchesTheWholeCell:this._matchesTheWholeCell,replaceRevealed:this._replaceRevealed,revealed:this._revealed}),this._stateUpdates$.next(t))}}let W=class extends o.Disposable{constructor(e,i){super();d(this,"_providers",new Set);d(this,"_state",new Re);d(this,"_model");d(this,"_currentMatch$",new C.BehaviorSubject(null));d(this,"currentMatch$",this._currentMatch$.asObservable());d(this,"_replaceables$",new C.BehaviorSubject([]));d(this,"replaceables$",this._replaceables$.asObservable());d(this,"_focusSignal$",new C.Subject);d(this,"focusSignal$",this._focusSignal$.asObservable());this._injector=e,this._contextService=i}get stateUpdates$(){return this._state.stateUpdates$}get state$(){return this._state.state$}get revealed(){return this._state.revealed}get replaceRevealed(){return this._state.replaceRevealed}dispose(){super.dispose(),this._currentMatch$.next(null),this._currentMatch$.complete(),this._replaceables$.next([]),this._replaceables$.complete(),this._focusSignal$.complete()}getCurrentMatch(){var e;return(e=this._model)==null?void 0:e.getCurrentMatch()}getFindString(){return this._state.findString}changeFindString(e){this._state.changeState({findString:e})}focusFindInput(){this._focusSignal$.next()}changeInputtingFindString(e){e?this._state.changeState({inputtingFindString:e}):this._state.changeState({inputtingFindString:"",findString:""})}changeReplaceString(e){this._state.changeState({replaceString:e})}changeMatchesTheWholeCell(e){this._state.changeState({matchesTheWholeCell:e})}changeCaseSensitive(e){this._state.changeState({caseSensitive:e})}changeFindBy(e){this._state.changeState({findBy:e}),this._toggleDisplayRawFormula(e==="formula")}changeFindScope(e){this._state.changeState({findScope:e})}changeFindDirection(e){this._state.changeState({findDirection:e})}moveToNextMatch(){this._model&&(this._state.replaceRevealed&&!this._model.searched?(this._state.changeState({findString:this._state.inputtingFindString}),this._model.start()):this._model.moveToNextMatch(),this._focusSignal$.next())}moveToPreviousMatch(){this._model&&(this._state.replaceRevealed&&!this._model.searched?(this._state.changeState({findString:this._state.inputtingFindString}),this._model.start()):this._model.moveToPreviousMatch(),this._focusSignal$.next())}async replace(){return this._model?this._model.replace():!1}async replaceAll(){if(!this._model)throw new Error("[FindReplaceService] replaceAll: model is not initialized!");return this._model.replaceAll()}revealReplace(){this._state.changeState({replaceRevealed:!0,inputtingFindString:this._state.findString}),this._toggleRevealReplace(!0)}start(e=!1){if(this._providers.size===0)return!1;this._model=this._injector.createInstance(U,this._state,this._providers),this._model.currentMatch$.subscribe(t=>this._currentMatch$.next(t)),this._model.replaceables$.subscribe(t=>this._replaceables$.next(t));const i=B();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(Q,e)}_toggleDisplayRawFormula(e){this._contextService.setContextValue(he.RENDER_RAW_FORMULA_KEY,e)}};W=X([w(0,S.Inject(S.Injector)),w(1,o.IContextService)],W);const P={id:"ui.operation.open-find-dialog",type:o.CommandType.OPERATION,handler:n=>{const e=n.get(b);return e.revealed?e.focusFindInput():e.start(),!0}},k={id:"ui.operation.open-replace-dialog",type:o.CommandType.OPERATION,handler:n=>{const e=n.get(b);return e.revealed?e.replaceRevealed?e.focusFindInput():e.revealReplace():e.start(!0),!0}},q={type:o.CommandType.OPERATION,id:"ui.operation.go-to-next-match",handler:n=>(n.get(b).moveToNextMatch(),!0)},ee={type:o.CommandType.OPERATION,id:"ui.operation.go-to-previous-match",handler:n=>(n.get(b).moveToPreviousMatch(),!0)};var te={exports:{}},E={};/**
|
|
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 ye=l,be=Symbol.for("react.element"),Me=Symbol.for("react.fragment"),Ie=Object.prototype.hasOwnProperty,Fe=ye.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,xe={key:!0,ref:!0,__self:!0,__source:!0};function ne(n,e,i){var t,s={},a=null,r=null;i!==void 0&&(a=""+i),e.key!==void 0&&(a=""+e.key),e.ref!==void 0&&(r=e.ref);for(t in e)Ie.call(e,t)&&!xe.hasOwnProperty(t)&&(s[t]=e[t]);if(n&&n.defaultProps)for(t in e=n.defaultProps,e)s[t]===void 0&&(s[t]=e[t]);return{$$typeof:be,type:n,key:a,ref:r,props:s,_owner:Fe.current}}N.Fragment=Me,N.jsx=ne,N.jsxs=ne,te.exports=N;var u=te.exports;const ie={id:"ui.command.replace-current-match",type:o.CommandType.COMMAND,handler:n=>n.get(b).replace()},De="CONFIRM_REPLACE_ALL",se={id:"ui.command.replace-all-matches",type:o.CommandType.COMMAND,handler:async n=>{const e=n.get(f.IConfirmService),i=n.get(o.LocaleService),t=n.get(f.IMessageService);if(!await e.confirm({id:De,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:r,failure:c}=a;return c>0?(r===0?t.show({type:p.MessageType.Error,content:i.t("find-replace.replace.all-failure")}):t.show({type:p.MessageType.Warning,content:i.t("find-replace.replace.partial-success",`${r}`,`${c}`)}),!1):(t.show({type:p.MessageType.Success,content:i.t("find-replace.replace.all-success",`${r}`)}),!0)}};function ae(n){const{findCompleted:e,localeService:i,matchesCount:t,matchesPosition:s,findString:a,findReplaceService:r,onChange:c,..._}=n,R=e&&t===0?i.t("find-replace.dialog.no-result"):t===0?" ":void 0;return u.jsx(p.InputWithSlot,{autoFocus:!0,placeholder:i.t("find-replace.dialog.find-placeholder"),slot:u.jsx(p.Pager,{loop:!0,text:R,value:s,total:t,onChange:v=>{s===t&&v===1?r.moveToNextMatch():s===1&&v===t||v<s?r.moveToPreviousMatch():r.moveToNextMatch()}}),value:a,onChange:v=>c==null?void 0:c(v),..._})}const j={findReplaceDialogContainer:"univer-find-replace-dialog-container",findReplaceExpandContainer:"univer-find-replace-expand-container",buttonText:"univer-button-text",findReplaceButtonsGroup:"univer-find-replace-buttons-group",findReplaceButtonsGroupRight:"univer-find-replace-buttons-group-right"};function re(n,e){const i=l.useCallback(()=>{var s;(s=document.querySelector(".univer-find-input input"))==null||s.focus()},[]),t=l.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 l.useImperativeHandle(e,()=>({focus:i,selectHasFocus:t})),l.useEffect(()=>{const s=n.focusSignal$.subscribe(()=>i());return()=>s.unsubscribe()},[n,i]),{focus:i,selectHasFocus:t}}const Te=l.forwardRef(function(e,i){const t=M.useDependency(o.LocaleService),s=M.useDependency(b),a=M.useDependency(o.ICommandService),r=f.useObservable(s.state$,void 0,!0),{findCompleted:c,findString:_,matchesCount:m,matchesPosition:R}=r,v=l.useCallback(()=>{a.executeCommand(k.id)},[a]),A=l.useCallback(F=>s.changeFindString(F),[s]);return re(s,i),u.jsxs(l.Fragment,{children:[u.jsx(ae,{findCompleted:c,className:"univer-find-input",matchesCount:m,matchesPosition:R,findReplaceService:s,localeService:t,findString:_,onChange:A}),u.jsx("div",{className:j.findReplaceExpandContainer,children:u.jsx(p.Button,{type:"text",size:"small",onClick:v,children:t.t("find-replace.dialog.advanced-finding")})})]})}),Oe=l.forwardRef(function(e,i){const t=M.useDependency(b),s=M.useDependency(o.LocaleService),a=M.useDependency(o.ICommandService),r=M.useDependency(f.IMessageService),c=f.useObservable(t.currentMatch$,void 0,!0),_=f.useObservable(t.replaceables$,void 0,!0),m=f.useObservable(t.state$,void 0,!0),{matchesCount:R,matchesPosition:v,findString:A,inputtingFindString:F,replaceString:qe,caseSensitive:et,matchesTheWholeCell:tt,findDirection:nt,findScope:it,findBy:st,findCompleted:K}=m,at=F.length===0,rt=R===0||!(c!=null&&c.replaceable),ot=_.length===0,ct=l.useCallback(g=>t.changeInputtingFindString(g),[t]),lt=l.useCallback(g=>t.changeReplaceString(g),[t]),{focus:dt}=re(t,i),ht=l.useCallback(()=>{A===F?t.moveToNextMatch():(t.changeFindString(F),t.find())},[A,F,t]),ut=l.useCallback(()=>a.executeCommand(ie.id),[a]),ft=l.useCallback(async()=>{await a.executeCommand(se.id),dt()},[a]),pt=l.useCallback(g=>{t.changeFindDirection(g)},[t]),_t=l.useCallback(g=>{t.changeFindScope(g)},[t]),gt=l.useCallback(g=>{t.changeFindBy(g)},[t]),mt=Ee(s),vt=Ne(s),St=je(s);return l.useEffect(()=>{const g=K&&R===0;let w=null;return g&&(w=r.show({content:s.t("find-replace.dialog.no-match"),type:p.MessageType.Warning,duration:5e3})),()=>w==null?void 0:w.dispose()},[K,R,r,s]),u.jsxs(l.Fragment,{children:[u.jsx(p.FormLayout,{label:s.t("find-replace.dialog.find"),children:u.jsx(ae,{findCompleted:K,className:"univer-find-input",matchesCount:R,matchesPosition:v,findReplaceService:t,localeService:s,findString:F,onChange:ct})}),u.jsx(p.FormLayout,{label:s.t("find-replace.dialog.replace"),children:u.jsx(p.Input,{placeholder:s.t("find-replace.dialog.replace-placeholder"),value:qe,onChange:g=>lt(g)})}),u.jsx(p.FormLayout,{label:s.t("find-replace.dialog.find-direction.title"),children:u.jsx(p.Select,{value:nt,options:vt,onChange:pt})}),u.jsx(p.FormDualColumnLayout,{children:u.jsxs(l.Fragment,{children:[u.jsx(p.FormLayout,{label:s.t("find-replace.dialog.find-scope.title"),children:u.jsx(p.Select,{value:it,options:mt,onChange:_t})}),u.jsx(p.FormLayout,{label:s.t("find-replace.dialog.find-by.title"),children:u.jsx(p.Select,{value:st,options:St,onChange:gt})})]})}),u.jsx(p.FormDualColumnLayout,{children:u.jsxs(l.Fragment,{children:[u.jsx(p.FormLayout,{children:u.jsx(p.Checkbox,{checked:et,onChange:g=>{t.changeCaseSensitive(g)},children:s.t("find-replace.dialog.case-sensitive")})}),u.jsx(p.FormLayout,{children:u.jsx(p.Checkbox,{checked:tt,onChange:g=>{t.changeMatchesTheWholeCell(g)},children:s.t("find-replace.dialog.match-the-whole-cell")})})]})}),u.jsxs("div",{className:j.findReplaceButtonsGroup,children:[u.jsx(p.Button,{type:"primary",onClick:ht,disabled:at,children:s.t("find-replace.dialog.find")}),u.jsxs("span",{className:j.findReplaceButtonsGroupRight,children:[u.jsx(p.Button,{disabled:rt,onClick:ut,children:s.t("find-replace.dialog.replace")}),u.jsx(p.Button,{disabled:ot,onClick:ft,children:s.t("find-replace.dialog.replace-all")})]})]})]})});function Pe(){const n=M.useDependency(b),e=M.useDependency(f.ILayoutService),i=M.useDependency(o.IContextService),t=f.useObservable(n.state$,void 0,!0),s=l.useRef(null);l.useEffect(()=>{let _;return s.current&&(_=e.registerContainerElement(s.current)),()=>_==null?void 0:_.dispose()},[e]);const a=l.useRef(null),r=l.useCallback(_=>i.setContextValue(J,_),[i]),c=l.useCallback(_=>i.setContextValue(Z,_),[i]);return l.useEffect(()=>{var m;const _=C.fromEvent(document,"focusin").subscribe(R=>{var v;R.target&&((v=s.current)!=null&&v.contains(R.target))?r(!0):r(!1),!a.current||!a.current.selectHasFocus()?c(!0):c(!1)});return(m=a.current)==null||m.focus(),r(!0),c(!0),()=>{_.unsubscribe(),r(!1)}},[r,c]),u.jsx("div",{className:j.findReplaceDialogContainer,ref:s,children:t.replaceRevealed?u.jsx(Oe,{ref:a}):u.jsx(Te,{ref:a})})}function Ee(n){const e=n.getCurrentLocale();return l.useMemo(()=>[{label:n.t("find-replace.dialog.find-scope.current-sheet"),value:P.SUBUNIT},{label:n.t("find-replace.dialog.find-scope.workbook"),value:P.UNIT}],[e])}function Ne(n){const e=n.getCurrentLocale();return l.useMemo(()=>[{label:n.t("find-replace.dialog.find-direction.row"),value:T.ROW},{label:n.t("find-replace.dialog.find-direction.column"),value:T.COLUMN}],[e])}function je(n){const e=n.getCurrentLocale();return l.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(J)}function Le(n){return n.getContextValue(Q)}function oe(n){return n.getContextValue(Z)}const L="7_find-replace-shortcuts";function G(n){return n.getContextValue(o.FOCUSING_SHEET)}function V(n){return!n.getContextValue(o.EDITOR_ACTIVATED)}const Ae={id:E.id,description:"find-replace.shortcut.open-find-dialog",binding:f.KeyCode.F|f.MetaKeys.CTRL_COMMAND,group:L,preconditions(n){return!x(n)&&G(n)&&V(n)}},we={id:E.id,description:"find-replace.shortcut.open-find-dialog",binding:f.KeyCode.F|f.MetaKeys.CTRL_COMMAND,mac:f.KeyCode.F|f.MetaKeys.MAC_CTRL,preconditions(n){return!x(n)&&G(n)&&V(n)}},Ue={id:k.id,description:"find-replace.shortcut.open-replace-dialog",binding:f.KeyCode.H|f.MetaKeys.CTRL_COMMAND,mac:f.KeyCode.H|f.MetaKeys.MAC_CTRL,group:L,preconditions(n){return G(n)&&V(n)&&(!x(n)||!Le(n))}},Be={id:q.id,description:"find-replace.shortcut.go-to-next-match",binding:f.KeyCode.ENTER,group:L,priority:1e3,preconditions(n){return oe(n)&&x(n)}},We={id:ee.id,description:"find-replace.shortcut.go-to-previous-match",binding:f.KeyCode.ENTER|f.MetaKeys.SHIFT,group:L,priority:1e3,preconditions(n){return oe(n)&&x(n)}};function ke(n){const e=n.get(o.IContextService);return{id:E.id,icon:"SearchIcon",tooltip:"find-replace.toolbar",group:f.MenuGroup.TOOLBAR_OTHERS,type:f.MenuItemType.BUTTON,positions:[f.MenuPosition.TOOLBAR_START],hidden$:f.getMenuHiddenObservable(n,o.UniverInstanceType.UNIVER_SHEET),disabled$:C.combineLatest([e.subscribeContextValue$(o.EDITOR_ACTIVATED),e.subscribeContextValue$(o.FOCUSING_SHEET)]).pipe(C.map(([i,t])=>i||!t))}}var Ge=Object.defineProperty,Ve=Object.getOwnPropertyDescriptor,He=(n,e,i,t)=>{for(var s=t>1?void 0:t?Ve(e,i):e,a=n.length-1,r;a>=0;a--)(r=n[a])&&(s=(t?r(e,i,s):r(s))||s);return t&&s&&Ge(e,i,s),s},I=(n,e)=>(i,t)=>e(i,t,n);const Ke={},ce="DESKTOP_FIND_REPLACE_DIALOG",le=350,$e=20,ze=-90;h.FindReplaceController=class extends o.RxDisposable{constructor(e,i,t,s,a,r,c,_,m,R,v){super(),this._config=e,this._univerInstanceService=i,this._menuService=t,this._shortcutService=s,this._commandService=a,this._findReplaceService=r,this._dialogService=c,this._layoutService=_,this._localeService=m,this._componentManager=R,this._injector=v,this._initCommands(),this._initUI(),this._initShortcuts()}_initCommands(){[E,k,q,ee,se,ie].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initShortcuts(){[Ue,Ae,we,We,Be].forEach(e=>this.disposeWithMe(this._shortcutService.registerShortcut(e)))}_initUI(){const{menu:e={}}=this._config;this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(ke),e)),this.disposeWithMe(this._componentManager.register("FindReplaceDialog",Pe)),this.disposeWithMe(this._componentManager.register("SearchIcon",Y)),this._findReplaceService.stateUpdates$.pipe(C.takeUntil(this.dispose$)).subscribe(i=>{i.revealed===!0&&this._openPanel()}),this.disposeWithMe(this._univerInstanceService.focused$.pipe(C.takeUntil(this.dispose$)).subscribe(i=>{(!i||!this._univerInstanceService.getUniverSheetInstance(i))&&this.closePanel()}))}_openPanel(){this._dialogService.open({id:ce,draggable:!0,width:le,title:{title:this._localeService.t("find-replace.dialog.title")},children:{label:"FindReplaceDialog"},destroyOnClose:!0,defaultPosition:Ye(),preservePositionOnDestroy:!0,onClose:()=>this.closePanel()})}closePanel(){this._dialogService.close(ce),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus())}},h.FindReplaceController=He([o.OnLifecycle(o.LifecycleStages.Rendered,h.FindReplaceController),I(1,o.IUniverInstanceService),I(2,f.IMenuService),I(3,f.IShortcutService),I(4,o.ICommandService),I(5,b),I(6,f.IDialogService),I(7,f.ILayoutService),I(8,S.Inject(o.LocaleService)),I(9,S.Inject(f.ComponentManager)),I(10,S.Inject(S.Injector))],h.FindReplaceController);function Ye(){const{innerWidth:n}=window;return{x:(n-le)/2-$e,y:ze}}var Ze=Object.defineProperty,Je=Object.getOwnPropertyDescriptor,Qe=(n,e,i,t)=>{for(var s=t>1?void 0:t?Je(e,i):e,a=n.length-1,r;a>=0;a--)(r=n[a])&&(s=(t?r(e,i,s):r(s))||s);return t&&s&&Ze(e,i,s),s},de=(n,e)=>(i,t)=>e(i,t,n);const Xe="FIND_REPLACE_PLUGIN";h.UniverFindReplacePlugin=(H=class extends o.Plugin{constructor(e={},i,t){super(),this._config=e,this._injector=i,this._localeService=t,this._config=o.Tools.deepMerge({},Ke,this._config)}onStarting(e){[[h.FindReplaceController,{useFactory:()=>this._injector.createInstance(h.FindReplaceController,this._config)}],[b,{useClass:W}]].forEach(i=>{e.add(i)})}},d(H,"pluginName",Xe),H),h.UniverFindReplacePlugin=Qe([de(1,S.Inject(S.Injector)),de(2,S.Inject(o.LocaleService))],h.UniverFindReplacePlugin),h.FindBy=O,h.FindDirection=T,h.FindModel=Se,h.FindScope=P,h.IFindReplaceService=b,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|
|
9
|
+
*/var ye=l,be=Symbol.for("react.element"),Me=Symbol.for("react.fragment"),Ie=Object.prototype.hasOwnProperty,Fe=ye.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,xe={key:!0,ref:!0,__self:!0,__source:!0};function ne(n,e,i){var t,s={},a=null,r=null;i!==void 0&&(a=""+i),e.key!==void 0&&(a=""+e.key),e.ref!==void 0&&(r=e.ref);for(t in e)Ie.call(e,t)&&!xe.hasOwnProperty(t)&&(s[t]=e[t]);if(n&&n.defaultProps)for(t in e=n.defaultProps,e)s[t]===void 0&&(s[t]=e[t]);return{$$typeof:be,type:n,key:a,ref:r,props:s,_owner:Fe.current}}E.Fragment=Me,E.jsx=ne,E.jsxs=ne,te.exports=E;var u=te.exports;const ie={id:"ui.command.replace-current-match",type:o.CommandType.COMMAND,handler:n=>n.get(b).replace()},De="CONFIRM_REPLACE_ALL",se={id:"ui.command.replace-all-matches",type:o.CommandType.COMMAND,handler:async n=>{const e=n.get(f.IConfirmService),i=n.get(o.LocaleService),t=n.get(f.IMessageService);if(!await e.confirm({id:De,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:r,failure:c}=a;return c>0?(r===0?t.show({type:p.MessageType.Error,content:i.t("find-replace.replace.all-failure")}):t.show({type:p.MessageType.Warning,content:i.t("find-replace.replace.partial-success",`${r}`,`${c}`)}),!1):(t.show({type:p.MessageType.Success,content:i.t("find-replace.replace.all-success",`${r}`)}),!0)}};function ae(n){const{findCompleted:e,localeService:i,matchesCount:t,matchesPosition:s,findString:a,findReplaceService:r,onChange:c,..._}=n,R=e&&t===0?i.t("find-replace.dialog.no-result"):t===0?" ":void 0;return u.jsx(p.InputWithSlot,{autoFocus:!0,placeholder:i.t("find-replace.dialog.find-placeholder"),slot:u.jsx(p.Pager,{loop:!0,text:R,value:s,total:t,onChange:v=>{s===t&&v===1?r.moveToNextMatch():s===1&&v===t||v<s?r.moveToPreviousMatch():r.moveToNextMatch()}}),value:a,onChange:v=>c==null?void 0:c(v),..._})}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 re(n,e){const i=l.useCallback(()=>{var s;(s=document.querySelector(".univer-find-input input"))==null||s.focus()},[]),t=l.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 l.useImperativeHandle(e,()=>({focus:i,selectHasFocus:t})),l.useEffect(()=>{const s=n.focusSignal$.subscribe(()=>i());return()=>s.unsubscribe()},[n,i]),{focus:i,selectHasFocus:t}}const Te=l.forwardRef(function(e,i){const t=M.useDependency(o.LocaleService),s=M.useDependency(b),a=M.useDependency(o.ICommandService),r=f.useObservable(s.state$,void 0,!0),{findCompleted:c,findString:_,matchesCount:m,matchesPosition:R}=r,v=l.useCallback(()=>{a.executeCommand(k.id)},[a]),L=l.useCallback(F=>s.changeFindString(F),[s]);return re(s,i),u.jsxs(l.Fragment,{children:[u.jsx(ae,{findCompleted:c,className:"univer-find-input",matchesCount:m,matchesPosition:R,findReplaceService:s,localeService:t,findString:_,onChange:L}),u.jsx("div",{className:N.findReplaceExpandContainer,children:u.jsx(p.Button,{type:"text",size:"small",onClick:v,children:t.t("find-replace.dialog.advanced-finding")})})]})}),Oe=l.forwardRef(function(e,i){const t=M.useDependency(b),s=M.useDependency(o.LocaleService),a=M.useDependency(o.ICommandService),r=M.useDependency(f.IMessageService),c=f.useObservable(t.currentMatch$,void 0,!0),_=f.useObservable(t.replaceables$,void 0,!0),m=f.useObservable(t.state$,void 0,!0),{matchesCount:R,matchesPosition:v,findString:L,inputtingFindString:F,replaceString:qe,caseSensitive:et,matchesTheWholeCell:tt,findDirection:nt,findScope:it,findBy:st,findCompleted:K}=m,at=F.length===0,rt=R===0||!(c!=null&&c.replaceable),ot=_.length===0,ct=l.useCallback(g=>t.changeInputtingFindString(g),[t]),lt=l.useCallback(g=>t.changeReplaceString(g),[t]),{focus:dt}=re(t,i),ht=l.useCallback(()=>{L===F?t.moveToNextMatch():(t.changeFindString(F),t.find())},[L,F,t]),ut=l.useCallback(()=>a.executeCommand(ie.id),[a]),ft=l.useCallback(async()=>{await a.executeCommand(se.id),dt()},[a]),pt=l.useCallback(g=>{t.changeFindDirection(g)},[t]),_t=l.useCallback(g=>{t.changeFindScope(g)},[t]),gt=l.useCallback(g=>{t.changeFindBy(g)},[t]),mt=Ee(s),vt=Ne(s),St=je(s);return l.useEffect(()=>{const g=K&&R===0;let A=null;return g&&(A=r.show({content:s.t("find-replace.dialog.no-match"),type:p.MessageType.Warning,duration:5e3})),()=>A==null?void 0:A.dispose()},[K,R,r,s]),u.jsxs(l.Fragment,{children:[u.jsx(p.FormLayout,{label:s.t("find-replace.dialog.find"),children:u.jsx(ae,{findCompleted:K,className:"univer-find-input",matchesCount:R,matchesPosition:v,findReplaceService:t,localeService:s,findString:F,onChange:ct})}),u.jsx(p.FormLayout,{label:s.t("find-replace.dialog.replace"),children:u.jsx(p.Input,{placeholder:s.t("find-replace.dialog.replace-placeholder"),value:qe,onChange:g=>lt(g)})}),u.jsx(p.FormLayout,{label:s.t("find-replace.dialog.find-direction.title"),children:u.jsx(p.Select,{value:nt,options:vt,onChange:pt})}),u.jsx(p.FormDualColumnLayout,{children:u.jsxs(l.Fragment,{children:[u.jsx(p.FormLayout,{label:s.t("find-replace.dialog.find-scope.title"),children:u.jsx(p.Select,{value:it,options:mt,onChange:_t})}),u.jsx(p.FormLayout,{label:s.t("find-replace.dialog.find-by.title"),children:u.jsx(p.Select,{value:st,options:St,onChange:gt})})]})}),u.jsx(p.FormDualColumnLayout,{children:u.jsxs(l.Fragment,{children:[u.jsx(p.FormLayout,{children:u.jsx(p.Checkbox,{checked:et,onChange:g=>{t.changeCaseSensitive(g)},children:s.t("find-replace.dialog.case-sensitive")})}),u.jsx(p.FormLayout,{children:u.jsx(p.Checkbox,{checked:tt,onChange:g=>{t.changeMatchesTheWholeCell(g)},children:s.t("find-replace.dialog.match-the-whole-cell")})})]})}),u.jsxs("div",{className:N.findReplaceButtonsGroup,children:[u.jsx(p.Button,{type:"primary",onClick:ht,disabled:at,children:s.t("find-replace.dialog.find")}),u.jsxs("span",{className:N.findReplaceButtonsGroupRight,children:[u.jsx(p.Button,{disabled:rt,onClick:ut,children:s.t("find-replace.dialog.replace")}),u.jsx(p.Button,{disabled:ot,onClick:ft,children:s.t("find-replace.dialog.replace-all")})]})]})]})});function Pe(){const n=M.useDependency(b),e=M.useDependency(f.ILayoutService),i=M.useDependency(o.IContextService),t=f.useObservable(n.state$,void 0,!0),s=l.useRef(null);l.useEffect(()=>{let _;return s.current&&(_=e.registerContainerElement(s.current)),()=>_==null?void 0:_.dispose()},[e]);const a=l.useRef(null),r=l.useCallback(_=>i.setContextValue(J,_),[i]),c=l.useCallback(_=>i.setContextValue(Z,_),[i]);return l.useEffect(()=>{var m;const _=C.fromEvent(document,"focusin").subscribe(R=>{var v;R.target&&((v=s.current)!=null&&v.contains(R.target))?r(!0):r(!1),!a.current||!a.current.selectHasFocus()?c(!0):c(!1)});return(m=a.current)==null||m.focus(),r(!0),c(!0),()=>{_.unsubscribe(),r(!1)}},[r,c]),u.jsx("div",{className:N.findReplaceDialogContainer,ref:s,children:t.replaceRevealed?u.jsx(Oe,{ref:a}):u.jsx(Te,{ref:a})})}function Ee(n){const e=n.getCurrentLocale();return l.useMemo(()=>[{label:n.t("find-replace.dialog.find-scope.current-sheet"),value:O.SUBUNIT},{label:n.t("find-replace.dialog.find-scope.workbook"),value:O.UNIT}],[e])}function Ne(n){const e=n.getCurrentLocale();return l.useMemo(()=>[{label:n.t("find-replace.dialog.find-direction.row"),value:D.ROW},{label:n.t("find-replace.dialog.find-direction.column"),value:D.COLUMN}],[e])}function je(n){const e=n.getCurrentLocale();return l.useMemo(()=>[{label:n.t("find-replace.dialog.find-by.value"),value:T.VALUE},{label:n.t("find-replace.dialog.find-by.formula"),value:T.FORMULA}],[e])}function x(n){return n.getContextValue(J)}function Le(n){return n.getContextValue(Q)}function oe(n){return n.getContextValue(Z)}const j="7_find-replace-shortcuts";function G(n){return n.getContextValue(o.FOCUSING_SHEET)}function V(n){return!n.getContextValue(o.EDITOR_ACTIVATED)}const Ae={id:P.id,description:"find-replace.shortcut.open-find-dialog",binding:f.KeyCode.F|f.MetaKeys.CTRL_COMMAND,group:j,preconditions(n){return!x(n)&&G(n)&&V(n)}},we={id:P.id,description:"find-replace.shortcut.open-find-dialog",binding:f.KeyCode.F|f.MetaKeys.CTRL_COMMAND,mac:f.KeyCode.F|f.MetaKeys.MAC_CTRL,preconditions(n){return!x(n)&&G(n)&&V(n)}},Ue={id:k.id,description:"find-replace.shortcut.open-replace-dialog",binding:f.KeyCode.H|f.MetaKeys.CTRL_COMMAND,mac:f.KeyCode.H|f.MetaKeys.MAC_CTRL,group:j,preconditions(n){return G(n)&&V(n)&&(!x(n)||!Le(n))}},Be={id:q.id,description:"find-replace.shortcut.go-to-next-match",binding:f.KeyCode.ENTER,group:j,priority:1e3,preconditions(n){return oe(n)&&x(n)}},We={id:ee.id,description:"find-replace.shortcut.go-to-previous-match",binding:f.KeyCode.ENTER|f.MetaKeys.SHIFT,group:j,priority:1e3,preconditions(n){return oe(n)&&x(n)}};function ke(n){const e=n.get(o.IContextService);return{id:P.id,icon:"SearchIcon",tooltip:"find-replace.toolbar",group:f.MenuGroup.TOOLBAR_OTHERS,type:f.MenuItemType.BUTTON,positions:[f.MenuPosition.TOOLBAR_START],hidden$:f.getMenuHiddenObservable(n,o.UniverInstanceType.UNIVER_SHEET),disabled$:C.combineLatest([e.subscribeContextValue$(o.EDITOR_ACTIVATED),e.subscribeContextValue$(o.FOCUSING_SHEET)]).pipe(C.map(([i,t])=>i||!t))}}var Ge=Object.defineProperty,Ve=Object.getOwnPropertyDescriptor,He=(n,e,i,t)=>{for(var s=t>1?void 0:t?Ve(e,i):e,a=n.length-1,r;a>=0;a--)(r=n[a])&&(s=(t?r(e,i,s):r(s))||s);return t&&s&&Ge(e,i,s),s},I=(n,e)=>(i,t)=>e(i,t,n);const Ke={},ce="DESKTOP_FIND_REPLACE_DIALOG",le=350,$e=20,ze=-90;h.FindReplaceController=class extends o.RxDisposable{constructor(e,i,t,s,a,r,c,_,m,R,v){super(),this._config=e,this._univerInstanceService=i,this._menuService=t,this._shortcutService=s,this._commandService=a,this._findReplaceService=r,this._dialogService=c,this._layoutService=_,this._localeService=m,this._componentManager=R,this._injector=v,this._initCommands(),this._initUI(),this._initShortcuts()}_initCommands(){[P,k,q,ee,se,ie].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initShortcuts(){[Ue,Ae,we,We,Be].forEach(e=>this.disposeWithMe(this._shortcutService.registerShortcut(e)))}_initUI(){const{menu:e={}}=this._config;this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(ke),e)),this.disposeWithMe(this._componentManager.register("FindReplaceDialog",Pe)),this.disposeWithMe(this._componentManager.register("SearchIcon",Y)),this._findReplaceService.stateUpdates$.pipe(C.takeUntil(this.dispose$)).subscribe(i=>{i.revealed===!0&&this._openPanel()}),this.disposeWithMe(this._univerInstanceService.focused$.pipe(C.takeUntil(this.dispose$)).subscribe(i=>{(!i||!this._univerInstanceService.getUniverSheetInstance(i))&&this.closePanel()}))}_openPanel(){this._dialogService.open({id:ce,draggable:!0,width:le,title:{title:this._localeService.t("find-replace.dialog.title")},children:{label:"FindReplaceDialog"},destroyOnClose:!0,defaultPosition:Ye(),preservePositionOnDestroy:!0,onClose:()=>this.closePanel()})}closePanel(){this._dialogService.close(ce),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus())}},h.FindReplaceController=He([o.OnLifecycle(o.LifecycleStages.Rendered,h.FindReplaceController),I(1,o.IUniverInstanceService),I(2,f.IMenuService),I(3,f.IShortcutService),I(4,o.ICommandService),I(5,b),I(6,f.IDialogService),I(7,f.ILayoutService),I(8,S.Inject(o.LocaleService)),I(9,S.Inject(f.ComponentManager)),I(10,S.Inject(S.Injector))],h.FindReplaceController);function Ye(){const{innerWidth:n}=window;return{x:(n-le)/2-$e,y:ze}}var Ze=Object.defineProperty,Je=Object.getOwnPropertyDescriptor,Qe=(n,e,i,t)=>{for(var s=t>1?void 0:t?Je(e,i):e,a=n.length-1,r;a>=0;a--)(r=n[a])&&(s=(t?r(e,i,s):r(s))||s);return t&&s&&Ze(e,i,s),s},de=(n,e)=>(i,t)=>e(i,t,n);const Xe="FIND_REPLACE_PLUGIN";h.UniverFindReplacePlugin=(H=class extends o.Plugin{constructor(e={},i,t){super(),this._config=e,this._injector=i,this._localeService=t,this._config=o.Tools.deepMerge({},Ke,this._config)}onStarting(e){[[h.FindReplaceController,{useFactory:()=>this._injector.createInstance(h.FindReplaceController,this._config)}],[b,{useClass:W}]].forEach(i=>{e.add(i)})}},d(H,"pluginName",Xe),H),h.UniverFindReplacePlugin=Qe([de(1,S.Inject(S.Injector)),de(2,S.Inject(o.LocaleService))],h.UniverFindReplacePlugin),h.FindBy=T,h.FindDirection=D,h.FindModel=Se,h.FindScope=O,h.IFindReplaceService=b,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/find-replace",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.17",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -53,10 +53,10 @@
|
|
|
53
53
|
"@wendellhu/redi": "0.15.4",
|
|
54
54
|
"react": "^16.9.0 || ^17.0.0 || ^18.0.0",
|
|
55
55
|
"rxjs": ">=7.0.0",
|
|
56
|
-
"@univerjs/core": "0.1.
|
|
57
|
-
"@univerjs/design": "0.1.
|
|
58
|
-
"@univerjs/engine-render": "0.1.
|
|
59
|
-
"@univerjs/ui": "0.1.
|
|
56
|
+
"@univerjs/core": "0.1.17",
|
|
57
|
+
"@univerjs/design": "0.1.17",
|
|
58
|
+
"@univerjs/engine-render": "0.1.17",
|
|
59
|
+
"@univerjs/ui": "0.1.17"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
62
|
"@univerjs/icons": "^0.1.57"
|
|
@@ -70,12 +70,12 @@
|
|
|
70
70
|
"typescript": "^5.4.5",
|
|
71
71
|
"vite": "^5.3.1",
|
|
72
72
|
"vitest": "^1.6.0",
|
|
73
|
-
"@univerjs/core": "0.1.
|
|
74
|
-
"@univerjs/engine-formula": "0.1.
|
|
75
|
-
"@univerjs/design": "0.1.
|
|
76
|
-
"@univerjs/shared": "0.1.
|
|
77
|
-
"@univerjs/ui": "0.1.
|
|
78
|
-
"@univerjs/engine-render": "0.1.
|
|
73
|
+
"@univerjs/core": "0.1.17",
|
|
74
|
+
"@univerjs/engine-formula": "0.1.17",
|
|
75
|
+
"@univerjs/design": "0.1.17",
|
|
76
|
+
"@univerjs/shared": "0.1.17",
|
|
77
|
+
"@univerjs/ui": "0.1.17",
|
|
78
|
+
"@univerjs/engine-render": "0.1.17"
|
|
79
79
|
},
|
|
80
80
|
"univerSpace": {
|
|
81
81
|
".": {
|