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