@univerjs/find-replace 0.2.6 → 0.2.7

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 CHANGED
@@ -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 f=require$$0,k=Symbol.for("react.element"),l=Symbol.for("react.fragment"),m=Object.prototype.hasOwnProperty,n=f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,p={key:!0,ref:!0,__self:!0,__source:!0};function q(c,a,g){var b,d={},e=null,h=null;g!==void 0&&(e=""+g),a.key!==void 0&&(e=""+a.key),a.ref!==void 0&&(h=a.ref);for(b in a)m.call(a,b)&&!p.hasOwnProperty(b)&&(d[b]=a[b]);if(c&&c.defaultProps)for(b in a=c.defaultProps,a)d[b]===void 0&&(d[b]=a[b]);return{$$typeof:k,type:c,key:e,ref:h,props:d,_owner:n.current}}__name(q,"q");reactJsxRuntime_production_min.Fragment=l;reactJsxRuntime_production_min.jsx=q;reactJsxRuntime_production_min.jsxs=q;jsxRuntime.exports=reactJsxRuntime_production_min;var jsxRuntimeExports=jsxRuntime.exports;const ReplaceCurrentMatchCommand={id:"ui.command.replace-current-match",type:core.CommandType.COMMAND,handler:__name(accessor=>accessor.get(IFindReplaceService).replace(),"handler")},CONFIRM_REPLACE_ALL_ID="CONFIRM_REPLACE_ALL",ReplaceAllMatchesCommand={id:"ui.command.replace-all-matches",type:core.CommandType.COMMAND,handler:__name(async accessor=>{const confirmService=accessor.get(ui.IConfirmService),localeService=accessor.get(core.LocaleService),messageService=accessor.get(ui.IMessageService);if(!await confirmService.confirm({id:CONFIRM_REPLACE_ALL_ID,title:{title:localeService.t("find-replace.replace.confirm.title")},cancelText:localeService.t("button.cancel"),confirmText:localeService.t("button.confirm")}))return!1;const result=await accessor.get(IFindReplaceService).replaceAll(),{success,failure}=result;return failure>0?(success===0?messageService.show({type:design.MessageType.Error,content:localeService.t("find-replace.replace.all-failure")}):messageService.show({type:design.MessageType.Warning,content:localeService.t("find-replace.replace.partial-success",`${success}`,`${failure}`)}),!1):(messageService.show({type:design.MessageType.Success,content:localeService.t("find-replace.replace.all-success",`${success}`)}),!0)},"handler")};function SearchInput(props){const{findCompleted:findComplete,localeService,matchesCount,matchesPosition,findString,findReplaceService,onChange,...rest}=props,text=findComplete&&matchesCount===0?localeService.t("find-replace.dialog.no-result"):matchesCount===0?" ":void 0;return jsxRuntimeExports.jsx(design.InputWithSlot,{autoFocus:!0,placeholder:localeService.t("find-replace.dialog.find-placeholder"),slot:jsxRuntimeExports.jsx(design.Pager,{loop:!0,text,value:matchesPosition,total:matchesCount,onChange:__name(newIndex=>{matchesPosition===matchesCount&&newIndex===1?findReplaceService.moveToNextMatch():matchesPosition===1&&newIndex===matchesCount||newIndex<matchesPosition?findReplaceService.moveToPreviousMatch():findReplaceService.moveToNextMatch()},"onChange")}),value:findString,onChange:__name(value=>onChange==null?void 0:onChange(value),"onChange"),...rest})}__name(SearchInput,"SearchInput");const 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",styles={findReplaceDialogContainer,findReplaceExpandContainer,buttonText,findReplaceButtonsGroup,findReplaceButtonsGroupRight};function useFindInputFocus(findReplaceService,ref){const focus=require$$0.useCallback(()=>{var _a5;(_a5=document.querySelector(".univer-find-input input"))==null||_a5.focus()},[]),selectHasFocus=require$$0.useCallback(()=>{const allInputs=document.querySelectorAll(".univer-find-replace-dialog-container .univer-select-selection-search-input");return Array.from(allInputs).some(input=>input===document.activeElement)},[]);return require$$0.useImperativeHandle(ref,()=>({focus,selectHasFocus})),require$$0.useEffect(()=>{const subscription=findReplaceService.focusSignal$.subscribe(()=>focus());return()=>subscription.unsubscribe()},[findReplaceService,focus]),{focus,selectHasFocus}}__name(useFindInputFocus,"useFindInputFocus");const FindDialog=require$$0.forwardRef(__name(function(_props,ref){const localeService=core.useDependency(core.LocaleService),findReplaceService=core.useDependency(IFindReplaceService),commandService=core.useDependency(core.ICommandService),state=ui.useObservable(findReplaceService.state$,void 0,!0),{findCompleted,findString,matchesCount,matchesPosition}=state,revealReplace=require$$0.useCallback(()=>{commandService.executeCommand(OpenReplaceDialogOperation.id)},[commandService]),onFindStringChange=require$$0.useCallback(findString2=>findReplaceService.changeFindString(findString2),[findReplaceService]);return useFindInputFocus(findReplaceService,ref),jsxRuntimeExports.jsxs(require$$0.Fragment,{children:[jsxRuntimeExports.jsx(SearchInput,{findCompleted,className:"univer-find-input",matchesCount,matchesPosition,findReplaceService,localeService,findString,onChange:onFindStringChange}),jsxRuntimeExports.jsx("div",{className:styles.findReplaceExpandContainer,children:jsxRuntimeExports.jsx(design.Button,{type:"text",size:"small",onClick:revealReplace,children:localeService.t("find-replace.dialog.advanced-finding")})})]})},"FindDialogImpl")),ReplaceDialog=require$$0.forwardRef(__name(function(_props,ref){const findReplaceService=core.useDependency(IFindReplaceService),localeService=core.useDependency(core.LocaleService),commandService=core.useDependency(core.ICommandService),messageService=core.useDependency(ui.IMessageService),currentMatch=ui.useObservable(findReplaceService.currentMatch$,void 0,!0),replaceables=ui.useObservable(findReplaceService.replaceables$,void 0,!0),state=ui.useObservable(findReplaceService.state$,void 0,!0),{matchesCount,matchesPosition,findString,inputtingFindString,replaceString,caseSensitive,matchesTheWholeCell,findDirection,findScope,findBy,findCompleted}=state,findDisabled=inputtingFindString.length===0,replaceDisabled=matchesCount===0||!(currentMatch!=null&&currentMatch.replaceable),replaceAllDisabled=replaceables.length===0,onFindStringChange=require$$0.useCallback(newValue=>findReplaceService.changeInputtingFindString(newValue),[findReplaceService]),onReplaceStringChange=require$$0.useCallback(replaceString2=>findReplaceService.changeReplaceString(replaceString2),[findReplaceService]),{focus}=useFindInputFocus(findReplaceService,ref),onClickFindButton=require$$0.useCallback(()=>{findString===inputtingFindString?findReplaceService.moveToNextMatch():(findReplaceService.changeFindString(inputtingFindString),findReplaceService.find())},[findString,inputtingFindString,findReplaceService]),onClickReplaceButton=require$$0.useCallback(()=>commandService.executeCommand(ReplaceCurrentMatchCommand.id),[commandService]),onClickReplaceAllButton=require$$0.useCallback(async()=>{await commandService.executeCommand(ReplaceAllMatchesCommand.id),focus()},[commandService]),onChangeFindDirection=require$$0.useCallback(findDirection2=>{findReplaceService.changeFindDirection(findDirection2)},[findReplaceService]),onChangeFindScope=require$$0.useCallback(findScope2=>{findReplaceService.changeFindScope(findScope2)},[findReplaceService]),onChangeFindBy=require$$0.useCallback(findBy2=>{findReplaceService.changeFindBy(findBy2)},[findReplaceService]),findScopeOptions=useFindScopeOptions(localeService),findDirectionOptions=useFindDirectionOptions(localeService),findByOptions=useFindByOptions(localeService);return require$$0.useEffect(()=>{const shouldDisplayNoMatchInfo=findCompleted&&matchesCount===0;let messageDisposable=null;return shouldDisplayNoMatchInfo&&(messageDisposable=messageService.show({content:localeService.t("find-replace.dialog.no-match"),type:design.MessageType.Warning,duration:5e3})),()=>messageDisposable==null?void 0:messageDisposable.dispose()},[findCompleted,matchesCount,messageService,localeService]),jsxRuntimeExports.jsxs(require$$0.Fragment,{children:[jsxRuntimeExports.jsx(design.FormLayout,{label:localeService.t("find-replace.dialog.find"),children:jsxRuntimeExports.jsx(SearchInput,{findCompleted,className:"univer-find-input",matchesCount,matchesPosition,findReplaceService,localeService,findString:inputtingFindString,onChange:onFindStringChange})}),jsxRuntimeExports.jsx(design.FormLayout,{label:localeService.t("find-replace.dialog.replace"),children:jsxRuntimeExports.jsx(design.Input,{placeholder:localeService.t("find-replace.dialog.replace-placeholder"),value:replaceString,onChange:__name(value=>onReplaceStringChange(value),"onChange")})}),jsxRuntimeExports.jsx(design.FormLayout,{label:localeService.t("find-replace.dialog.find-direction.title"),children:jsxRuntimeExports.jsx(design.Select,{value:findDirection,options:findDirectionOptions,onChange:onChangeFindDirection})}),jsxRuntimeExports.jsx(design.FormDualColumnLayout,{children:jsxRuntimeExports.jsxs(require$$0.Fragment,{children:[jsxRuntimeExports.jsx(design.FormLayout,{label:localeService.t("find-replace.dialog.find-scope.title"),children:jsxRuntimeExports.jsx(design.Select,{value:findScope,options:findScopeOptions,onChange:onChangeFindScope})}),jsxRuntimeExports.jsx(design.FormLayout,{label:localeService.t("find-replace.dialog.find-by.title"),children:jsxRuntimeExports.jsx(design.Select,{value:findBy,options:findByOptions,onChange:onChangeFindBy})})]})}),jsxRuntimeExports.jsx(design.FormDualColumnLayout,{children:jsxRuntimeExports.jsxs(require$$0.Fragment,{children:[jsxRuntimeExports.jsx(design.FormLayout,{children:jsxRuntimeExports.jsx(design.Checkbox,{checked:caseSensitive,onChange:__name(checked=>{findReplaceService.changeCaseSensitive(checked)},"onChange"),children:localeService.t("find-replace.dialog.case-sensitive")})}),jsxRuntimeExports.jsx(design.FormLayout,{children:jsxRuntimeExports.jsx(design.Checkbox,{checked:matchesTheWholeCell,onChange:__name(checked=>{findReplaceService.changeMatchesTheWholeCell(checked)},"onChange"),children:localeService.t("find-replace.dialog.match-the-whole-cell")})})]})}),jsxRuntimeExports.jsxs("div",{className:styles.findReplaceButtonsGroup,children:[jsxRuntimeExports.jsx(design.Button,{type:"primary",onClick:onClickFindButton,disabled:findDisabled,children:localeService.t("find-replace.dialog.find")}),jsxRuntimeExports.jsxs("span",{className:styles.findReplaceButtonsGroupRight,children:[jsxRuntimeExports.jsx(design.Button,{disabled:replaceDisabled,onClick:onClickReplaceButton,children:localeService.t("find-replace.dialog.replace")}),jsxRuntimeExports.jsx(design.Button,{disabled:replaceAllDisabled,onClick:onClickReplaceAllButton,children:localeService.t("find-replace.dialog.replace-all")})]})]})]})},"ReplaceDIalogImpl"));function FindReplaceDialog(){const findReplaceService=core.useDependency(IFindReplaceService),layoutService=core.useDependency(ui.ILayoutService),contextService=core.useDependency(core.IContextService),state=ui.useObservable(findReplaceService.state$,void 0,!0),dialogContainerRef=require$$0.useRef(null);require$$0.useEffect(()=>{let disposable;return dialogContainerRef.current&&(disposable=layoutService.registerContainerElement(dialogContainerRef.current)),()=>disposable==null?void 0:disposable.dispose()},[layoutService]);const focusRef=require$$0.useRef(null),setDialogContainerFocus=require$$0.useCallback(focused=>contextService.setContextValue(FIND_REPLACE_DIALOG_FOCUS,focused),[contextService]),setDialogInputFocus=require$$0.useCallback(focused=>contextService.setContextValue(FIND_REPLACE_INPUT_FOCUS,focused),[contextService]);return require$$0.useEffect(()=>{var _a5;const focusSubscription=rxjs.fromEvent(document,"focusin").subscribe(event=>{var _a6;event.target&&((_a6=dialogContainerRef.current)!=null&&_a6.contains(event.target))?setDialogContainerFocus(!0):setDialogContainerFocus(!1),!focusRef.current||!focusRef.current.selectHasFocus()?setDialogInputFocus(!0):setDialogInputFocus(!1)});return(_a5=focusRef.current)==null||_a5.focus(),setDialogContainerFocus(!0),setDialogInputFocus(!0),()=>{focusSubscription.unsubscribe(),setDialogContainerFocus(!1)}},[setDialogContainerFocus,setDialogInputFocus]),jsxRuntimeExports.jsx("div",{className:styles.findReplaceDialogContainer,ref:dialogContainerRef,children:state.replaceRevealed?jsxRuntimeExports.jsx(ReplaceDialog,{ref:focusRef}):jsxRuntimeExports.jsx(FindDialog,{ref:focusRef})})}__name(FindReplaceDialog,"FindReplaceDialog");function useFindScopeOptions(localeService){const locale=localeService.getCurrentLocale();return require$$0.useMemo(()=>[{label:localeService.t("find-replace.dialog.find-scope.current-sheet"),value:FindScope.SUBUNIT},{label:localeService.t("find-replace.dialog.find-scope.workbook"),value:FindScope.UNIT}],[locale])}__name(useFindScopeOptions,"useFindScopeOptions");function useFindDirectionOptions(localeService){const locale=localeService.getCurrentLocale();return require$$0.useMemo(()=>[{label:localeService.t("find-replace.dialog.find-direction.row"),value:FindDirection.ROW},{label:localeService.t("find-replace.dialog.find-direction.column"),value:FindDirection.COLUMN}],[locale])}__name(useFindDirectionOptions,"useFindDirectionOptions");function useFindByOptions(localeService){const locale=localeService.getCurrentLocale();return require$$0.useMemo(()=>[{label:localeService.t("find-replace.dialog.find-by.value"),value:FindBy.VALUE},{label:localeService.t("find-replace.dialog.find-by.formula"),value:FindBy.FORMULA}],[locale])}__name(useFindByOptions,"useFindByOptions");function whenFindReplaceDialogFocused(contextService){return contextService.getContextValue(FIND_REPLACE_DIALOG_FOCUS)}__name(whenFindReplaceDialogFocused,"whenFindReplaceDialogFocused");function whenReplaceRevealed(contextService){return contextService.getContextValue(FIND_REPLACE_REPLACE_REVEALED)}__name(whenReplaceRevealed,"whenReplaceRevealed");function whenFindReplaceInputFocused(contextService){return contextService.getContextValue(FIND_REPLACE_INPUT_FOCUS)}__name(whenFindReplaceInputFocused,"whenFindReplaceInputFocused");const FIND_REPLACE_SHORTCUT_GROUP="7_find-replace-shortcuts";function whenSheetFocused(contextService){return contextService.getContextValue(core.FOCUSING_SHEET)}__name(whenSheetFocused,"whenSheetFocused");function whenEditorNotActivated(contextService){return!contextService.getContextValue(core.EDITOR_ACTIVATED)}__name(whenEditorNotActivated,"whenEditorNotActivated");const OpenFindDialogShortcutItem={id:OpenFindDialogOperation.id,description:"find-replace.shortcut.open-find-dialog",binding:ui.KeyCode.F|ui.MetaKeys.CTRL_COMMAND,group:FIND_REPLACE_SHORTCUT_GROUP,preconditions(contextService){return!whenFindReplaceDialogFocused(contextService)&&whenSheetFocused(contextService)&&whenEditorNotActivated(contextService)}},MacOpenFindDialogShortcutItem={id:OpenFindDialogOperation.id,description:"find-replace.shortcut.open-find-dialog",binding:ui.KeyCode.F|ui.MetaKeys.CTRL_COMMAND,mac:ui.KeyCode.F|ui.MetaKeys.MAC_CTRL,preconditions(contextService){return!whenFindReplaceDialogFocused(contextService)&&whenSheetFocused(contextService)&&whenEditorNotActivated(contextService)}},OpenReplaceDialogShortcutItem={id:OpenReplaceDialogOperation.id,description:"find-replace.shortcut.open-replace-dialog",binding:ui.KeyCode.H|ui.MetaKeys.CTRL_COMMAND,mac:ui.KeyCode.H|ui.MetaKeys.MAC_CTRL,group:FIND_REPLACE_SHORTCUT_GROUP,preconditions(contextService){return whenSheetFocused(contextService)&&whenEditorNotActivated(contextService)&&(!whenFindReplaceDialogFocused(contextService)||!whenReplaceRevealed(contextService))}},GoToNextFindMatchShortcutItem={id:GoToNextMatchOperation.id,description:"find-replace.shortcut.go-to-next-match",binding:ui.KeyCode.ENTER,group:FIND_REPLACE_SHORTCUT_GROUP,priority:1e3,preconditions(contextService){return whenFindReplaceInputFocused(contextService)&&whenFindReplaceDialogFocused(contextService)}},GoToPreviousFindMatchShortcutItem={id:GoToPreviousMatchOperation.id,description:"find-replace.shortcut.go-to-previous-match",binding:ui.KeyCode.ENTER|ui.MetaKeys.SHIFT,group:FIND_REPLACE_SHORTCUT_GROUP,priority:1e3,preconditions(contextService){return whenFindReplaceInputFocused(contextService)&&whenFindReplaceDialogFocused(contextService)}};function FindReplaceMenuItemFactory(accessor){const contextService=accessor.get(core.IContextService);return{id:OpenFindDialogOperation.id,icon:"SearchIcon",tooltip:"find-replace.toolbar",group:ui.MenuGroup.TOOLBAR_OTHERS,type:ui.MenuItemType.BUTTON,positions:[ui.MenuPosition.TOOLBAR_START],hidden$:ui.getMenuHiddenObservable(accessor,core.UniverInstanceType.UNIVER_SHEET),disabled$:rxjs.combineLatest([contextService.subscribeContextValue$(core.EDITOR_ACTIVATED),contextService.subscribeContextValue$(core.FOCUSING_SHEET)]).pipe(rxjs.map(([editorActivated,focusingSheet])=>editorActivated||!focusingSheet))}}__name(FindReplaceMenuItemFactory,"FindReplaceMenuItemFactory");var __defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$1");const DefaultFindReplaceConfig={},FIND_REPLACE_DIALOG_ID="DESKTOP_FIND_REPLACE_DIALOG",FIND_REPLACE_PANEL_WIDTH=350,FIND_REPLACE_PANEL_RIGHT_PADDING=20,FIND_REPLACE_PANEL_TOP_PADDING=-90;var _a3;exports.FindReplaceController=(_a3=class extends core.RxDisposable{constructor(_config,_univerInstanceService,_menuService,_shortcutService,_commandService,_findReplaceService,_dialogService,_layoutService,_localeService,_componentManager,_injector){super(),this._config=_config,this._univerInstanceService=_univerInstanceService,this._menuService=_menuService,this._shortcutService=_shortcutService,this._commandService=_commandService,this._findReplaceService=_findReplaceService,this._dialogService=_dialogService,this._layoutService=_layoutService,this._localeService=_localeService,this._componentManager=_componentManager,this._injector=_injector,this._initCommands(),this._initUI(),this._initShortcuts()}_initCommands(){[OpenFindDialogOperation,OpenReplaceDialogOperation,GoToNextMatchOperation,GoToPreviousMatchOperation,ReplaceAllMatchesCommand,ReplaceCurrentMatchCommand].forEach(c=>{this.disposeWithMe(this._commandService.registerCommand(c))})}_initShortcuts(){[OpenReplaceDialogShortcutItem,OpenFindDialogShortcutItem,MacOpenFindDialogShortcutItem,GoToPreviousFindMatchShortcutItem,GoToNextFindMatchShortcutItem].forEach(s=>this.disposeWithMe(this._shortcutService.registerShortcut(s)))}_initUI(){const{menu={}}=this._config;this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(FindReplaceMenuItemFactory),menu)),this.disposeWithMe(this._componentManager.register("FindReplaceDialog",FindReplaceDialog)),this.disposeWithMe(this._componentManager.register("SearchIcon",SearchSingle16)),this._findReplaceService.stateUpdates$.pipe(rxjs.takeUntil(this.dispose$)).subscribe(newState=>{newState.revealed===!0&&this._openPanel()}),this.disposeWithMe(this._univerInstanceService.focused$.pipe(rxjs.takeUntil(this.dispose$)).subscribe(focused=>{(!focused||!this._univerInstanceService.getUniverSheetInstance(focused))&&this.closePanel()}))}_openPanel(){this._dialogService.open({id:FIND_REPLACE_DIALOG_ID,draggable:!0,width:FIND_REPLACE_PANEL_WIDTH,title:{title:this._localeService.t("find-replace.dialog.title")},children:{label:"FindReplaceDialog"},destroyOnClose:!0,defaultPosition:getFindReplaceDialogDefaultPosition(),preservePositionOnDestroy:!0,onClose:__name(()=>this.closePanel(),"onClose")})}closePanel(){this._dialogService.close(FIND_REPLACE_DIALOG_ID),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus())}},__name(_a3,"FindReplaceController"),_a3);exports.FindReplaceController=__decorateClass$1([core.OnLifecycle(core.LifecycleStages.Rendered,exports.FindReplaceController),__decorateParam$1(1,core.IUniverInstanceService),__decorateParam$1(2,ui.IMenuService),__decorateParam$1(3,ui.IShortcutService),__decorateParam$1(4,core.ICommandService),__decorateParam$1(5,IFindReplaceService),__decorateParam$1(6,ui.IDialogService),__decorateParam$1(7,ui.ILayoutService),__decorateParam$1(8,core.Inject(core.LocaleService)),__decorateParam$1(9,core.Inject(ui.ComponentManager)),__decorateParam$1(10,core.Inject(core.Injector))],exports.FindReplaceController);function getFindReplaceDialogDefaultPosition(){const{innerWidth}=window;return{x:(innerWidth-FIND_REPLACE_PANEL_WIDTH)/2-FIND_REPLACE_PANEL_RIGHT_PADDING,y:FIND_REPLACE_PANEL_TOP_PADDING}}__name(getFindReplaceDialogDefaultPosition,"getFindReplaceDialogDefaultPosition");var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam");const PLUGIN_NAME="FIND_REPLACE_PLUGIN";var _a4;exports.UniverFindReplacePlugin=(_a4=class extends core.Plugin{constructor(_config={},_injector,_localeService){super(),this._config=_config,this._injector=_injector,this._localeService=_localeService,this._config=core.Tools.deepMerge({},DefaultFindReplaceConfig,this._config)}onStarting(){[[exports.FindReplaceController,{useFactory:__name(()=>this._injector.createInstance(exports.FindReplaceController,this._config),"useFactory")}],[IFindReplaceService,{useClass:FindReplaceService}]].forEach(d=>{this._injector.add(d)})}},__name(_a4,"UniverFindReplacePlugin"),__publicField(_a4,"pluginName",PLUGIN_NAME),_a4);exports.UniverFindReplacePlugin=__decorateClass([__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.Inject(core.LocaleService))],exports.UniverFindReplacePlugin);exports.FindBy=FindBy;exports.FindDirection=FindDirection;exports.FindModel=FindModel;exports.FindScope=FindScope;exports.GoToNextMatchOperation=GoToNextMatchOperation;exports.GoToPreviousMatchOperation=GoToPreviousMatchOperation;exports.IFindReplaceService=IFindReplaceService;exports.OpenFindDialogOperation=OpenFindDialogOperation;exports.OpenReplaceDialogOperation=OpenReplaceDialogOperation;exports.ReplaceAllMatchesCommand=ReplaceAllMatchesCommand;exports.ReplaceCurrentMatchCommand=ReplaceCurrentMatchCommand;
9
+ */var f=require$$0,k=Symbol.for("react.element"),l=Symbol.for("react.fragment"),m=Object.prototype.hasOwnProperty,n=f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,p={key:!0,ref:!0,__self:!0,__source:!0};function q(c,a,g){var b,d={},e=null,h=null;g!==void 0&&(e=""+g),a.key!==void 0&&(e=""+a.key),a.ref!==void 0&&(h=a.ref);for(b in a)m.call(a,b)&&!p.hasOwnProperty(b)&&(d[b]=a[b]);if(c&&c.defaultProps)for(b in a=c.defaultProps,a)d[b]===void 0&&(d[b]=a[b]);return{$$typeof:k,type:c,key:e,ref:h,props:d,_owner:n.current}}__name(q,"q");reactJsxRuntime_production_min.Fragment=l;reactJsxRuntime_production_min.jsx=q;reactJsxRuntime_production_min.jsxs=q;jsxRuntime.exports=reactJsxRuntime_production_min;var jsxRuntimeExports=jsxRuntime.exports;const ReplaceCurrentMatchCommand={id:"ui.command.replace-current-match",type:core.CommandType.COMMAND,handler:__name(accessor=>accessor.get(IFindReplaceService).replace(),"handler")},CONFIRM_REPLACE_ALL_ID="CONFIRM_REPLACE_ALL",ReplaceAllMatchesCommand={id:"ui.command.replace-all-matches",type:core.CommandType.COMMAND,handler:__name(async accessor=>{const confirmService=accessor.get(ui.IConfirmService),localeService=accessor.get(core.LocaleService),messageService=accessor.get(ui.IMessageService);if(!await confirmService.confirm({id:CONFIRM_REPLACE_ALL_ID,title:{title:localeService.t("find-replace.replace.confirm.title")},cancelText:localeService.t("button.cancel"),confirmText:localeService.t("button.confirm")}))return!1;const result=await accessor.get(IFindReplaceService).replaceAll(),{success,failure}=result;return failure>0?(success===0?messageService.show({type:design.MessageType.Error,content:localeService.t("find-replace.replace.all-failure")}):messageService.show({type:design.MessageType.Warning,content:localeService.t("find-replace.replace.partial-success",`${success}`,`${failure}`)}),!1):(messageService.show({type:design.MessageType.Success,content:localeService.t("find-replace.replace.all-success",`${success}`)}),!0)},"handler")};function SearchInput(props){const{findCompleted:findComplete,localeService,matchesCount,matchesPosition,findString,findReplaceService,onChange,...rest}=props,text=findComplete&&matchesCount===0?localeService.t("find-replace.dialog.no-result"):matchesCount===0?" ":void 0;return jsxRuntimeExports.jsx(design.InputWithSlot,{autoFocus:!0,placeholder:localeService.t("find-replace.dialog.find-placeholder"),slot:jsxRuntimeExports.jsx(design.Pager,{loop:!0,text,value:matchesPosition,total:matchesCount,onChange:__name(newIndex=>{matchesPosition===matchesCount&&newIndex===1?findReplaceService.moveToNextMatch():matchesPosition===1&&newIndex===matchesCount||newIndex<matchesPosition?findReplaceService.moveToPreviousMatch():findReplaceService.moveToNextMatch()},"onChange")}),value:findString,onChange:__name(value=>onChange==null?void 0:onChange(value),"onChange"),...rest})}__name(SearchInput,"SearchInput");const 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",styles={findReplaceDialogContainer,findReplaceExpandContainer,buttonText,findReplaceButtonsGroup,findReplaceButtonsGroupRight};function useFindInputFocus(findReplaceService,ref){const focus=require$$0.useCallback(()=>{var _a5;(_a5=document.querySelector(".univer-find-input input"))==null||_a5.focus()},[]),selectHasFocus=require$$0.useCallback(()=>{const allInputs=document.querySelectorAll(".univer-find-replace-dialog-container .univer-select-selection-search-input");return Array.from(allInputs).some(input=>input===document.activeElement)},[]);return require$$0.useImperativeHandle(ref,()=>({focus,selectHasFocus})),require$$0.useEffect(()=>{const subscription=findReplaceService.focusSignal$.subscribe(()=>focus());return()=>subscription.unsubscribe()},[findReplaceService,focus]),{focus,selectHasFocus}}__name(useFindInputFocus,"useFindInputFocus");const FindDialog=require$$0.forwardRef(__name(function(_props,ref){const localeService=core.useDependency(core.LocaleService),findReplaceService=core.useDependency(IFindReplaceService),commandService=core.useDependency(core.ICommandService),state=ui.useObservable(findReplaceService.state$,void 0,!0),{findCompleted,findString,matchesCount,matchesPosition}=state,revealReplace=require$$0.useCallback(()=>{commandService.executeCommand(OpenReplaceDialogOperation.id)},[commandService]),onFindStringChange=require$$0.useCallback(findString2=>findReplaceService.changeFindString(findString2),[findReplaceService]);return useFindInputFocus(findReplaceService,ref),jsxRuntimeExports.jsxs(require$$0.Fragment,{children:[jsxRuntimeExports.jsx(SearchInput,{findCompleted,className:"univer-find-input",matchesCount,matchesPosition,findReplaceService,localeService,findString,onChange:onFindStringChange}),jsxRuntimeExports.jsx("div",{className:styles.findReplaceExpandContainer,children:jsxRuntimeExports.jsx(design.Button,{type:"text",size:"small",onClick:revealReplace,children:localeService.t("find-replace.dialog.advanced-finding")})})]})},"FindDialogImpl")),ReplaceDialog=require$$0.forwardRef(__name(function(_props,ref){const findReplaceService=core.useDependency(IFindReplaceService),localeService=core.useDependency(core.LocaleService),commandService=core.useDependency(core.ICommandService),messageService=core.useDependency(ui.IMessageService),currentMatch=ui.useObservable(findReplaceService.currentMatch$,void 0,!0),replaceables=ui.useObservable(findReplaceService.replaceables$,void 0,!0),state=ui.useObservable(findReplaceService.state$,void 0,!0),{matchesCount,matchesPosition,findString,inputtingFindString,replaceString,caseSensitive,matchesTheWholeCell,findDirection,findScope,findBy,findCompleted}=state,findDisabled=inputtingFindString.length===0,replaceDisabled=matchesCount===0||!(currentMatch!=null&&currentMatch.replaceable),replaceAllDisabled=replaceables.length===0,onFindStringChange=require$$0.useCallback(newValue=>findReplaceService.changeInputtingFindString(newValue),[findReplaceService]),onReplaceStringChange=require$$0.useCallback(replaceString2=>findReplaceService.changeReplaceString(replaceString2),[findReplaceService]),{focus}=useFindInputFocus(findReplaceService,ref),onClickFindButton=require$$0.useCallback(()=>{findString===inputtingFindString?findReplaceService.moveToNextMatch():(findReplaceService.changeFindString(inputtingFindString),findReplaceService.find())},[findString,inputtingFindString,findReplaceService]),onClickReplaceButton=require$$0.useCallback(()=>commandService.executeCommand(ReplaceCurrentMatchCommand.id),[commandService]),onClickReplaceAllButton=require$$0.useCallback(async()=>{await commandService.executeCommand(ReplaceAllMatchesCommand.id),focus()},[commandService]),onChangeFindDirection=require$$0.useCallback(findDirection2=>{findReplaceService.changeFindDirection(findDirection2)},[findReplaceService]),onChangeFindScope=require$$0.useCallback(findScope2=>{findReplaceService.changeFindScope(findScope2)},[findReplaceService]),onChangeFindBy=require$$0.useCallback(findBy2=>{findReplaceService.changeFindBy(findBy2)},[findReplaceService]),findScopeOptions=useFindScopeOptions(localeService),findDirectionOptions=useFindDirectionOptions(localeService),findByOptions=useFindByOptions(localeService);return require$$0.useEffect(()=>{const shouldDisplayNoMatchInfo=findCompleted&&matchesCount===0;let messageDisposable=null;return shouldDisplayNoMatchInfo&&(messageDisposable=messageService.show({content:localeService.t("find-replace.dialog.no-match"),type:design.MessageType.Warning,duration:5e3})),()=>messageDisposable==null?void 0:messageDisposable.dispose()},[findCompleted,matchesCount,messageService,localeService]),jsxRuntimeExports.jsxs(require$$0.Fragment,{children:[jsxRuntimeExports.jsx(design.FormLayout,{label:localeService.t("find-replace.dialog.find"),children:jsxRuntimeExports.jsx(SearchInput,{findCompleted,className:"univer-find-input",matchesCount,matchesPosition,findReplaceService,localeService,findString:inputtingFindString,onChange:onFindStringChange})}),jsxRuntimeExports.jsx(design.FormLayout,{label:localeService.t("find-replace.dialog.replace"),children:jsxRuntimeExports.jsx(design.Input,{placeholder:localeService.t("find-replace.dialog.replace-placeholder"),value:replaceString,onChange:__name(value=>onReplaceStringChange(value),"onChange")})}),jsxRuntimeExports.jsx(design.FormLayout,{label:localeService.t("find-replace.dialog.find-direction.title"),children:jsxRuntimeExports.jsx(design.Select,{value:findDirection,options:findDirectionOptions,onChange:onChangeFindDirection})}),jsxRuntimeExports.jsx(design.FormDualColumnLayout,{children:jsxRuntimeExports.jsxs(require$$0.Fragment,{children:[jsxRuntimeExports.jsx(design.FormLayout,{label:localeService.t("find-replace.dialog.find-scope.title"),children:jsxRuntimeExports.jsx(design.Select,{value:findScope,options:findScopeOptions,onChange:onChangeFindScope})}),jsxRuntimeExports.jsx(design.FormLayout,{label:localeService.t("find-replace.dialog.find-by.title"),children:jsxRuntimeExports.jsx(design.Select,{value:findBy,options:findByOptions,onChange:onChangeFindBy})})]})}),jsxRuntimeExports.jsx(design.FormDualColumnLayout,{children:jsxRuntimeExports.jsxs(require$$0.Fragment,{children:[jsxRuntimeExports.jsx(design.FormLayout,{children:jsxRuntimeExports.jsx(design.Checkbox,{checked:caseSensitive,onChange:__name(checked=>{findReplaceService.changeCaseSensitive(checked)},"onChange"),children:localeService.t("find-replace.dialog.case-sensitive")})}),jsxRuntimeExports.jsx(design.FormLayout,{children:jsxRuntimeExports.jsx(design.Checkbox,{checked:matchesTheWholeCell,onChange:__name(checked=>{findReplaceService.changeMatchesTheWholeCell(checked)},"onChange"),children:localeService.t("find-replace.dialog.match-the-whole-cell")})})]})}),jsxRuntimeExports.jsxs("div",{className:styles.findReplaceButtonsGroup,children:[jsxRuntimeExports.jsx(design.Button,{type:"primary",onClick:onClickFindButton,disabled:findDisabled,children:localeService.t("find-replace.dialog.find")}),jsxRuntimeExports.jsxs("span",{className:styles.findReplaceButtonsGroupRight,children:[jsxRuntimeExports.jsx(design.Button,{disabled:replaceDisabled,onClick:onClickReplaceButton,children:localeService.t("find-replace.dialog.replace")}),jsxRuntimeExports.jsx(design.Button,{disabled:replaceAllDisabled,onClick:onClickReplaceAllButton,children:localeService.t("find-replace.dialog.replace-all")})]})]})]})},"ReplaceDIalogImpl"));function FindReplaceDialog(){const findReplaceService=core.useDependency(IFindReplaceService),layoutService=core.useDependency(ui.ILayoutService),contextService=core.useDependency(core.IContextService),state=ui.useObservable(findReplaceService.state$,void 0,!0),dialogContainerRef=require$$0.useRef(null);require$$0.useEffect(()=>{let disposable;return dialogContainerRef.current&&(disposable=layoutService.registerContainerElement(dialogContainerRef.current)),()=>disposable==null?void 0:disposable.dispose()},[layoutService]);const focusRef=require$$0.useRef(null),setDialogContainerFocus=require$$0.useCallback(focused=>contextService.setContextValue(FIND_REPLACE_DIALOG_FOCUS,focused),[contextService]),setDialogInputFocus=require$$0.useCallback(focused=>contextService.setContextValue(FIND_REPLACE_INPUT_FOCUS,focused),[contextService]);return require$$0.useEffect(()=>{var _a5;const focusSubscription=rxjs.fromEvent(document,"focusin").subscribe(event=>{var _a6;event.target&&((_a6=dialogContainerRef.current)!=null&&_a6.contains(event.target))?setDialogContainerFocus(!0):setDialogContainerFocus(!1),!focusRef.current||!focusRef.current.selectHasFocus()?setDialogInputFocus(!0):setDialogInputFocus(!1)});return(_a5=focusRef.current)==null||_a5.focus(),setDialogContainerFocus(!0),setDialogInputFocus(!0),()=>{focusSubscription.unsubscribe(),setDialogContainerFocus(!1)}},[setDialogContainerFocus,setDialogInputFocus]),jsxRuntimeExports.jsx("div",{className:styles.findReplaceDialogContainer,ref:dialogContainerRef,children:state.replaceRevealed?jsxRuntimeExports.jsx(ReplaceDialog,{ref:focusRef}):jsxRuntimeExports.jsx(FindDialog,{ref:focusRef})})}__name(FindReplaceDialog,"FindReplaceDialog");function useFindScopeOptions(localeService){const locale=localeService.getCurrentLocale();return require$$0.useMemo(()=>[{label:localeService.t("find-replace.dialog.find-scope.current-sheet"),value:FindScope.SUBUNIT},{label:localeService.t("find-replace.dialog.find-scope.workbook"),value:FindScope.UNIT}],[locale])}__name(useFindScopeOptions,"useFindScopeOptions");function useFindDirectionOptions(localeService){const locale=localeService.getCurrentLocale();return require$$0.useMemo(()=>[{label:localeService.t("find-replace.dialog.find-direction.row"),value:FindDirection.ROW},{label:localeService.t("find-replace.dialog.find-direction.column"),value:FindDirection.COLUMN}],[locale])}__name(useFindDirectionOptions,"useFindDirectionOptions");function useFindByOptions(localeService){const locale=localeService.getCurrentLocale();return require$$0.useMemo(()=>[{label:localeService.t("find-replace.dialog.find-by.value"),value:FindBy.VALUE},{label:localeService.t("find-replace.dialog.find-by.formula"),value:FindBy.FORMULA}],[locale])}__name(useFindByOptions,"useFindByOptions");function whenFindReplaceDialogFocused(contextService){return contextService.getContextValue(FIND_REPLACE_DIALOG_FOCUS)}__name(whenFindReplaceDialogFocused,"whenFindReplaceDialogFocused");function whenReplaceRevealed(contextService){return contextService.getContextValue(FIND_REPLACE_REPLACE_REVEALED)}__name(whenReplaceRevealed,"whenReplaceRevealed");function whenFindReplaceInputFocused(contextService){return contextService.getContextValue(FIND_REPLACE_INPUT_FOCUS)}__name(whenFindReplaceInputFocused,"whenFindReplaceInputFocused");const FIND_REPLACE_SHORTCUT_GROUP="7_find-replace-shortcuts";function whenSheetFocused(contextService){return contextService.getContextValue(core.FOCUSING_SHEET)}__name(whenSheetFocused,"whenSheetFocused");function whenEditorNotActivated(contextService){return!contextService.getContextValue(core.EDITOR_ACTIVATED)}__name(whenEditorNotActivated,"whenEditorNotActivated");const OpenFindDialogShortcutItem={id:OpenFindDialogOperation.id,description:"find-replace.shortcut.open-find-dialog",binding:ui.KeyCode.F|ui.MetaKeys.CTRL_COMMAND,group:FIND_REPLACE_SHORTCUT_GROUP,preconditions(contextService){return!whenFindReplaceDialogFocused(contextService)&&whenSheetFocused(contextService)&&whenEditorNotActivated(contextService)}},MacOpenFindDialogShortcutItem={id:OpenFindDialogOperation.id,description:"find-replace.shortcut.open-find-dialog",binding:ui.KeyCode.F|ui.MetaKeys.CTRL_COMMAND,mac:ui.KeyCode.F|ui.MetaKeys.MAC_CTRL,preconditions(contextService){return!whenFindReplaceDialogFocused(contextService)&&whenSheetFocused(contextService)&&whenEditorNotActivated(contextService)}},OpenReplaceDialogShortcutItem={id:OpenReplaceDialogOperation.id,description:"find-replace.shortcut.open-replace-dialog",binding:ui.KeyCode.H|ui.MetaKeys.CTRL_COMMAND,mac:ui.KeyCode.H|ui.MetaKeys.MAC_CTRL,group:FIND_REPLACE_SHORTCUT_GROUP,preconditions(contextService){return whenSheetFocused(contextService)&&whenEditorNotActivated(contextService)&&(!whenFindReplaceDialogFocused(contextService)||!whenReplaceRevealed(contextService))}},GoToNextFindMatchShortcutItem={id:GoToNextMatchOperation.id,description:"find-replace.shortcut.go-to-next-match",binding:ui.KeyCode.ENTER,group:FIND_REPLACE_SHORTCUT_GROUP,priority:1e3,preconditions(contextService){return whenFindReplaceInputFocused(contextService)&&whenFindReplaceDialogFocused(contextService)}},GoToPreviousFindMatchShortcutItem={id:GoToPreviousMatchOperation.id,description:"find-replace.shortcut.go-to-previous-match",binding:ui.KeyCode.ENTER|ui.MetaKeys.SHIFT,group:FIND_REPLACE_SHORTCUT_GROUP,priority:1e3,preconditions(contextService){return whenFindReplaceInputFocused(contextService)&&whenFindReplaceDialogFocused(contextService)}};function FindReplaceMenuItemFactory(accessor){const contextService=accessor.get(core.IContextService);return{id:OpenFindDialogOperation.id,icon:"SearchIcon",tooltip:"find-replace.toolbar",group:ui.MenuGroup.TOOLBAR_OTHERS,type:ui.MenuItemType.BUTTON,positions:[ui.MenuPosition.TOOLBAR_START],hidden$:ui.getMenuHiddenObservable(accessor,core.UniverInstanceType.UNIVER_SHEET),disabled$:rxjs.combineLatest([contextService.subscribeContextValue$(core.EDITOR_ACTIVATED),contextService.subscribeContextValue$(core.FOCUSING_SHEET)]).pipe(rxjs.map(([editorActivated,focusingSheet])=>editorActivated||!focusingSheet))}}__name(FindReplaceMenuItemFactory,"FindReplaceMenuItemFactory");var __defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$1");const DefaultFindReplaceConfig={},FIND_REPLACE_DIALOG_ID="DESKTOP_FIND_REPLACE_DIALOG",FIND_REPLACE_PANEL_WIDTH=350,FIND_REPLACE_PANEL_RIGHT_PADDING=20,FIND_REPLACE_PANEL_TOP_PADDING=-90;var _a3;exports.FindReplaceController=(_a3=class extends core.RxDisposable{constructor(_config,_univerInstanceService,_menuService,_shortcutService,_commandService,_findReplaceService,_dialogService,_layoutService,_localeService,_componentManager,_injector){super();__publicField(this,"_closingListenerDisposable");this._config=_config,this._univerInstanceService=_univerInstanceService,this._menuService=_menuService,this._shortcutService=_shortcutService,this._commandService=_commandService,this._findReplaceService=_findReplaceService,this._dialogService=_dialogService,this._layoutService=_layoutService,this._localeService=_localeService,this._componentManager=_componentManager,this._injector=_injector,this._initCommands(),this._initUI(),this._initShortcuts()}dispose(){var _a5;super.dispose(),(_a5=this._closingListenerDisposable)==null||_a5.dispose(),this._closingListenerDisposable=null}_initCommands(){[OpenFindDialogOperation,OpenReplaceDialogOperation,GoToNextMatchOperation,GoToPreviousMatchOperation,ReplaceAllMatchesCommand,ReplaceCurrentMatchCommand].forEach(c=>{this.disposeWithMe(this._commandService.registerCommand(c))})}_initShortcuts(){[OpenReplaceDialogShortcutItem,OpenFindDialogShortcutItem,MacOpenFindDialogShortcutItem,GoToPreviousFindMatchShortcutItem,GoToNextFindMatchShortcutItem].forEach(s=>this.disposeWithMe(this._shortcutService.registerShortcut(s)))}_initUI(){const{menu={}}=this._config;this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(FindReplaceMenuItemFactory),menu)),this.disposeWithMe(this._componentManager.register("FindReplaceDialog",FindReplaceDialog)),this.disposeWithMe(this._componentManager.register("SearchIcon",SearchSingle16)),this._findReplaceService.stateUpdates$.pipe(rxjs.takeUntil(this.dispose$)).subscribe(newState=>{newState.revealed===!0&&this._openPanel()})}_openPanel(){this._dialogService.open({id:FIND_REPLACE_DIALOG_ID,draggable:!0,width:FIND_REPLACE_PANEL_WIDTH,title:{title:this._localeService.t("find-replace.dialog.title")},children:{label:"FindReplaceDialog"},destroyOnClose:!0,defaultPosition:getFindReplaceDialogDefaultPosition(),preservePositionOnDestroy:!0,onClose:__name(()=>this.closePanel(),"onClose")}),this._closingListenerDisposable=core.toDisposable(this._univerInstanceService.focused$.pipe(rxjs.takeUntil(this.dispose$)).subscribe(focused=>{(!focused||!this._univerInstanceService.getUniverSheetInstance(focused))&&this.closePanel()}))}closePanel(){this._closingListenerDisposable&&(this._closingListenerDisposable.dispose(),this._closingListenerDisposable=null,this._dialogService.close(FIND_REPLACE_DIALOG_ID),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus()))}},__name(_a3,"FindReplaceController"),_a3);exports.FindReplaceController=__decorateClass$1([core.OnLifecycle(core.LifecycleStages.Rendered,exports.FindReplaceController),__decorateParam$1(1,core.IUniverInstanceService),__decorateParam$1(2,ui.IMenuService),__decorateParam$1(3,ui.IShortcutService),__decorateParam$1(4,core.ICommandService),__decorateParam$1(5,IFindReplaceService),__decorateParam$1(6,ui.IDialogService),__decorateParam$1(7,ui.ILayoutService),__decorateParam$1(8,core.Inject(core.LocaleService)),__decorateParam$1(9,core.Inject(ui.ComponentManager)),__decorateParam$1(10,core.Inject(core.Injector))],exports.FindReplaceController);function getFindReplaceDialogDefaultPosition(){const{innerWidth}=window;return{x:(innerWidth-FIND_REPLACE_PANEL_WIDTH)/2-FIND_REPLACE_PANEL_RIGHT_PADDING,y:FIND_REPLACE_PANEL_TOP_PADDING}}__name(getFindReplaceDialogDefaultPosition,"getFindReplaceDialogDefaultPosition");var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam");const PLUGIN_NAME="FIND_REPLACE_PLUGIN";var _a4;exports.UniverFindReplacePlugin=(_a4=class extends core.Plugin{constructor(_config={},_injector,_localeService){super(),this._config=_config,this._injector=_injector,this._localeService=_localeService,this._config=core.Tools.deepMerge({},DefaultFindReplaceConfig,this._config)}onStarting(){[[exports.FindReplaceController,{useFactory:__name(()=>this._injector.createInstance(exports.FindReplaceController,this._config),"useFactory")}],[IFindReplaceService,{useClass:FindReplaceService}]].forEach(d=>{this._injector.add(d)})}},__name(_a4,"UniverFindReplacePlugin"),__publicField(_a4,"pluginName",PLUGIN_NAME),_a4);exports.UniverFindReplacePlugin=__decorateClass([__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.Inject(core.LocaleService))],exports.UniverFindReplacePlugin);exports.FindBy=FindBy;exports.FindDirection=FindDirection;exports.FindModel=FindModel;exports.FindScope=FindScope;exports.GoToNextMatchOperation=GoToNextMatchOperation;exports.GoToPreviousMatchOperation=GoToPreviousMatchOperation;exports.IFindReplaceService=IFindReplaceService;exports.OpenFindDialogOperation=OpenFindDialogOperation;exports.OpenReplaceDialogOperation=OpenReplaceDialogOperation;exports.ReplaceAllMatchesCommand=ReplaceAllMatchesCommand;exports.ReplaceCurrentMatchCommand=ReplaceCurrentMatchCommand;
package/lib/es/index.js CHANGED
@@ -820,7 +820,13 @@ const DefaultFindReplaceConfig = {}, FIND_REPLACE_DIALOG_ID = "DESKTOP_FIND_REPL
820
820
  var _a3;
821
821
  let FindReplaceController = (_a3 = class extends RxDisposable {
822
822
  constructor(_config, _univerInstanceService, _menuService, _shortcutService, _commandService, _findReplaceService, _dialogService, _layoutService, _localeService, _componentManager, _injector) {
823
- super(), this._config = _config, this._univerInstanceService = _univerInstanceService, this._menuService = _menuService, this._shortcutService = _shortcutService, this._commandService = _commandService, this._findReplaceService = _findReplaceService, this._dialogService = _dialogService, this._layoutService = _layoutService, this._localeService = _localeService, this._componentManager = _componentManager, this._injector = _injector, this._initCommands(), this._initUI(), this._initShortcuts();
823
+ super();
824
+ __publicField(this, "_closingListenerDisposable");
825
+ this._config = _config, this._univerInstanceService = _univerInstanceService, this._menuService = _menuService, this._shortcutService = _shortcutService, this._commandService = _commandService, this._findReplaceService = _findReplaceService, this._dialogService = _dialogService, this._layoutService = _layoutService, this._localeService = _localeService, this._componentManager = _componentManager, this._injector = _injector, this._initCommands(), this._initUI(), this._initShortcuts();
826
+ }
827
+ dispose() {
828
+ var _a5;
829
+ super.dispose(), (_a5 = this._closingListenerDisposable) == null || _a5.dispose(), this._closingListenerDisposable = null;
824
830
  }
825
831
  _initCommands() {
826
832
  [
@@ -847,11 +853,7 @@ let FindReplaceController = (_a3 = class extends RxDisposable {
847
853
  const { menu = {} } = this._config;
848
854
  this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(FindReplaceMenuItemFactory), menu)), this.disposeWithMe(this._componentManager.register("FindReplaceDialog", FindReplaceDialog)), this.disposeWithMe(this._componentManager.register("SearchIcon", SearchSingle16)), this._findReplaceService.stateUpdates$.pipe(takeUntil(this.dispose$)).subscribe((newState) => {
849
855
  newState.revealed === !0 && this._openPanel();
850
- }), this.disposeWithMe(
851
- this._univerInstanceService.focused$.pipe(takeUntil(this.dispose$)).subscribe((focused) => {
852
- (!focused || !this._univerInstanceService.getUniverSheetInstance(focused)) && this.closePanel();
853
- })
854
- );
856
+ });
855
857
  }
856
858
  _openPanel() {
857
859
  this._dialogService.open({
@@ -864,10 +866,12 @@ let FindReplaceController = (_a3 = class extends RxDisposable {
864
866
  defaultPosition: getFindReplaceDialogDefaultPosition(),
865
867
  preservePositionOnDestroy: !0,
866
868
  onClose: /* @__PURE__ */ __name(() => this.closePanel(), "onClose")
867
- });
869
+ }), this._closingListenerDisposable = toDisposable(this._univerInstanceService.focused$.pipe(takeUntil(this.dispose$)).subscribe((focused) => {
870
+ (!focused || !this._univerInstanceService.getUniverSheetInstance(focused)) && this.closePanel();
871
+ }));
868
872
  }
869
873
  closePanel() {
870
- this._dialogService.close(FIND_REPLACE_DIALOG_ID), this._findReplaceService.terminate(), queueMicrotask(() => this._layoutService.focus());
874
+ this._closingListenerDisposable && (this._closingListenerDisposable.dispose(), this._closingListenerDisposable = null, this._dialogService.close(FIND_REPLACE_DIALOG_ID), this._findReplaceService.terminate(), queueMicrotask(() => this._layoutService.focus()));
871
875
  }
872
876
  }, __name(_a3, "FindReplaceController"), _a3);
873
877
  FindReplaceController = __decorateClass$1([
@@ -19,9 +19,11 @@ export declare class FindReplaceController extends RxDisposable {
19
19
  private readonly _componentManager;
20
20
  private readonly _injector;
21
21
  constructor(_config: Partial<IUniverFindReplaceConfig>, _univerInstanceService: IUniverInstanceService, _menuService: IMenuService, _shortcutService: IShortcutService, _commandService: ICommandService, _findReplaceService: IFindReplaceService, _dialogService: IDialogService, _layoutService: ILayoutService, _localeService: LocaleService, _componentManager: ComponentManager, _injector: Injector);
22
+ dispose(): void;
22
23
  private _initCommands;
23
24
  private _initShortcuts;
24
25
  private _initUI;
25
26
  private _openPanel;
27
+ private _closingListenerDisposable;
26
28
  closePanel(): void;
27
29
  }
package/lib/umd/index.js CHANGED
@@ -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 f=require$$0,k=Symbol.for("react.element"),l=Symbol.for("react.fragment"),m=Object.prototype.hasOwnProperty,n=f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,p={key:!0,ref:!0,__self:!0,__source:!0};function q(c,a,g){var b,d={},e=null,h=null;g!==void 0&&(e=""+g),a.key!==void 0&&(e=""+a.key),a.ref!==void 0&&(h=a.ref);for(b in a)m.call(a,b)&&!p.hasOwnProperty(b)&&(d[b]=a[b]);if(c&&c.defaultProps)for(b in a=c.defaultProps,a)d[b]===void 0&&(d[b]=a[b]);return{$$typeof:k,type:c,key:e,ref:h,props:d,_owner:n.current}}__name(q,"q"),reactJsxRuntime_production_min.Fragment=l,reactJsxRuntime_production_min.jsx=q,reactJsxRuntime_production_min.jsxs=q,jsxRuntime.exports=reactJsxRuntime_production_min;var jsxRuntimeExports=jsxRuntime.exports;const ReplaceCurrentMatchCommand={id:"ui.command.replace-current-match",type:core.CommandType.COMMAND,handler:__name(accessor=>accessor.get(IFindReplaceService).replace(),"handler")},CONFIRM_REPLACE_ALL_ID="CONFIRM_REPLACE_ALL",ReplaceAllMatchesCommand={id:"ui.command.replace-all-matches",type:core.CommandType.COMMAND,handler:__name(async accessor=>{const confirmService=accessor.get(ui.IConfirmService),localeService=accessor.get(core.LocaleService),messageService=accessor.get(ui.IMessageService);if(!await confirmService.confirm({id:CONFIRM_REPLACE_ALL_ID,title:{title:localeService.t("find-replace.replace.confirm.title")},cancelText:localeService.t("button.cancel"),confirmText:localeService.t("button.confirm")}))return!1;const result=await accessor.get(IFindReplaceService).replaceAll(),{success,failure}=result;return failure>0?(success===0?messageService.show({type:design.MessageType.Error,content:localeService.t("find-replace.replace.all-failure")}):messageService.show({type:design.MessageType.Warning,content:localeService.t("find-replace.replace.partial-success",`${success}`,`${failure}`)}),!1):(messageService.show({type:design.MessageType.Success,content:localeService.t("find-replace.replace.all-success",`${success}`)}),!0)},"handler")};function SearchInput(props){const{findCompleted:findComplete,localeService,matchesCount,matchesPosition,findString,findReplaceService,onChange,...rest}=props,text=findComplete&&matchesCount===0?localeService.t("find-replace.dialog.no-result"):matchesCount===0?" ":void 0;return jsxRuntimeExports.jsx(design.InputWithSlot,{autoFocus:!0,placeholder:localeService.t("find-replace.dialog.find-placeholder"),slot:jsxRuntimeExports.jsx(design.Pager,{loop:!0,text,value:matchesPosition,total:matchesCount,onChange:__name(newIndex=>{matchesPosition===matchesCount&&newIndex===1?findReplaceService.moveToNextMatch():matchesPosition===1&&newIndex===matchesCount||newIndex<matchesPosition?findReplaceService.moveToPreviousMatch():findReplaceService.moveToNextMatch()},"onChange")}),value:findString,onChange:__name(value=>onChange==null?void 0:onChange(value),"onChange"),...rest})}__name(SearchInput,"SearchInput");const styles={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 useFindInputFocus(findReplaceService,ref){const focus=require$$0.useCallback(()=>{var _a2;(_a2=document.querySelector(".univer-find-input input"))==null||_a2.focus()},[]),selectHasFocus=require$$0.useCallback(()=>{const allInputs=document.querySelectorAll(".univer-find-replace-dialog-container .univer-select-selection-search-input");return Array.from(allInputs).some(input=>input===document.activeElement)},[]);return require$$0.useImperativeHandle(ref,()=>({focus,selectHasFocus})),require$$0.useEffect(()=>{const subscription=findReplaceService.focusSignal$.subscribe(()=>focus());return()=>subscription.unsubscribe()},[findReplaceService,focus]),{focus,selectHasFocus}}__name(useFindInputFocus,"useFindInputFocus");const FindDialog=require$$0.forwardRef(__name(function(_props,ref){const localeService=core.useDependency(core.LocaleService),findReplaceService=core.useDependency(IFindReplaceService),commandService=core.useDependency(core.ICommandService),state=ui.useObservable(findReplaceService.state$,void 0,!0),{findCompleted,findString,matchesCount,matchesPosition}=state,revealReplace=require$$0.useCallback(()=>{commandService.executeCommand(OpenReplaceDialogOperation.id)},[commandService]),onFindStringChange=require$$0.useCallback(findString2=>findReplaceService.changeFindString(findString2),[findReplaceService]);return useFindInputFocus(findReplaceService,ref),jsxRuntimeExports.jsxs(require$$0.Fragment,{children:[jsxRuntimeExports.jsx(SearchInput,{findCompleted,className:"univer-find-input",matchesCount,matchesPosition,findReplaceService,localeService,findString,onChange:onFindStringChange}),jsxRuntimeExports.jsx("div",{className:styles.findReplaceExpandContainer,children:jsxRuntimeExports.jsx(design.Button,{type:"text",size:"small",onClick:revealReplace,children:localeService.t("find-replace.dialog.advanced-finding")})})]})},"FindDialogImpl")),ReplaceDialog=require$$0.forwardRef(__name(function(_props,ref){const findReplaceService=core.useDependency(IFindReplaceService),localeService=core.useDependency(core.LocaleService),commandService=core.useDependency(core.ICommandService),messageService=core.useDependency(ui.IMessageService),currentMatch=ui.useObservable(findReplaceService.currentMatch$,void 0,!0),replaceables=ui.useObservable(findReplaceService.replaceables$,void 0,!0),state=ui.useObservable(findReplaceService.state$,void 0,!0),{matchesCount,matchesPosition,findString,inputtingFindString,replaceString,caseSensitive,matchesTheWholeCell,findDirection,findScope,findBy,findCompleted}=state,findDisabled=inputtingFindString.length===0,replaceDisabled=matchesCount===0||!(currentMatch!=null&&currentMatch.replaceable),replaceAllDisabled=replaceables.length===0,onFindStringChange=require$$0.useCallback(newValue=>findReplaceService.changeInputtingFindString(newValue),[findReplaceService]),onReplaceStringChange=require$$0.useCallback(replaceString2=>findReplaceService.changeReplaceString(replaceString2),[findReplaceService]),{focus}=useFindInputFocus(findReplaceService,ref),onClickFindButton=require$$0.useCallback(()=>{findString===inputtingFindString?findReplaceService.moveToNextMatch():(findReplaceService.changeFindString(inputtingFindString),findReplaceService.find())},[findString,inputtingFindString,findReplaceService]),onClickReplaceButton=require$$0.useCallback(()=>commandService.executeCommand(ReplaceCurrentMatchCommand.id),[commandService]),onClickReplaceAllButton=require$$0.useCallback(async()=>{await commandService.executeCommand(ReplaceAllMatchesCommand.id),focus()},[commandService]),onChangeFindDirection=require$$0.useCallback(findDirection2=>{findReplaceService.changeFindDirection(findDirection2)},[findReplaceService]),onChangeFindScope=require$$0.useCallback(findScope2=>{findReplaceService.changeFindScope(findScope2)},[findReplaceService]),onChangeFindBy=require$$0.useCallback(findBy2=>{findReplaceService.changeFindBy(findBy2)},[findReplaceService]),findScopeOptions=useFindScopeOptions(localeService),findDirectionOptions=useFindDirectionOptions(localeService),findByOptions=useFindByOptions(localeService);return require$$0.useEffect(()=>{const shouldDisplayNoMatchInfo=findCompleted&&matchesCount===0;let messageDisposable=null;return shouldDisplayNoMatchInfo&&(messageDisposable=messageService.show({content:localeService.t("find-replace.dialog.no-match"),type:design.MessageType.Warning,duration:5e3})),()=>messageDisposable==null?void 0:messageDisposable.dispose()},[findCompleted,matchesCount,messageService,localeService]),jsxRuntimeExports.jsxs(require$$0.Fragment,{children:[jsxRuntimeExports.jsx(design.FormLayout,{label:localeService.t("find-replace.dialog.find"),children:jsxRuntimeExports.jsx(SearchInput,{findCompleted,className:"univer-find-input",matchesCount,matchesPosition,findReplaceService,localeService,findString:inputtingFindString,onChange:onFindStringChange})}),jsxRuntimeExports.jsx(design.FormLayout,{label:localeService.t("find-replace.dialog.replace"),children:jsxRuntimeExports.jsx(design.Input,{placeholder:localeService.t("find-replace.dialog.replace-placeholder"),value:replaceString,onChange:__name(value=>onReplaceStringChange(value),"onChange")})}),jsxRuntimeExports.jsx(design.FormLayout,{label:localeService.t("find-replace.dialog.find-direction.title"),children:jsxRuntimeExports.jsx(design.Select,{value:findDirection,options:findDirectionOptions,onChange:onChangeFindDirection})}),jsxRuntimeExports.jsx(design.FormDualColumnLayout,{children:jsxRuntimeExports.jsxs(require$$0.Fragment,{children:[jsxRuntimeExports.jsx(design.FormLayout,{label:localeService.t("find-replace.dialog.find-scope.title"),children:jsxRuntimeExports.jsx(design.Select,{value:findScope,options:findScopeOptions,onChange:onChangeFindScope})}),jsxRuntimeExports.jsx(design.FormLayout,{label:localeService.t("find-replace.dialog.find-by.title"),children:jsxRuntimeExports.jsx(design.Select,{value:findBy,options:findByOptions,onChange:onChangeFindBy})})]})}),jsxRuntimeExports.jsx(design.FormDualColumnLayout,{children:jsxRuntimeExports.jsxs(require$$0.Fragment,{children:[jsxRuntimeExports.jsx(design.FormLayout,{children:jsxRuntimeExports.jsx(design.Checkbox,{checked:caseSensitive,onChange:__name(checked=>{findReplaceService.changeCaseSensitive(checked)},"onChange"),children:localeService.t("find-replace.dialog.case-sensitive")})}),jsxRuntimeExports.jsx(design.FormLayout,{children:jsxRuntimeExports.jsx(design.Checkbox,{checked:matchesTheWholeCell,onChange:__name(checked=>{findReplaceService.changeMatchesTheWholeCell(checked)},"onChange"),children:localeService.t("find-replace.dialog.match-the-whole-cell")})})]})}),jsxRuntimeExports.jsxs("div",{className:styles.findReplaceButtonsGroup,children:[jsxRuntimeExports.jsx(design.Button,{type:"primary",onClick:onClickFindButton,disabled:findDisabled,children:localeService.t("find-replace.dialog.find")}),jsxRuntimeExports.jsxs("span",{className:styles.findReplaceButtonsGroupRight,children:[jsxRuntimeExports.jsx(design.Button,{disabled:replaceDisabled,onClick:onClickReplaceButton,children:localeService.t("find-replace.dialog.replace")}),jsxRuntimeExports.jsx(design.Button,{disabled:replaceAllDisabled,onClick:onClickReplaceAllButton,children:localeService.t("find-replace.dialog.replace-all")})]})]})]})},"ReplaceDIalogImpl"));function FindReplaceDialog(){const findReplaceService=core.useDependency(IFindReplaceService),layoutService=core.useDependency(ui.ILayoutService),contextService=core.useDependency(core.IContextService),state=ui.useObservable(findReplaceService.state$,void 0,!0),dialogContainerRef=require$$0.useRef(null);require$$0.useEffect(()=>{let disposable;return dialogContainerRef.current&&(disposable=layoutService.registerContainerElement(dialogContainerRef.current)),()=>disposable==null?void 0:disposable.dispose()},[layoutService]);const focusRef=require$$0.useRef(null),setDialogContainerFocus=require$$0.useCallback(focused=>contextService.setContextValue(FIND_REPLACE_DIALOG_FOCUS,focused),[contextService]),setDialogInputFocus=require$$0.useCallback(focused=>contextService.setContextValue(FIND_REPLACE_INPUT_FOCUS,focused),[contextService]);return require$$0.useEffect(()=>{var _a2;const focusSubscription=rxjs.fromEvent(document,"focusin").subscribe(event=>{var _a3;event.target&&((_a3=dialogContainerRef.current)!=null&&_a3.contains(event.target))?setDialogContainerFocus(!0):setDialogContainerFocus(!1),!focusRef.current||!focusRef.current.selectHasFocus()?setDialogInputFocus(!0):setDialogInputFocus(!1)});return(_a2=focusRef.current)==null||_a2.focus(),setDialogContainerFocus(!0),setDialogInputFocus(!0),()=>{focusSubscription.unsubscribe(),setDialogContainerFocus(!1)}},[setDialogContainerFocus,setDialogInputFocus]),jsxRuntimeExports.jsx("div",{className:styles.findReplaceDialogContainer,ref:dialogContainerRef,children:state.replaceRevealed?jsxRuntimeExports.jsx(ReplaceDialog,{ref:focusRef}):jsxRuntimeExports.jsx(FindDialog,{ref:focusRef})})}__name(FindReplaceDialog,"FindReplaceDialog");function useFindScopeOptions(localeService){const locale=localeService.getCurrentLocale();return require$$0.useMemo(()=>[{label:localeService.t("find-replace.dialog.find-scope.current-sheet"),value:FindScope.SUBUNIT},{label:localeService.t("find-replace.dialog.find-scope.workbook"),value:FindScope.UNIT}],[locale])}__name(useFindScopeOptions,"useFindScopeOptions");function useFindDirectionOptions(localeService){const locale=localeService.getCurrentLocale();return require$$0.useMemo(()=>[{label:localeService.t("find-replace.dialog.find-direction.row"),value:FindDirection.ROW},{label:localeService.t("find-replace.dialog.find-direction.column"),value:FindDirection.COLUMN}],[locale])}__name(useFindDirectionOptions,"useFindDirectionOptions");function useFindByOptions(localeService){const locale=localeService.getCurrentLocale();return require$$0.useMemo(()=>[{label:localeService.t("find-replace.dialog.find-by.value"),value:FindBy.VALUE},{label:localeService.t("find-replace.dialog.find-by.formula"),value:FindBy.FORMULA}],[locale])}__name(useFindByOptions,"useFindByOptions");function whenFindReplaceDialogFocused(contextService){return contextService.getContextValue(FIND_REPLACE_DIALOG_FOCUS)}__name(whenFindReplaceDialogFocused,"whenFindReplaceDialogFocused");function whenReplaceRevealed(contextService){return contextService.getContextValue(FIND_REPLACE_REPLACE_REVEALED)}__name(whenReplaceRevealed,"whenReplaceRevealed");function whenFindReplaceInputFocused(contextService){return contextService.getContextValue(FIND_REPLACE_INPUT_FOCUS)}__name(whenFindReplaceInputFocused,"whenFindReplaceInputFocused");const FIND_REPLACE_SHORTCUT_GROUP="7_find-replace-shortcuts";function whenSheetFocused(contextService){return contextService.getContextValue(core.FOCUSING_SHEET)}__name(whenSheetFocused,"whenSheetFocused");function whenEditorNotActivated(contextService){return!contextService.getContextValue(core.EDITOR_ACTIVATED)}__name(whenEditorNotActivated,"whenEditorNotActivated");const OpenFindDialogShortcutItem={id:OpenFindDialogOperation.id,description:"find-replace.shortcut.open-find-dialog",binding:ui.KeyCode.F|ui.MetaKeys.CTRL_COMMAND,group:FIND_REPLACE_SHORTCUT_GROUP,preconditions(contextService){return!whenFindReplaceDialogFocused(contextService)&&whenSheetFocused(contextService)&&whenEditorNotActivated(contextService)}},MacOpenFindDialogShortcutItem={id:OpenFindDialogOperation.id,description:"find-replace.shortcut.open-find-dialog",binding:ui.KeyCode.F|ui.MetaKeys.CTRL_COMMAND,mac:ui.KeyCode.F|ui.MetaKeys.MAC_CTRL,preconditions(contextService){return!whenFindReplaceDialogFocused(contextService)&&whenSheetFocused(contextService)&&whenEditorNotActivated(contextService)}},OpenReplaceDialogShortcutItem={id:OpenReplaceDialogOperation.id,description:"find-replace.shortcut.open-replace-dialog",binding:ui.KeyCode.H|ui.MetaKeys.CTRL_COMMAND,mac:ui.KeyCode.H|ui.MetaKeys.MAC_CTRL,group:FIND_REPLACE_SHORTCUT_GROUP,preconditions(contextService){return whenSheetFocused(contextService)&&whenEditorNotActivated(contextService)&&(!whenFindReplaceDialogFocused(contextService)||!whenReplaceRevealed(contextService))}},GoToNextFindMatchShortcutItem={id:GoToNextMatchOperation.id,description:"find-replace.shortcut.go-to-next-match",binding:ui.KeyCode.ENTER,group:FIND_REPLACE_SHORTCUT_GROUP,priority:1e3,preconditions(contextService){return whenFindReplaceInputFocused(contextService)&&whenFindReplaceDialogFocused(contextService)}},GoToPreviousFindMatchShortcutItem={id:GoToPreviousMatchOperation.id,description:"find-replace.shortcut.go-to-previous-match",binding:ui.KeyCode.ENTER|ui.MetaKeys.SHIFT,group:FIND_REPLACE_SHORTCUT_GROUP,priority:1e3,preconditions(contextService){return whenFindReplaceInputFocused(contextService)&&whenFindReplaceDialogFocused(contextService)}};function FindReplaceMenuItemFactory(accessor){const contextService=accessor.get(core.IContextService);return{id:OpenFindDialogOperation.id,icon:"SearchIcon",tooltip:"find-replace.toolbar",group:ui.MenuGroup.TOOLBAR_OTHERS,type:ui.MenuItemType.BUTTON,positions:[ui.MenuPosition.TOOLBAR_START],hidden$:ui.getMenuHiddenObservable(accessor,core.UniverInstanceType.UNIVER_SHEET),disabled$:rxjs.combineLatest([contextService.subscribeContextValue$(core.EDITOR_ACTIVATED),contextService.subscribeContextValue$(core.FOCUSING_SHEET)]).pipe(rxjs.map(([editorActivated,focusingSheet])=>editorActivated||!focusingSheet))}}__name(FindReplaceMenuItemFactory,"FindReplaceMenuItemFactory");var __defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$1");const DefaultFindReplaceConfig={},FIND_REPLACE_DIALOG_ID="DESKTOP_FIND_REPLACE_DIALOG",FIND_REPLACE_PANEL_WIDTH=350,FIND_REPLACE_PANEL_RIGHT_PADDING=20,FIND_REPLACE_PANEL_TOP_PADDING=-90;exports2.FindReplaceController=(_c=class extends core.RxDisposable{constructor(_config,_univerInstanceService,_menuService,_shortcutService,_commandService,_findReplaceService,_dialogService,_layoutService,_localeService,_componentManager,_injector){super(),this._config=_config,this._univerInstanceService=_univerInstanceService,this._menuService=_menuService,this._shortcutService=_shortcutService,this._commandService=_commandService,this._findReplaceService=_findReplaceService,this._dialogService=_dialogService,this._layoutService=_layoutService,this._localeService=_localeService,this._componentManager=_componentManager,this._injector=_injector,this._initCommands(),this._initUI(),this._initShortcuts()}_initCommands(){[OpenFindDialogOperation,OpenReplaceDialogOperation,GoToNextMatchOperation,GoToPreviousMatchOperation,ReplaceAllMatchesCommand,ReplaceCurrentMatchCommand].forEach(c=>{this.disposeWithMe(this._commandService.registerCommand(c))})}_initShortcuts(){[OpenReplaceDialogShortcutItem,OpenFindDialogShortcutItem,MacOpenFindDialogShortcutItem,GoToPreviousFindMatchShortcutItem,GoToNextFindMatchShortcutItem].forEach(s=>this.disposeWithMe(this._shortcutService.registerShortcut(s)))}_initUI(){const{menu={}}=this._config;this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(FindReplaceMenuItemFactory),menu)),this.disposeWithMe(this._componentManager.register("FindReplaceDialog",FindReplaceDialog)),this.disposeWithMe(this._componentManager.register("SearchIcon",SearchSingle16)),this._findReplaceService.stateUpdates$.pipe(rxjs.takeUntil(this.dispose$)).subscribe(newState=>{newState.revealed===!0&&this._openPanel()}),this.disposeWithMe(this._univerInstanceService.focused$.pipe(rxjs.takeUntil(this.dispose$)).subscribe(focused=>{(!focused||!this._univerInstanceService.getUniverSheetInstance(focused))&&this.closePanel()}))}_openPanel(){this._dialogService.open({id:FIND_REPLACE_DIALOG_ID,draggable:!0,width:FIND_REPLACE_PANEL_WIDTH,title:{title:this._localeService.t("find-replace.dialog.title")},children:{label:"FindReplaceDialog"},destroyOnClose:!0,defaultPosition:getFindReplaceDialogDefaultPosition(),preservePositionOnDestroy:!0,onClose:__name(()=>this.closePanel(),"onClose")})}closePanel(){this._dialogService.close(FIND_REPLACE_DIALOG_ID),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus())}},__name(_c,"FindReplaceController"),_c),exports2.FindReplaceController=__decorateClass$1([core.OnLifecycle(core.LifecycleStages.Rendered,exports2.FindReplaceController),__decorateParam$1(1,core.IUniverInstanceService),__decorateParam$1(2,ui.IMenuService),__decorateParam$1(3,ui.IShortcutService),__decorateParam$1(4,core.ICommandService),__decorateParam$1(5,IFindReplaceService),__decorateParam$1(6,ui.IDialogService),__decorateParam$1(7,ui.ILayoutService),__decorateParam$1(8,core.Inject(core.LocaleService)),__decorateParam$1(9,core.Inject(ui.ComponentManager)),__decorateParam$1(10,core.Inject(core.Injector))],exports2.FindReplaceController);function getFindReplaceDialogDefaultPosition(){const{innerWidth}=window;return{x:(innerWidth-FIND_REPLACE_PANEL_WIDTH)/2-FIND_REPLACE_PANEL_RIGHT_PADDING,y:FIND_REPLACE_PANEL_TOP_PADDING}}__name(getFindReplaceDialogDefaultPosition,"getFindReplaceDialogDefaultPosition");var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam");const PLUGIN_NAME="FIND_REPLACE_PLUGIN";exports2.UniverFindReplacePlugin=(_d=class extends core.Plugin{constructor(_config={},_injector,_localeService){super(),this._config=_config,this._injector=_injector,this._localeService=_localeService,this._config=core.Tools.deepMerge({},DefaultFindReplaceConfig,this._config)}onStarting(){[[exports2.FindReplaceController,{useFactory:__name(()=>this._injector.createInstance(exports2.FindReplaceController,this._config),"useFactory")}],[IFindReplaceService,{useClass:FindReplaceService}]].forEach(d=>{this._injector.add(d)})}},__name(_d,"UniverFindReplacePlugin"),__publicField(_d,"pluginName",PLUGIN_NAME),_d),exports2.UniverFindReplacePlugin=__decorateClass([__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.Inject(core.LocaleService))],exports2.UniverFindReplacePlugin),exports2.FindBy=FindBy,exports2.FindDirection=FindDirection,exports2.FindModel=FindModel,exports2.FindScope=FindScope,exports2.GoToNextMatchOperation=GoToNextMatchOperation,exports2.GoToPreviousMatchOperation=GoToPreviousMatchOperation,exports2.IFindReplaceService=IFindReplaceService,exports2.OpenFindDialogOperation=OpenFindDialogOperation,exports2.OpenReplaceDialogOperation=OpenReplaceDialogOperation,exports2.ReplaceAllMatchesCommand=ReplaceAllMatchesCommand,exports2.ReplaceCurrentMatchCommand=ReplaceCurrentMatchCommand,Object.defineProperty(exports2,Symbol.toStringTag,{value:"Module"})});
9
+ */var f=require$$0,k=Symbol.for("react.element"),l=Symbol.for("react.fragment"),m=Object.prototype.hasOwnProperty,n=f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,p={key:!0,ref:!0,__self:!0,__source:!0};function q(c,a,g){var b,d={},e=null,h=null;g!==void 0&&(e=""+g),a.key!==void 0&&(e=""+a.key),a.ref!==void 0&&(h=a.ref);for(b in a)m.call(a,b)&&!p.hasOwnProperty(b)&&(d[b]=a[b]);if(c&&c.defaultProps)for(b in a=c.defaultProps,a)d[b]===void 0&&(d[b]=a[b]);return{$$typeof:k,type:c,key:e,ref:h,props:d,_owner:n.current}}__name(q,"q"),reactJsxRuntime_production_min.Fragment=l,reactJsxRuntime_production_min.jsx=q,reactJsxRuntime_production_min.jsxs=q,jsxRuntime.exports=reactJsxRuntime_production_min;var jsxRuntimeExports=jsxRuntime.exports;const ReplaceCurrentMatchCommand={id:"ui.command.replace-current-match",type:core.CommandType.COMMAND,handler:__name(accessor=>accessor.get(IFindReplaceService).replace(),"handler")},CONFIRM_REPLACE_ALL_ID="CONFIRM_REPLACE_ALL",ReplaceAllMatchesCommand={id:"ui.command.replace-all-matches",type:core.CommandType.COMMAND,handler:__name(async accessor=>{const confirmService=accessor.get(ui.IConfirmService),localeService=accessor.get(core.LocaleService),messageService=accessor.get(ui.IMessageService);if(!await confirmService.confirm({id:CONFIRM_REPLACE_ALL_ID,title:{title:localeService.t("find-replace.replace.confirm.title")},cancelText:localeService.t("button.cancel"),confirmText:localeService.t("button.confirm")}))return!1;const result=await accessor.get(IFindReplaceService).replaceAll(),{success,failure}=result;return failure>0?(success===0?messageService.show({type:design.MessageType.Error,content:localeService.t("find-replace.replace.all-failure")}):messageService.show({type:design.MessageType.Warning,content:localeService.t("find-replace.replace.partial-success",`${success}`,`${failure}`)}),!1):(messageService.show({type:design.MessageType.Success,content:localeService.t("find-replace.replace.all-success",`${success}`)}),!0)},"handler")};function SearchInput(props){const{findCompleted:findComplete,localeService,matchesCount,matchesPosition,findString,findReplaceService,onChange,...rest}=props,text=findComplete&&matchesCount===0?localeService.t("find-replace.dialog.no-result"):matchesCount===0?" ":void 0;return jsxRuntimeExports.jsx(design.InputWithSlot,{autoFocus:!0,placeholder:localeService.t("find-replace.dialog.find-placeholder"),slot:jsxRuntimeExports.jsx(design.Pager,{loop:!0,text,value:matchesPosition,total:matchesCount,onChange:__name(newIndex=>{matchesPosition===matchesCount&&newIndex===1?findReplaceService.moveToNextMatch():matchesPosition===1&&newIndex===matchesCount||newIndex<matchesPosition?findReplaceService.moveToPreviousMatch():findReplaceService.moveToNextMatch()},"onChange")}),value:findString,onChange:__name(value=>onChange==null?void 0:onChange(value),"onChange"),...rest})}__name(SearchInput,"SearchInput");const styles={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 useFindInputFocus(findReplaceService,ref){const focus=require$$0.useCallback(()=>{var _a2;(_a2=document.querySelector(".univer-find-input input"))==null||_a2.focus()},[]),selectHasFocus=require$$0.useCallback(()=>{const allInputs=document.querySelectorAll(".univer-find-replace-dialog-container .univer-select-selection-search-input");return Array.from(allInputs).some(input=>input===document.activeElement)},[]);return require$$0.useImperativeHandle(ref,()=>({focus,selectHasFocus})),require$$0.useEffect(()=>{const subscription=findReplaceService.focusSignal$.subscribe(()=>focus());return()=>subscription.unsubscribe()},[findReplaceService,focus]),{focus,selectHasFocus}}__name(useFindInputFocus,"useFindInputFocus");const FindDialog=require$$0.forwardRef(__name(function(_props,ref){const localeService=core.useDependency(core.LocaleService),findReplaceService=core.useDependency(IFindReplaceService),commandService=core.useDependency(core.ICommandService),state=ui.useObservable(findReplaceService.state$,void 0,!0),{findCompleted,findString,matchesCount,matchesPosition}=state,revealReplace=require$$0.useCallback(()=>{commandService.executeCommand(OpenReplaceDialogOperation.id)},[commandService]),onFindStringChange=require$$0.useCallback(findString2=>findReplaceService.changeFindString(findString2),[findReplaceService]);return useFindInputFocus(findReplaceService,ref),jsxRuntimeExports.jsxs(require$$0.Fragment,{children:[jsxRuntimeExports.jsx(SearchInput,{findCompleted,className:"univer-find-input",matchesCount,matchesPosition,findReplaceService,localeService,findString,onChange:onFindStringChange}),jsxRuntimeExports.jsx("div",{className:styles.findReplaceExpandContainer,children:jsxRuntimeExports.jsx(design.Button,{type:"text",size:"small",onClick:revealReplace,children:localeService.t("find-replace.dialog.advanced-finding")})})]})},"FindDialogImpl")),ReplaceDialog=require$$0.forwardRef(__name(function(_props,ref){const findReplaceService=core.useDependency(IFindReplaceService),localeService=core.useDependency(core.LocaleService),commandService=core.useDependency(core.ICommandService),messageService=core.useDependency(ui.IMessageService),currentMatch=ui.useObservable(findReplaceService.currentMatch$,void 0,!0),replaceables=ui.useObservable(findReplaceService.replaceables$,void 0,!0),state=ui.useObservable(findReplaceService.state$,void 0,!0),{matchesCount,matchesPosition,findString,inputtingFindString,replaceString,caseSensitive,matchesTheWholeCell,findDirection,findScope,findBy,findCompleted}=state,findDisabled=inputtingFindString.length===0,replaceDisabled=matchesCount===0||!(currentMatch!=null&&currentMatch.replaceable),replaceAllDisabled=replaceables.length===0,onFindStringChange=require$$0.useCallback(newValue=>findReplaceService.changeInputtingFindString(newValue),[findReplaceService]),onReplaceStringChange=require$$0.useCallback(replaceString2=>findReplaceService.changeReplaceString(replaceString2),[findReplaceService]),{focus}=useFindInputFocus(findReplaceService,ref),onClickFindButton=require$$0.useCallback(()=>{findString===inputtingFindString?findReplaceService.moveToNextMatch():(findReplaceService.changeFindString(inputtingFindString),findReplaceService.find())},[findString,inputtingFindString,findReplaceService]),onClickReplaceButton=require$$0.useCallback(()=>commandService.executeCommand(ReplaceCurrentMatchCommand.id),[commandService]),onClickReplaceAllButton=require$$0.useCallback(async()=>{await commandService.executeCommand(ReplaceAllMatchesCommand.id),focus()},[commandService]),onChangeFindDirection=require$$0.useCallback(findDirection2=>{findReplaceService.changeFindDirection(findDirection2)},[findReplaceService]),onChangeFindScope=require$$0.useCallback(findScope2=>{findReplaceService.changeFindScope(findScope2)},[findReplaceService]),onChangeFindBy=require$$0.useCallback(findBy2=>{findReplaceService.changeFindBy(findBy2)},[findReplaceService]),findScopeOptions=useFindScopeOptions(localeService),findDirectionOptions=useFindDirectionOptions(localeService),findByOptions=useFindByOptions(localeService);return require$$0.useEffect(()=>{const shouldDisplayNoMatchInfo=findCompleted&&matchesCount===0;let messageDisposable=null;return shouldDisplayNoMatchInfo&&(messageDisposable=messageService.show({content:localeService.t("find-replace.dialog.no-match"),type:design.MessageType.Warning,duration:5e3})),()=>messageDisposable==null?void 0:messageDisposable.dispose()},[findCompleted,matchesCount,messageService,localeService]),jsxRuntimeExports.jsxs(require$$0.Fragment,{children:[jsxRuntimeExports.jsx(design.FormLayout,{label:localeService.t("find-replace.dialog.find"),children:jsxRuntimeExports.jsx(SearchInput,{findCompleted,className:"univer-find-input",matchesCount,matchesPosition,findReplaceService,localeService,findString:inputtingFindString,onChange:onFindStringChange})}),jsxRuntimeExports.jsx(design.FormLayout,{label:localeService.t("find-replace.dialog.replace"),children:jsxRuntimeExports.jsx(design.Input,{placeholder:localeService.t("find-replace.dialog.replace-placeholder"),value:replaceString,onChange:__name(value=>onReplaceStringChange(value),"onChange")})}),jsxRuntimeExports.jsx(design.FormLayout,{label:localeService.t("find-replace.dialog.find-direction.title"),children:jsxRuntimeExports.jsx(design.Select,{value:findDirection,options:findDirectionOptions,onChange:onChangeFindDirection})}),jsxRuntimeExports.jsx(design.FormDualColumnLayout,{children:jsxRuntimeExports.jsxs(require$$0.Fragment,{children:[jsxRuntimeExports.jsx(design.FormLayout,{label:localeService.t("find-replace.dialog.find-scope.title"),children:jsxRuntimeExports.jsx(design.Select,{value:findScope,options:findScopeOptions,onChange:onChangeFindScope})}),jsxRuntimeExports.jsx(design.FormLayout,{label:localeService.t("find-replace.dialog.find-by.title"),children:jsxRuntimeExports.jsx(design.Select,{value:findBy,options:findByOptions,onChange:onChangeFindBy})})]})}),jsxRuntimeExports.jsx(design.FormDualColumnLayout,{children:jsxRuntimeExports.jsxs(require$$0.Fragment,{children:[jsxRuntimeExports.jsx(design.FormLayout,{children:jsxRuntimeExports.jsx(design.Checkbox,{checked:caseSensitive,onChange:__name(checked=>{findReplaceService.changeCaseSensitive(checked)},"onChange"),children:localeService.t("find-replace.dialog.case-sensitive")})}),jsxRuntimeExports.jsx(design.FormLayout,{children:jsxRuntimeExports.jsx(design.Checkbox,{checked:matchesTheWholeCell,onChange:__name(checked=>{findReplaceService.changeMatchesTheWholeCell(checked)},"onChange"),children:localeService.t("find-replace.dialog.match-the-whole-cell")})})]})}),jsxRuntimeExports.jsxs("div",{className:styles.findReplaceButtonsGroup,children:[jsxRuntimeExports.jsx(design.Button,{type:"primary",onClick:onClickFindButton,disabled:findDisabled,children:localeService.t("find-replace.dialog.find")}),jsxRuntimeExports.jsxs("span",{className:styles.findReplaceButtonsGroupRight,children:[jsxRuntimeExports.jsx(design.Button,{disabled:replaceDisabled,onClick:onClickReplaceButton,children:localeService.t("find-replace.dialog.replace")}),jsxRuntimeExports.jsx(design.Button,{disabled:replaceAllDisabled,onClick:onClickReplaceAllButton,children:localeService.t("find-replace.dialog.replace-all")})]})]})]})},"ReplaceDIalogImpl"));function FindReplaceDialog(){const findReplaceService=core.useDependency(IFindReplaceService),layoutService=core.useDependency(ui.ILayoutService),contextService=core.useDependency(core.IContextService),state=ui.useObservable(findReplaceService.state$,void 0,!0),dialogContainerRef=require$$0.useRef(null);require$$0.useEffect(()=>{let disposable;return dialogContainerRef.current&&(disposable=layoutService.registerContainerElement(dialogContainerRef.current)),()=>disposable==null?void 0:disposable.dispose()},[layoutService]);const focusRef=require$$0.useRef(null),setDialogContainerFocus=require$$0.useCallback(focused=>contextService.setContextValue(FIND_REPLACE_DIALOG_FOCUS,focused),[contextService]),setDialogInputFocus=require$$0.useCallback(focused=>contextService.setContextValue(FIND_REPLACE_INPUT_FOCUS,focused),[contextService]);return require$$0.useEffect(()=>{var _a2;const focusSubscription=rxjs.fromEvent(document,"focusin").subscribe(event=>{var _a3;event.target&&((_a3=dialogContainerRef.current)!=null&&_a3.contains(event.target))?setDialogContainerFocus(!0):setDialogContainerFocus(!1),!focusRef.current||!focusRef.current.selectHasFocus()?setDialogInputFocus(!0):setDialogInputFocus(!1)});return(_a2=focusRef.current)==null||_a2.focus(),setDialogContainerFocus(!0),setDialogInputFocus(!0),()=>{focusSubscription.unsubscribe(),setDialogContainerFocus(!1)}},[setDialogContainerFocus,setDialogInputFocus]),jsxRuntimeExports.jsx("div",{className:styles.findReplaceDialogContainer,ref:dialogContainerRef,children:state.replaceRevealed?jsxRuntimeExports.jsx(ReplaceDialog,{ref:focusRef}):jsxRuntimeExports.jsx(FindDialog,{ref:focusRef})})}__name(FindReplaceDialog,"FindReplaceDialog");function useFindScopeOptions(localeService){const locale=localeService.getCurrentLocale();return require$$0.useMemo(()=>[{label:localeService.t("find-replace.dialog.find-scope.current-sheet"),value:FindScope.SUBUNIT},{label:localeService.t("find-replace.dialog.find-scope.workbook"),value:FindScope.UNIT}],[locale])}__name(useFindScopeOptions,"useFindScopeOptions");function useFindDirectionOptions(localeService){const locale=localeService.getCurrentLocale();return require$$0.useMemo(()=>[{label:localeService.t("find-replace.dialog.find-direction.row"),value:FindDirection.ROW},{label:localeService.t("find-replace.dialog.find-direction.column"),value:FindDirection.COLUMN}],[locale])}__name(useFindDirectionOptions,"useFindDirectionOptions");function useFindByOptions(localeService){const locale=localeService.getCurrentLocale();return require$$0.useMemo(()=>[{label:localeService.t("find-replace.dialog.find-by.value"),value:FindBy.VALUE},{label:localeService.t("find-replace.dialog.find-by.formula"),value:FindBy.FORMULA}],[locale])}__name(useFindByOptions,"useFindByOptions");function whenFindReplaceDialogFocused(contextService){return contextService.getContextValue(FIND_REPLACE_DIALOG_FOCUS)}__name(whenFindReplaceDialogFocused,"whenFindReplaceDialogFocused");function whenReplaceRevealed(contextService){return contextService.getContextValue(FIND_REPLACE_REPLACE_REVEALED)}__name(whenReplaceRevealed,"whenReplaceRevealed");function whenFindReplaceInputFocused(contextService){return contextService.getContextValue(FIND_REPLACE_INPUT_FOCUS)}__name(whenFindReplaceInputFocused,"whenFindReplaceInputFocused");const FIND_REPLACE_SHORTCUT_GROUP="7_find-replace-shortcuts";function whenSheetFocused(contextService){return contextService.getContextValue(core.FOCUSING_SHEET)}__name(whenSheetFocused,"whenSheetFocused");function whenEditorNotActivated(contextService){return!contextService.getContextValue(core.EDITOR_ACTIVATED)}__name(whenEditorNotActivated,"whenEditorNotActivated");const OpenFindDialogShortcutItem={id:OpenFindDialogOperation.id,description:"find-replace.shortcut.open-find-dialog",binding:ui.KeyCode.F|ui.MetaKeys.CTRL_COMMAND,group:FIND_REPLACE_SHORTCUT_GROUP,preconditions(contextService){return!whenFindReplaceDialogFocused(contextService)&&whenSheetFocused(contextService)&&whenEditorNotActivated(contextService)}},MacOpenFindDialogShortcutItem={id:OpenFindDialogOperation.id,description:"find-replace.shortcut.open-find-dialog",binding:ui.KeyCode.F|ui.MetaKeys.CTRL_COMMAND,mac:ui.KeyCode.F|ui.MetaKeys.MAC_CTRL,preconditions(contextService){return!whenFindReplaceDialogFocused(contextService)&&whenSheetFocused(contextService)&&whenEditorNotActivated(contextService)}},OpenReplaceDialogShortcutItem={id:OpenReplaceDialogOperation.id,description:"find-replace.shortcut.open-replace-dialog",binding:ui.KeyCode.H|ui.MetaKeys.CTRL_COMMAND,mac:ui.KeyCode.H|ui.MetaKeys.MAC_CTRL,group:FIND_REPLACE_SHORTCUT_GROUP,preconditions(contextService){return whenSheetFocused(contextService)&&whenEditorNotActivated(contextService)&&(!whenFindReplaceDialogFocused(contextService)||!whenReplaceRevealed(contextService))}},GoToNextFindMatchShortcutItem={id:GoToNextMatchOperation.id,description:"find-replace.shortcut.go-to-next-match",binding:ui.KeyCode.ENTER,group:FIND_REPLACE_SHORTCUT_GROUP,priority:1e3,preconditions(contextService){return whenFindReplaceInputFocused(contextService)&&whenFindReplaceDialogFocused(contextService)}},GoToPreviousFindMatchShortcutItem={id:GoToPreviousMatchOperation.id,description:"find-replace.shortcut.go-to-previous-match",binding:ui.KeyCode.ENTER|ui.MetaKeys.SHIFT,group:FIND_REPLACE_SHORTCUT_GROUP,priority:1e3,preconditions(contextService){return whenFindReplaceInputFocused(contextService)&&whenFindReplaceDialogFocused(contextService)}};function FindReplaceMenuItemFactory(accessor){const contextService=accessor.get(core.IContextService);return{id:OpenFindDialogOperation.id,icon:"SearchIcon",tooltip:"find-replace.toolbar",group:ui.MenuGroup.TOOLBAR_OTHERS,type:ui.MenuItemType.BUTTON,positions:[ui.MenuPosition.TOOLBAR_START],hidden$:ui.getMenuHiddenObservable(accessor,core.UniverInstanceType.UNIVER_SHEET),disabled$:rxjs.combineLatest([contextService.subscribeContextValue$(core.EDITOR_ACTIVATED),contextService.subscribeContextValue$(core.FOCUSING_SHEET)]).pipe(rxjs.map(([editorActivated,focusingSheet])=>editorActivated||!focusingSheet))}}__name(FindReplaceMenuItemFactory,"FindReplaceMenuItemFactory");var __defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$1");const DefaultFindReplaceConfig={},FIND_REPLACE_DIALOG_ID="DESKTOP_FIND_REPLACE_DIALOG",FIND_REPLACE_PANEL_WIDTH=350,FIND_REPLACE_PANEL_RIGHT_PADDING=20,FIND_REPLACE_PANEL_TOP_PADDING=-90;exports2.FindReplaceController=(_c=class extends core.RxDisposable{constructor(_config,_univerInstanceService,_menuService,_shortcutService,_commandService,_findReplaceService,_dialogService,_layoutService,_localeService,_componentManager,_injector){super();__publicField(this,"_closingListenerDisposable");this._config=_config,this._univerInstanceService=_univerInstanceService,this._menuService=_menuService,this._shortcutService=_shortcutService,this._commandService=_commandService,this._findReplaceService=_findReplaceService,this._dialogService=_dialogService,this._layoutService=_layoutService,this._localeService=_localeService,this._componentManager=_componentManager,this._injector=_injector,this._initCommands(),this._initUI(),this._initShortcuts()}dispose(){var _a2;super.dispose(),(_a2=this._closingListenerDisposable)==null||_a2.dispose(),this._closingListenerDisposable=null}_initCommands(){[OpenFindDialogOperation,OpenReplaceDialogOperation,GoToNextMatchOperation,GoToPreviousMatchOperation,ReplaceAllMatchesCommand,ReplaceCurrentMatchCommand].forEach(c=>{this.disposeWithMe(this._commandService.registerCommand(c))})}_initShortcuts(){[OpenReplaceDialogShortcutItem,OpenFindDialogShortcutItem,MacOpenFindDialogShortcutItem,GoToPreviousFindMatchShortcutItem,GoToNextFindMatchShortcutItem].forEach(s=>this.disposeWithMe(this._shortcutService.registerShortcut(s)))}_initUI(){const{menu={}}=this._config;this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(FindReplaceMenuItemFactory),menu)),this.disposeWithMe(this._componentManager.register("FindReplaceDialog",FindReplaceDialog)),this.disposeWithMe(this._componentManager.register("SearchIcon",SearchSingle16)),this._findReplaceService.stateUpdates$.pipe(rxjs.takeUntil(this.dispose$)).subscribe(newState=>{newState.revealed===!0&&this._openPanel()})}_openPanel(){this._dialogService.open({id:FIND_REPLACE_DIALOG_ID,draggable:!0,width:FIND_REPLACE_PANEL_WIDTH,title:{title:this._localeService.t("find-replace.dialog.title")},children:{label:"FindReplaceDialog"},destroyOnClose:!0,defaultPosition:getFindReplaceDialogDefaultPosition(),preservePositionOnDestroy:!0,onClose:__name(()=>this.closePanel(),"onClose")}),this._closingListenerDisposable=core.toDisposable(this._univerInstanceService.focused$.pipe(rxjs.takeUntil(this.dispose$)).subscribe(focused=>{(!focused||!this._univerInstanceService.getUniverSheetInstance(focused))&&this.closePanel()}))}closePanel(){this._closingListenerDisposable&&(this._closingListenerDisposable.dispose(),this._closingListenerDisposable=null,this._dialogService.close(FIND_REPLACE_DIALOG_ID),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus()))}},__name(_c,"FindReplaceController"),_c),exports2.FindReplaceController=__decorateClass$1([core.OnLifecycle(core.LifecycleStages.Rendered,exports2.FindReplaceController),__decorateParam$1(1,core.IUniverInstanceService),__decorateParam$1(2,ui.IMenuService),__decorateParam$1(3,ui.IShortcutService),__decorateParam$1(4,core.ICommandService),__decorateParam$1(5,IFindReplaceService),__decorateParam$1(6,ui.IDialogService),__decorateParam$1(7,ui.ILayoutService),__decorateParam$1(8,core.Inject(core.LocaleService)),__decorateParam$1(9,core.Inject(ui.ComponentManager)),__decorateParam$1(10,core.Inject(core.Injector))],exports2.FindReplaceController);function getFindReplaceDialogDefaultPosition(){const{innerWidth}=window;return{x:(innerWidth-FIND_REPLACE_PANEL_WIDTH)/2-FIND_REPLACE_PANEL_RIGHT_PADDING,y:FIND_REPLACE_PANEL_TOP_PADDING}}__name(getFindReplaceDialogDefaultPosition,"getFindReplaceDialogDefaultPosition");var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam");const PLUGIN_NAME="FIND_REPLACE_PLUGIN";exports2.UniverFindReplacePlugin=(_d=class extends core.Plugin{constructor(_config={},_injector,_localeService){super(),this._config=_config,this._injector=_injector,this._localeService=_localeService,this._config=core.Tools.deepMerge({},DefaultFindReplaceConfig,this._config)}onStarting(){[[exports2.FindReplaceController,{useFactory:__name(()=>this._injector.createInstance(exports2.FindReplaceController,this._config),"useFactory")}],[IFindReplaceService,{useClass:FindReplaceService}]].forEach(d=>{this._injector.add(d)})}},__name(_d,"UniverFindReplacePlugin"),__publicField(_d,"pluginName",PLUGIN_NAME),_d),exports2.UniverFindReplacePlugin=__decorateClass([__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.Inject(core.LocaleService))],exports2.UniverFindReplacePlugin),exports2.FindBy=FindBy,exports2.FindDirection=FindDirection,exports2.FindModel=FindModel,exports2.FindScope=FindScope,exports2.GoToNextMatchOperation=GoToNextMatchOperation,exports2.GoToPreviousMatchOperation=GoToPreviousMatchOperation,exports2.IFindReplaceService=IFindReplaceService,exports2.OpenFindDialogOperation=OpenFindDialogOperation,exports2.OpenReplaceDialogOperation=OpenReplaceDialogOperation,exports2.ReplaceAllMatchesCommand=ReplaceAllMatchesCommand,exports2.ReplaceCurrentMatchCommand=ReplaceCurrentMatchCommand,Object.defineProperty(exports2,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/find-replace",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -52,13 +52,13 @@
52
52
  "peerDependencies": {
53
53
  "react": "^16.9.0 || ^17.0.0 || ^18.0.0",
54
54
  "rxjs": ">=7.0.0",
55
- "@univerjs/core": "0.2.6",
56
- "@univerjs/engine-render": "0.2.6",
57
- "@univerjs/ui": "0.2.6",
58
- "@univerjs/design": "0.2.6"
55
+ "@univerjs/design": "0.2.7",
56
+ "@univerjs/core": "0.2.7",
57
+ "@univerjs/ui": "0.2.7",
58
+ "@univerjs/engine-render": "0.2.7"
59
59
  },
60
60
  "dependencies": {
61
- "@univerjs/icons": "^0.1.70"
61
+ "@univerjs/icons": "^0.1.72"
62
62
  },
63
63
  "devDependencies": {
64
64
  "@types/react": "^18.3.3",
@@ -67,13 +67,13 @@
67
67
  "rxjs": "^7.8.1",
68
68
  "typescript": "^5.5.4",
69
69
  "vite": "^5.3.5",
70
- "vitest": "^2.0.4",
71
- "@univerjs/core": "0.2.6",
72
- "@univerjs/design": "0.2.6",
73
- "@univerjs/engine-formula": "0.2.6",
74
- "@univerjs/shared": "0.2.6",
75
- "@univerjs/engine-render": "0.2.6",
76
- "@univerjs/ui": "0.2.6"
70
+ "vitest": "^2.0.5",
71
+ "@univerjs/core": "0.2.7",
72
+ "@univerjs/design": "0.2.7",
73
+ "@univerjs/engine-formula": "0.2.7",
74
+ "@univerjs/engine-render": "0.2.7",
75
+ "@univerjs/shared": "0.2.7",
76
+ "@univerjs/ui": "0.2.7"
77
77
  },
78
78
  "univerSpace": {
79
79
  ".": {