@univerjs/find-replace 0.20.1 → 0.21.0-insiders.20260422-d7fcb4d
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 +1322 -1
- package/lib/cjs/locale/ca-ES.js +52 -1
- package/lib/cjs/locale/en-US.js +67 -1
- package/lib/cjs/locale/es-ES.js +52 -1
- package/lib/cjs/locale/fa-IR.js +52 -1
- package/lib/cjs/locale/fr-FR.js +52 -1
- package/lib/cjs/locale/ja-JP.js +52 -1
- package/lib/cjs/locale/ko-KR.js +52 -1
- package/lib/cjs/locale/ru-RU.js +52 -1
- package/lib/cjs/locale/sk-SK.js +52 -1
- package/lib/cjs/locale/vi-VN.js +52 -1
- package/lib/cjs/locale/zh-CN.js +52 -1
- package/lib/cjs/locale/zh-TW.js +52 -1
- package/lib/es/index.js +1291 -1
- package/lib/es/locale/ca-ES.js +51 -1
- package/lib/es/locale/en-US.js +66 -1
- package/lib/es/locale/es-ES.js +51 -1
- package/lib/es/locale/fa-IR.js +51 -1
- package/lib/es/locale/fr-FR.js +51 -1
- package/lib/es/locale/ja-JP.js +51 -1
- package/lib/es/locale/ko-KR.js +51 -1
- package/lib/es/locale/ru-RU.js +51 -1
- package/lib/es/locale/sk-SK.js +51 -1
- package/lib/es/locale/vi-VN.js +51 -1
- package/lib/es/locale/zh-CN.js +51 -1
- package/lib/es/locale/zh-TW.js +51 -1
- package/lib/index.js +1291 -1
- package/lib/locale/ca-ES.js +51 -1
- package/lib/locale/en-US.js +66 -1
- package/lib/locale/es-ES.js +51 -1
- package/lib/locale/fa-IR.js +51 -1
- package/lib/locale/fr-FR.js +51 -1
- package/lib/locale/ja-JP.js +51 -1
- package/lib/locale/ko-KR.js +51 -1
- package/lib/locale/ru-RU.js +51 -1
- package/lib/locale/sk-SK.js +51 -1
- package/lib/locale/vi-VN.js +51 -1
- package/lib/locale/zh-CN.js +51 -1
- package/lib/locale/zh-TW.js +51 -1
- package/lib/umd/index.js +1 -1
- package/package.json +8 -8
- package/LICENSE +0 -176
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1,1322 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/core`),t=require(`@univerjs/design`),n=require(`@univerjs/ui`),r=require(`@univerjs/engine-render`),i=require(`rxjs`),a=require(`@univerjs/icons`),o=require(`react`),s=require(`react/jsx-runtime`);const c=`FIND_REPLACE_INPUT_FOCUS`,l=`FIND_REPLACE_DIALOG_FOCUS`,u=`FIND_REPLACE_REPLACE_REVEALED`;function d(e){"@babel/helpers - typeof";return d=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},d(e)}function f(e,t){if(d(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(d(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function p(e){var t=f(e,`string`);return d(t)==`symbol`?t:t+``}function m(e,t,n){return(t=p(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function h(e,t){return function(n,r){t(n,r,e)}}function g(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}var _=class extends e.Disposable{};const v=(0,e.createIdentifier)(`find-replace.service`);function y(e){return e.findString!==void 0||e.inputtingFindString!==void 0||e.findDirection!==void 0||e.matchesTheWholeCell!==void 0||e.caseSensitive!==void 0||e.findScope!==void 0||e.findBy!==void 0}let b=class extends e.Disposable{get searched(){return this._findModels.length>0}constructor(e,t,n,r){super(),this._state=e,this._providers=t,this._univerInstanceService=n,this._commandService=r,m(this,`currentMatch$`,new i.BehaviorSubject(null)),m(this,`replaceables$`,new i.BehaviorSubject([])),m(this,`_findModels`,[]),m(this,`_matchingModel`,null),m(this,`_matches`,[]),m(this,`_currentSearchingDisposables`,null),this.disposeWithMe(this._state.stateUpdates$.pipe((0,i.throttleTime)(200,void 0,{leading:!0,trailing:!0})).subscribe(async e=>{let t=this._state.state;y(e)&&(t.findString!==``&&!t.replaceRevealed?(await this._startSearching(),this._state.changeState({findCompleted:!0})):e.replaceRevealed!==!0&&this._stopSearching())}))}dispose(){super.dispose(),this._stopSearching(),this.currentMatch$.complete(),this.replaceables$.complete(),this._state.changeState({...w(),revealed:!1})}async start(){if(!this._state.findString)return{results:[]};let e=await this._startSearching();return this._state.changeState({findCompleted:!0}),e}focusSelection(){var e;(e=this._matchingModel)==null||e.focusSelection()}async _startSearching(){if(!this._state.findString)return{results:[]};let e=Array.from(this._providers),t=this._findModels=(await Promise.all(e.map(e=>e.find({findString:this._state.findString,findDirection:this._state.findDirection,findScope:this._state.findScope,findBy:this._state.findBy,replaceRevealed:this._state.replaceRevealed,caseSensitive:this._state.caseSensitive,matchesTheWholeCell:this._state.matchesTheWholeCell})))).flat();this._subscribeToModelsChanges(t);let n=this._matches=t.map(e=>e.getMatches()).flat();return this.replaceables$.next(n.filter(e=>e.replaceable)),n.length?(this._moveToInitialMatch(t),this._state.changeState({matchesCount:n.length}),{results:n}):(this._state.changeState({matchesCount:0,matchesPosition:0}),{results:[]})}_stopSearching(){var e;this._providers.forEach(e=>e.terminate()),this._findModels=[],this._matches=[],this._matchingModel=null,(e=this._currentSearchingDisposables)==null||e.dispose(),this._currentSearchingDisposables=null,this.currentMatch$.next(null),this.replaceables$.next([]),this._state.changeState({findCompleted:!1,matchesCount:0,matchesPosition:0})}_subscribeToModelsChanges(t){let n=this._currentSearchingDisposables=new e.DisposableCollection,r=(0,i.combineLatest)(t.map(e=>e.matchesUpdate$)).pipe((0,i.debounceTime)(220)).subscribe(([...e])=>{let t=this._matches=e.flat();t.length?(this._moveToInitialMatch(this._findModels,!0),this._state.changeState({matchesCount:t.length}),this.replaceables$.next(t.filter(e=>e.replaceable))):(this._state.changeState({matchesCount:0,matchesPosition:0}),this.replaceables$.next([]))});t.forEach(t=>n.add((0,e.toDisposable)(t.activelyChangingMatch$.subscribe(e=>{let t=this._matches.findIndex(t=>t===e);this._state.changeState({matchesPosition:t+1})})))),n.add((0,e.toDisposable)(r))}async replace(){return this._matchingModel?this._matchingModel.replace(this._state.replaceString):!1}async replaceAll(){let e=await Promise.all(this._findModels.map(e=>e.replaceAll(this._state.replaceString))).then(e=>e.reduce((e,t)=>(e.success+=t.success,e.failure+=t.failure,e),{success:0,failure:0}));return e.failure===0&&this._stopSearching(),e}getCurrentMatch(){return this._state.matchesPosition>0?this._matches[this._state.matchesPosition-1]:null}_markMatch(e){let t=this._matches.findIndex(t=>t===e);this.currentMatch$.next(e),this._state.changeState({matchesPosition:t+1})}moveToNextMatch(){if(!this._matchingModel)return;let e=this._findModels.length===1,t=this._matchingModel.moveToNextMatch({loop:e});if(t)return this._markMatch(t),t;{let e=this._findModels.findIndex(e=>e===this._matchingModel);return this._moveToNextUnitMatch(e)}}_moveToNextUnitMatch(e){let t=this._findModels.length;for(let n=(e+1)%t;n!==e;){let e=this._findModels[n],r=e.moveToNextMatch({ignoreSelection:!0});if(r)return this._matchingModel=e,this._markMatch(r),r;n=(n+1)%t}if(this._matchingModel){let e=this._matchingModel.moveToNextMatch({ignoreSelection:!0});return e&&this._markMatch(e),e}}moveToPreviousMatch(){if(!this._matchingModel)return;let e=this._findModels.length===1,t=this._matchingModel.moveToPreviousMatch({loop:e});if(t){let e=this._matches.findIndex(e=>e===t);return this.currentMatch$.next(t),this._state.changeState({matchesPosition:e+1}),t}else{let e=this._findModels.length,t=this._findModels.findIndex(e=>e===this._matchingModel);for(let n=(t-1+e)%e;n!==t;){let t=this._findModels[n],r=t.moveToPreviousMatch({ignoreSelection:!0});if(r)return this._matchingModel=t,this._markMatch(r),r;n=(n-1)%e}let n=this._matchingModel.moveToPreviousMatch({ignoreSelection:!0});return n&&this._markMatch(n),n}}_moveToInitialMatch(e,t=!1){var n;let r=(n=this._univerInstanceService.getFocusedUnit())==null?void 0:n.getUnitId();if(!r)return-1;let i=e.findIndex(e=>e.unitId===r);if(i!==-1){this._matchingModel=e[i];let n=this._matchingModel.moveToNextMatch({stayIfOnMatch:!0,noFocus:t});if(n)return this._markMatch(n),i}return this._moveToNextUnitMatch(i),0}};b=g([h(2,e.IUniverInstanceService),h(3,e.ICommandService)],b);let x=function(e){return e.ROW=`row`,e.COLUMN=`column`,e}({}),S=function(e){return e.VALUE=`value`,e.FORMULA=`formula`,e}({}),C=function(e){return e.SUBUNIT=`subunit`,e.UNIT=`unit`,e}({});function w(){return{caseSensitive:!1,findBy:S.VALUE,findCompleted:!1,findDirection:x.ROW,findScope:C.SUBUNIT,findString:``,inputtingFindString:``,matchesCount:0,matchesPosition:0,matchesTheWholeCell:!1,replaceRevealed:!1,replaceString:``,revealed:!0}}var T=class{constructor(){m(this,`_stateUpdates$`,new i.Subject),m(this,`stateUpdates$`,this._stateUpdates$.asObservable()),m(this,`_state$`,new i.BehaviorSubject(w())),m(this,`state$`,this._state$.asObservable()),m(this,`_findString`,``),m(this,`_inputtingFindString`,``),m(this,`_replaceString`,``),m(this,`_revealed`,!1),m(this,`_replaceRevealed`,!1),m(this,`_matchesPosition`,0),m(this,`_matchesCount`,0),m(this,`_caseSensitive`,!0),m(this,`_matchesTheWholeCell`,!1),m(this,`_findDirection`,x.ROW),m(this,`_findScope`,C.SUBUNIT),m(this,`_findBy`,S.VALUE),m(this,`_findCompleted`,!1)}get state(){return this._state$.getValue()}get inputtingFindString(){return this._inputtingFindString}get findString(){return this._findString}get revealed(){return this._revealed}get replaceRevealed(){return this._replaceRevealed}get matchesPosition(){return this._matchesPosition}get matchesCount(){return this._matchesCount}get replaceString(){return this._replaceString}get caseSensitive(){return this._caseSensitive}get matchesTheWholeCell(){return this._matchesTheWholeCell}get findDirection(){return this._findDirection}get findScope(){return this._findScope}get findBy(){return this._findBy}get findCompleted(){return this._findCompleted}changeState(e){let t=!1,n={};e.findString!==void 0&&e.findString!==this._findString&&(this._findString=e.findString,n.findString=this._findString,t=!0),e.revealed!==void 0&&e.revealed!==this._revealed&&(this._revealed=e.revealed,n.revealed=e.revealed,t=!0),e.replaceRevealed!==void 0&&e.replaceRevealed!==this._replaceRevealed&&(this._replaceRevealed=e.replaceRevealed,n.replaceRevealed=e.replaceRevealed,t=!0),e.replaceString!==void 0&&e.replaceString!==this._replaceString&&(this._replaceString=e.replaceString,n.replaceString=e.replaceString,t=!0),e.matchesCount!==void 0&&e.matchesCount!==this._matchesCount&&(this._matchesCount=e.matchesCount,n.matchesCount=e.matchesCount,t=!0),e.matchesPosition!==void 0&&e.matchesPosition!==this._matchesPosition&&(this._matchesPosition=e.matchesPosition,n.matchesPosition=e.matchesPosition,t=!0),e.findBy!==void 0&&e.findBy!==this._findBy&&(this._findBy=e.findBy,n.findBy=e.findBy,t=!0),e.findScope!==void 0&&e.findScope!==this._findScope&&(this._findScope=e.findScope,n.findScope=e.findScope,t=!0),e.findDirection!==void 0&&e.findDirection!==this._findDirection&&(this._findDirection=e.findDirection,n.findDirection=e.findDirection,t=!0),e.caseSensitive!==void 0&&e.caseSensitive!==this._caseSensitive&&(this._caseSensitive=e.caseSensitive,n.caseSensitive=e.caseSensitive,t=!0),e.matchesTheWholeCell!==void 0&&e.matchesTheWholeCell!==this._matchesTheWholeCell&&(this._matchesTheWholeCell=e.matchesTheWholeCell,n.matchesTheWholeCell=e.matchesTheWholeCell,t=!0),e.inputtingFindString!==void 0&&e.inputtingFindString!==this._inputtingFindString&&(this._inputtingFindString=e.inputtingFindString,n.inputtingFindString=e.inputtingFindString,t=!0),e.findCompleted!==void 0&&e.findCompleted!==this._findCompleted&&(this._findCompleted=e.findCompleted,n.findCompleted=e.findCompleted,t=!0),t&&(this._state$.next({caseSensitive:this._caseSensitive,findBy:this._findBy,findCompleted:this._findCompleted,findDirection:this._findDirection,findScope:this._findScope,findString:this._findString,inputtingFindString:this._inputtingFindString,matchesCount:this._matchesCount,matchesPosition:this._matchesPosition,matchesTheWholeCell:this._matchesTheWholeCell,replaceRevealed:this._replaceRevealed,revealed:this._revealed}),this._stateUpdates$.next(n))}};let E=class extends e.Disposable{get stateUpdates$(){return this._state.stateUpdates$}get state$(){return this._state.state$}get revealed(){return this._state.revealed}get replaceRevealed(){return this._state.replaceRevealed}constructor(e,t){super(),this._injector=e,this._contextService=t,m(this,`_providers`,new Set),m(this,`_state`,new T),m(this,`_model`,void 0),m(this,`_currentMatch$`,new i.BehaviorSubject(null)),m(this,`currentMatch$`,this._currentMatch$.asObservable()),m(this,`_replaceables$`,new i.BehaviorSubject([])),m(this,`replaceables$`,this._replaceables$.asObservable()),m(this,`_focusSignal$`,new i.Subject),m(this,`focusSignal$`,this._focusSignal$.asObservable())}dispose(){super.dispose(),this._currentMatch$.next(null),this._currentMatch$.complete(),this._replaceables$.next([]),this._replaceables$.complete(),this._focusSignal$.complete()}getProviders(){return this._providers}getCurrentMatch(){var e;return(e=this._model)==null?void 0:e.getCurrentMatch()}getFindString(){return this._state.findString}changeFindString(e){this._state.changeState({findString:e})}focusFindInput(){this._focusSignal$.next()}changeInputtingFindString(e){e?this._state.changeState({inputtingFindString:e}):this._state.changeState({inputtingFindString:``,findString:``})}changeReplaceString(e){this._state.changeState({replaceString:e})}changeMatchesTheWholeCell(e){this._state.changeState({matchesTheWholeCell:e})}changeCaseSensitive(e){this._state.changeState({caseSensitive:e})}changeFindBy(e){this._state.changeState({findBy:e}),this._toggleDisplayRawFormula(e===S.FORMULA)}changeFindScope(e){this._state.changeState({findScope:e})}changeFindDirection(e){this._state.changeState({findDirection:e})}moveToNextMatch(){this._model&&(this._state.replaceRevealed&&!this._model.searched?(this._state.changeState({findString:this._state.inputtingFindString}),this._model.start()):this._model.moveToNextMatch(),this._focusSignal$.next())}moveToPreviousMatch(){this._model&&(this._state.replaceRevealed&&!this._model.searched?(this._state.changeState({findString:this._state.inputtingFindString}),this._model.start()):this._model.moveToPreviousMatch(),this._focusSignal$.next())}async replace(){return this._model?this._model.replace():!1}async replaceAll(){if(!this._model)throw Error(`[FindReplaceService] replaceAll: model is not initialized!`);return this._model.replaceAll()}revealReplace(){this._state.changeState({replaceRevealed:!0,inputtingFindString:this._state.findString}),this._toggleRevealReplace(!0)}focusSelection(){var e;(e=this._model)==null||e.focusSelection()}start(e=!1){if(this._providers.size===0)return!1;this._model=this._injector.createInstance(b,this._state,this._providers),this._model.currentMatch$.subscribe(e=>this._currentMatch$.next(e)),this._model.replaceables$.subscribe(e=>this._replaceables$.next(e));let t=w();return e&&(t.replaceRevealed=!0),this._state.changeState(t),this._toggleRevealReplace(e),!0}find(){var e;(e=this._model)==null||e.start()}terminate(){var e;(e=this._model)==null||e.dispose(),this._model=null,this._toggleDisplayRawFormula(!1),this._toggleRevealReplace(!1)}registerFindReplaceProvider(t){return this._providers.add(t),(0,e.toDisposable)(()=>this._providers.delete(t))}_toggleRevealReplace(e){this._contextService.setContextValue(u,e)}_toggleDisplayRawFormula(e){this._contextService.setContextValue(r.RENDER_RAW_FORMULA_KEY,e)}};E=g([h(0,(0,e.Inject)(e.Injector)),h(1,e.IContextService)],E);const D={id:`ui.command.replace-current-match`,type:e.CommandType.COMMAND,handler:e=>e.get(v).replace()},O={id:`ui.command.replace-all-matches`,type:e.CommandType.COMMAND,handler:async r=>{let i=r.get(e.IConfirmService),a=r.get(e.LocaleService),o=r.get(n.IMessageService);if(!await i.confirm({id:`CONFIRM_REPLACE_ALL`,title:{title:a.t(`find-replace.replace.confirm.title`)},cancelText:a.t(`button.cancel`),confirmText:a.t(`button.confirm`)}))return!1;let{success:s,failure:c}=await r.get(v).replaceAll();return c>0?(s===0?o.show({type:t.MessageType.Error,content:a.t(`find-replace.replace.all-failure`)}):o.show({type:t.MessageType.Warning,content:a.t(`find-replace.replace.partial-success`,`${s}`,`${c}`)}),!1):(o.show({type:t.MessageType.Success,content:a.t(`find-replace.replace.all-success`,`${s}`)}),!0)}},k={id:`ui.operation.open-find-dialog`,type:e.CommandType.OPERATION,handler:e=>{let t=e.get(v);return t.revealed?t.focusFindInput():t.start(),!0}},A={id:`ui.operation.open-replace-dialog`,type:e.CommandType.OPERATION,handler:e=>{let t=e.get(v);return t.revealed?t.replaceRevealed?t.focusFindInput():t.revealReplace():t.start(!0),!0}},j={type:e.CommandType.OPERATION,id:`ui.operation.go-to-next-match`,handler:e=>(e.get(v).moveToNextMatch(),!0)},M={type:e.CommandType.OPERATION,id:`ui.operation.go-to-previous-match`,handler:e=>(e.get(v).moveToPreviousMatch(),!0)},N={type:e.CommandType.OPERATION,id:`ui.operation.focus-selection`,handler:e=>(e.get(v).focusSelection(),!0)};function P(t){let r=t.get(e.IContextService);return{id:k.id,icon:`SearchIcon`,tooltip:`find-replace.toolbar`,type:n.MenuItemType.BUTTON,hidden$:(0,n.getMenuHiddenObservable)(t,e.UniverInstanceType.UNIVER_SHEET),disabled$:(0,i.combineLatest)([r.subscribeContextValue$(e.EDITOR_ACTIVATED),r.subscribeContextValue$(e.FOCUSING_SHEET)]).pipe((0,i.map)(([e,t])=>e||!t))}}const F={[n.RibbonDataGroup.ORGANIZATION]:{[k.id]:{order:2,menuItemFactory:P}}};function I(e){let{findCompleted:n,localeService:r,matchesCount:i,matchesPosition:a,initialFindString:c,findReplaceService:l,onChange:u,...d}=e,[f,p]=(0,o.useState)(c),m=n&&i===0?r.t(`find-replace.dialog.no-result`):i===0?` `:void 0;function h(e){a===i&&e===1?l.moveToNextMatch():a===1&&e===i||e<a?l.moveToPreviousMatch():l.moveToNextMatch()}return(0,s.jsx)(`div`,{className:`univer-relative univer-flex univer-items-center univer-gap-2`,onDrag:e=>e.stopPropagation(),children:(0,s.jsx)(t.Input,{"data-u-comp":`search-input`,autoFocus:!0,placeholder:r.t(`find-replace.dialog.find-placeholder`),value:f,onChange:e=>{p(e),u==null||u(e)},slot:(0,s.jsx)(t.Pager,{loop:!0,text:m,value:a,total:i,onChange:h}),...d})})}function L(e,t){let n=(0,o.useCallback)(()=>{var e;(e=document.querySelector(`.univer-find-input input`))==null||e.focus()},[]),r=(0,o.useCallback)(()=>{let e=document.querySelectorAll(`[data-u-comp=find-replace-dialog] [data-u-comp=search-input]`);return Array.from(e).some(e=>e===document.activeElement)},[]);return(0,o.useImperativeHandle)(t,()=>({focus:n,selectHasFocus:r})),(0,o.useEffect)(()=>{let t=e.focusSignal$.subscribe(()=>n());return()=>t.unsubscribe()},[e,n]),{focus:n,selectHasFocus:r}}const R=(0,o.forwardRef)(function(t,r){let i=(0,n.useDependency)(e.LocaleService),a=(0,n.useDependency)(v),c=(0,n.useDependency)(e.ICommandService),{findCompleted:l,findString:u,matchesCount:d,matchesPosition:f}=(0,n.useObservable)(a.state$,void 0,!0),p=(0,o.useCallback)(()=>{c.executeCommand(A.id)},[c]),m=(0,n.useDebounceFn)(e=>a.changeFindString(e),500);return L(a,r),(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(I,{findCompleted:l,matchesCount:d,matchesPosition:f,findReplaceService:a,localeService:i,initialFindString:u,onChange:m}),(0,s.jsx)(`div`,{className:`univer-mt-4 univer-text-center`,children:(0,s.jsx)(`a`,{className:`hover:univer-text-primary-500/80 univer-cursor-pointer univer-text-sm univer-text-primary-500 univer-transition-colors`,onClick:p,children:i.t(`find-replace.dialog.advanced-finding`)})})]})}),z=(0,o.forwardRef)(function(r,i){let a=(0,n.useDependency)(v),c=(0,n.useDependency)(e.LocaleService),l=(0,n.useDependency)(e.ICommandService),u=(0,n.useDependency)(n.IMessageService),d=(0,n.useObservable)(a.currentMatch$,void 0,!0),f=(0,n.useObservable)(a.replaceables$,void 0,!0),{matchesCount:p,matchesPosition:m,findString:h,inputtingFindString:g,replaceString:_,caseSensitive:y,matchesTheWholeCell:b,findDirection:x,findScope:S,findBy:C,findCompleted:w}=(0,n.useObservable)(a.state$,void 0,!0),T=g.length===0,E=p===0||!(d!=null&&d.replaceable),k=f.length===0,A=(0,o.useCallback)(e=>a.changeInputtingFindString(e),[a]),j=(0,o.useCallback)(e=>a.changeReplaceString(e),[a]),{focus:M}=L(a,i),N=(0,o.useCallback)(()=>{h===g?a.moveToNextMatch():(a.changeFindString(g),a.find())},[h,g,a]),P=(0,o.useCallback)(()=>l.executeCommand(D.id),[l]),F=(0,o.useCallback)(async()=>{await l.executeCommand(O.id),M()},[l]),R=(0,o.useCallback)(e=>{a.changeFindDirection(e)},[a]),z=(0,o.useCallback)(e=>{a.changeFindScope(e)},[a]),B=(0,o.useCallback)(e=>{a.changeFindBy(e)},[a]),U=V(c),W=H(c),G=ee(c);return(0,o.useEffect)(()=>{w&&p===0&&u.show({content:c.t(`find-replace.dialog.no-match`),type:t.MessageType.Warning,duration:5e3})},[w,p,u,c]),(0,s.jsxs)(`div`,{children:[(0,s.jsx)(t.FormLayout,{label:c.t(`find-replace.dialog.find`),children:(0,s.jsx)(I,{findCompleted:w,className:`univer-find-input`,matchesCount:p,matchesPosition:m,findReplaceService:a,localeService:c,initialFindString:g,onChange:A})}),(0,s.jsx)(t.FormLayout,{label:c.t(`find-replace.dialog.replace`),children:(0,s.jsx)(t.Input,{placeholder:c.t(`find-replace.dialog.replace-placeholder`),value:_,onChange:e=>j(e)})}),(0,s.jsx)(t.FormLayout,{label:c.t(`find-replace.dialog.find-direction.title`),children:(0,s.jsx)(t.Select,{value:x,options:W,onChange:R})}),(0,s.jsx)(t.FormDualColumnLayout,{children:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.FormLayout,{label:c.t(`find-replace.dialog.find-scope.title`),children:(0,s.jsx)(t.Select,{value:S,options:U,onChange:z})}),(0,s.jsx)(t.FormLayout,{label:c.t(`find-replace.dialog.find-by.title`),children:(0,s.jsx)(t.Select,{value:C,options:G,onChange:B})})]})}),(0,s.jsx)(t.FormDualColumnLayout,{children:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.FormLayout,{children:(0,s.jsx)(t.Checkbox,{checked:y,onChange:e=>{a.changeCaseSensitive(e)},children:c.t(`find-replace.dialog.case-sensitive`)})}),(0,s.jsx)(t.FormLayout,{children:(0,s.jsx)(t.Checkbox,{checked:b,onChange:e=>{a.changeMatchesTheWholeCell(e)},children:c.t(`find-replace.dialog.match-the-whole-cell`)})})]})}),(0,s.jsxs)(`div`,{className:`univer-mt-6 univer-flex univer-justify-between`,children:[(0,s.jsx)(t.Button,{variant:`primary`,onClick:N,disabled:T,children:c.t(`find-replace.dialog.find`)}),(0,s.jsxs)(`span`,{className:`univer-inline-flex univer-gap-2`,children:[(0,s.jsx)(t.Button,{disabled:E,onClick:P,children:c.t(`find-replace.dialog.replace`)}),(0,s.jsx)(t.Button,{disabled:k,onClick:F,children:c.t(`find-replace.dialog.replace-all`)})]})]})]})});function B(){let t=(0,n.useDependency)(v),r=(0,n.useDependency)(n.ILayoutService),a=(0,n.useDependency)(e.IContextService),u=(0,n.useObservable)(t.state$,void 0,!0),d=(0,o.useRef)(null);(0,o.useEffect)(()=>{let e;return d.current&&(e=r.registerContainerElement(d.current)),()=>e==null?void 0:e.dispose()},[r]);let f=(0,o.useRef)(null),p=(0,o.useCallback)(e=>a.setContextValue(l,e),[a]),m=(0,o.useCallback)(e=>a.setContextValue(c,e),[a]);return(0,o.useEffect)(()=>{var e;let t=(0,i.fromEvent)(document,`focusin`).subscribe(e=>{var t;e.target&&(t=d.current)!=null&&t.contains(e.target)?p(!0):p(!1),!f.current||!f.current.selectHasFocus()?m(!1):m(!0)});return(e=f.current)==null||e.focus(),p(!0),m(!0),()=>{t.unsubscribe(),p(!1)}},[p,m]),(0,s.jsx)(`div`,{ref:d,"data-u-comp":`find-replace-dialog`,children:u.replaceRevealed?(0,s.jsx)(z,{ref:f}):(0,s.jsx)(R,{ref:f})})}function V(e){return(0,o.useMemo)(()=>[{label:e.t(`find-replace.dialog.find-scope.current-sheet`),value:C.SUBUNIT},{label:e.t(`find-replace.dialog.find-scope.workbook`),value:C.UNIT}],[e.getCurrentLocale()])}function H(e){return(0,o.useMemo)(()=>[{label:e.t(`find-replace.dialog.find-direction.row`),value:x.ROW},{label:e.t(`find-replace.dialog.find-direction.column`),value:x.COLUMN}],[e.getCurrentLocale()])}function ee(e){return(0,o.useMemo)(()=>[{label:e.t(`find-replace.dialog.find-by.value`),value:S.VALUE},{label:e.t(`find-replace.dialog.find-by.formula`),value:S.FORMULA}],[e.getCurrentLocale()])}function U(e){return e.getContextValue(l)}function W(e){return e.getContextValue(u)}function G(e){return e.getContextValue(c)}const K=`7_find-replace-shortcuts`;function q(t){return t.getContextValue(e.FOCUSING_SHEET)}function J(t){return!t.getContextValue(e.EDITOR_ACTIVATED)}const te={id:k.id,description:`find-replace.shortcut.open-find-dialog`,binding:n.KeyCode.F|n.MetaKeys.CTRL_COMMAND,group:K,preconditions(e){return!U(e)&&q(e)&&J(e)}},ne={id:k.id,description:`find-replace.shortcut.open-find-dialog`,binding:n.KeyCode.F|n.MetaKeys.CTRL_COMMAND,mac:n.KeyCode.F|n.MetaKeys.MAC_CTRL,preconditions(e){return!U(e)&&q(e)&&J(e)}},re={id:A.id,description:`find-replace.shortcut.open-replace-dialog`,binding:n.KeyCode.H|n.MetaKeys.CTRL_COMMAND,mac:n.KeyCode.H|n.MetaKeys.MAC_CTRL,group:K,preconditions(e){return q(e)&&J(e)&&(!U(e)||!W(e))}},ie={id:j.id,description:`find-replace.shortcut.go-to-next-match`,binding:n.KeyCode.ENTER,group:K,priority:1e3,preconditions(e){return G(e)&&U(e)}},ae={id:M.id,description:`find-replace.shortcut.go-to-previous-match`,binding:n.KeyCode.ENTER|n.MetaKeys.SHIFT,group:K,priority:1e3,preconditions(e){return G(e)&&U(e)}},oe={id:N.id,description:`find-replace.shortcut.focus-selection`,binding:n.KeyCode.ESC,group:K,priority:1e3,preconditions(e){return U(e)}},Y=`DESKTOP_FIND_REPLACE_DIALOG`;let X=class extends e.RxDisposable{constructor(e,t,n,r,i,a,o,s,c){super(),this._univerInstanceService=e,this._menuManagerService=t,this._shortcutService=n,this._commandService=r,this._findReplaceService=i,this._dialogService=a,this._layoutService=o,this._localeService=s,this._componentManager=c,m(this,`_closingListenerDisposable`,void 0),this._initCommands(),this._initUI(),this._initShortcuts()}dispose(){var e;super.dispose(),(e=this._closingListenerDisposable)==null||e.dispose(),this._closingListenerDisposable=null}_initCommands(){[k,A,j,M,O,D,N].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initShortcuts(){[re,te,ne,ae,ie,oe].forEach(e=>this.disposeWithMe(this._shortcutService.registerShortcut(e)))}_initUI(){[[`FindReplaceDialog`,B],[`SearchIcon`,a.SearchIcon]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))}),this._menuManagerService.mergeMenu(F),this._findReplaceService.stateUpdates$.pipe((0,i.takeUntil)(this.dispose$)).subscribe(e=>{e.revealed===!0&&this._openPanel()})}_openPanel(){this._dialogService.open({id:Y,draggable:!0,width:350,title:{title:this._localeService.t(`find-replace.dialog.title`)},children:{label:`FindReplaceDialog`},destroyOnClose:!0,mask:!1,maskClosable:!1,defaultPosition:se(),preservePositionOnDestroy:!0,onClose:()=>this.closePanel()}),this._closingListenerDisposable=(0,e.toDisposable)(this._univerInstanceService.focused$.pipe((0,i.takeUntil)(this.dispose$)).subscribe(e=>{(!e||!this._univerInstanceService.getUniverSheetInstance(e))&&this.closePanel()}))}closePanel(){this._closingListenerDisposable&&(this._closingListenerDisposable.dispose(),this._closingListenerDisposable=null,this._dialogService.close(Y),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus()))}};X=g([h(0,e.IUniverInstanceService),h(1,n.IMenuManagerService),h(2,n.IShortcutService),h(3,e.ICommandService),h(4,v),h(5,n.IDialogService),h(6,n.ILayoutService),h(7,(0,e.Inject)(e.LocaleService)),h(8,(0,e.Inject)(n.ComponentManager))],X);function se(){let{innerWidth:e}=window;return{x:e-350-20,y:64}}var ce=`@univerjs/find-replace`,le=`0.20.1`;const Z=`find-replace.config`;Symbol(Z);const Q={};let $=class extends e.Plugin{constructor(t=Q,n,r){super(),this._config=t,this._injector=n,this._configService=r;let{...i}=(0,e.merge)({},Q,this._config);this._configService.setConfig(Z,i)}onStarting(){[[X],[v,{useClass:E}]].forEach(e=>this._injector.add(e))}onRendered(){this._injector.get(X)}};m($,`pluginName`,`UNIVER_FIND_REPLACE_PLUGIN`),m($,`packageName`,ce),m($,`version`,le),$=g([h(1,(0,e.Inject)(e.Injector)),h(2,e.IConfigService)],$),exports.FindBy=S,exports.FindDirection=x,exports.FindModel=_,Object.defineProperty(exports,`FindReplaceController`,{enumerable:!0,get:function(){return X}}),Object.defineProperty(exports,`FindReplaceModel`,{enumerable:!0,get:function(){return b}}),exports.FindReplaceState=T,exports.FindScope=C,exports.GoToNextMatchOperation=j,exports.GoToPreviousMatchOperation=M,exports.IFindReplaceService=v,exports.OpenFindDialogOperation=k,exports.OpenReplaceDialogOperation=A,exports.ReplaceAllMatchesCommand=O,exports.ReplaceCurrentMatchCommand=D,Object.defineProperty(exports,`UniverFindReplacePlugin`,{enumerable:!0,get:function(){return $}}),exports.createInitFindReplaceState=w;
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let _univerjs_core = require("@univerjs/core");
|
|
3
|
+
let _univerjs_design = require("@univerjs/design");
|
|
4
|
+
let _univerjs_ui = require("@univerjs/ui");
|
|
5
|
+
let _univerjs_engine_render = require("@univerjs/engine-render");
|
|
6
|
+
let rxjs = require("rxjs");
|
|
7
|
+
let _univerjs_icons = require("@univerjs/icons");
|
|
8
|
+
let react = require("react");
|
|
9
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
10
|
+
|
|
11
|
+
//#region src/services/context-keys.ts
|
|
12
|
+
/**
|
|
13
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
14
|
+
*
|
|
15
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
16
|
+
* you may not use this file except in compliance with the License.
|
|
17
|
+
* You may obtain a copy of the License at
|
|
18
|
+
*
|
|
19
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
20
|
+
*
|
|
21
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
22
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
23
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
24
|
+
* See the License for the specific language governing permissions and
|
|
25
|
+
* limitations under the License.
|
|
26
|
+
*/
|
|
27
|
+
const FIND_REPLACE_INPUT_FOCUS = "FIND_REPLACE_INPUT_FOCUS";
|
|
28
|
+
/**
|
|
29
|
+
* If find replace panel is focused.
|
|
30
|
+
*/
|
|
31
|
+
const FIND_REPLACE_DIALOG_FOCUS = "FIND_REPLACE_DIALOG_FOCUS";
|
|
32
|
+
/**
|
|
33
|
+
* If the find replace feature is activated and the replace is revealed.
|
|
34
|
+
*/
|
|
35
|
+
const FIND_REPLACE_REPLACE_REVEALED = "FIND_REPLACE_REPLACE_REVEALED";
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
|
|
39
|
+
function _typeof(o) {
|
|
40
|
+
"@babel/helpers - typeof";
|
|
41
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
42
|
+
return typeof o;
|
|
43
|
+
} : function(o) {
|
|
44
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
45
|
+
}, _typeof(o);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
|
|
50
|
+
function toPrimitive(t, r) {
|
|
51
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
52
|
+
var e = t[Symbol.toPrimitive];
|
|
53
|
+
if (void 0 !== e) {
|
|
54
|
+
var i = e.call(t, r || "default");
|
|
55
|
+
if ("object" != _typeof(i)) return i;
|
|
56
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
57
|
+
}
|
|
58
|
+
return ("string" === r ? String : Number)(t);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
|
|
63
|
+
function toPropertyKey(t) {
|
|
64
|
+
var i = toPrimitive(t, "string");
|
|
65
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
|
|
70
|
+
function _defineProperty(e, r, t) {
|
|
71
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
72
|
+
value: t,
|
|
73
|
+
enumerable: !0,
|
|
74
|
+
configurable: !0,
|
|
75
|
+
writable: !0
|
|
76
|
+
}) : e[r] = t, e;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
|
|
81
|
+
function __decorateParam(paramIndex, decorator) {
|
|
82
|
+
return function(target, key) {
|
|
83
|
+
decorator(target, key, paramIndex);
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
|
|
89
|
+
function __decorate(decorators, target, key, desc) {
|
|
90
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
91
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
92
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
93
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region src/services/find-replace.service.ts
|
|
98
|
+
var FindModel = class extends _univerjs_core.Disposable {};
|
|
99
|
+
const IFindReplaceService = (0, _univerjs_core.createIdentifier)("find-replace.service");
|
|
100
|
+
/**
|
|
101
|
+
*
|
|
102
|
+
* @param statusUpdate
|
|
103
|
+
*/
|
|
104
|
+
function shouldStateUpdateTriggerResearch(statusUpdate) {
|
|
105
|
+
if (typeof statusUpdate.findString !== "undefined") return true;
|
|
106
|
+
if (typeof statusUpdate.inputtingFindString !== "undefined") return true;
|
|
107
|
+
if (typeof statusUpdate.findDirection !== "undefined") return true;
|
|
108
|
+
if (typeof statusUpdate.matchesTheWholeCell !== "undefined") return true;
|
|
109
|
+
if (typeof statusUpdate.caseSensitive !== "undefined") return true;
|
|
110
|
+
if (typeof statusUpdate.findScope !== "undefined") return true;
|
|
111
|
+
if (typeof statusUpdate.findBy !== "undefined") return true;
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
let FindReplaceModel = class FindReplaceModel extends _univerjs_core.Disposable {
|
|
115
|
+
get searched() {
|
|
116
|
+
return this._findModels.length > 0;
|
|
117
|
+
}
|
|
118
|
+
constructor(_state, _providers, _univerInstanceService, _commandService) {
|
|
119
|
+
super();
|
|
120
|
+
this._state = _state;
|
|
121
|
+
this._providers = _providers;
|
|
122
|
+
this._univerInstanceService = _univerInstanceService;
|
|
123
|
+
this._commandService = _commandService;
|
|
124
|
+
_defineProperty(this, "currentMatch$", new rxjs.BehaviorSubject(null));
|
|
125
|
+
_defineProperty(this, "replaceables$", new rxjs.BehaviorSubject([]));
|
|
126
|
+
_defineProperty(this, "_findModels", []);
|
|
127
|
+
_defineProperty(this, "_matchingModel", null);
|
|
128
|
+
_defineProperty(this, "_matches", []);
|
|
129
|
+
_defineProperty(this, "_currentSearchingDisposables", null);
|
|
130
|
+
this.disposeWithMe(this._state.stateUpdates$.pipe((0, rxjs.throttleTime)(200, void 0, {
|
|
131
|
+
leading: true,
|
|
132
|
+
trailing: true
|
|
133
|
+
})).subscribe(async (stateUpdate) => {
|
|
134
|
+
const state = this._state.state;
|
|
135
|
+
if (shouldStateUpdateTriggerResearch(stateUpdate)) {
|
|
136
|
+
if (state.findString !== "" && !state.replaceRevealed) {
|
|
137
|
+
await this._startSearching();
|
|
138
|
+
this._state.changeState({ findCompleted: true });
|
|
139
|
+
} else if (stateUpdate.replaceRevealed !== true) this._stopSearching();
|
|
140
|
+
}
|
|
141
|
+
}));
|
|
142
|
+
}
|
|
143
|
+
dispose() {
|
|
144
|
+
super.dispose();
|
|
145
|
+
this._stopSearching();
|
|
146
|
+
this.currentMatch$.complete();
|
|
147
|
+
this.replaceables$.complete();
|
|
148
|
+
this._state.changeState({
|
|
149
|
+
...createInitFindReplaceState(),
|
|
150
|
+
revealed: false
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
async start() {
|
|
154
|
+
if (!this._state.findString) return { results: [] };
|
|
155
|
+
const complete = await this._startSearching();
|
|
156
|
+
this._state.changeState({ findCompleted: true });
|
|
157
|
+
return complete;
|
|
158
|
+
}
|
|
159
|
+
focusSelection() {
|
|
160
|
+
var _this$_matchingModel;
|
|
161
|
+
(_this$_matchingModel = this._matchingModel) === null || _this$_matchingModel === void 0 || _this$_matchingModel.focusSelection();
|
|
162
|
+
}
|
|
163
|
+
/** Call this method to start a `searching`. */
|
|
164
|
+
async _startSearching() {
|
|
165
|
+
if (!this._state.findString) return { results: [] };
|
|
166
|
+
const providers = Array.from(this._providers);
|
|
167
|
+
const findModels = this._findModels = (await Promise.all(providers.map((provider) => provider.find({
|
|
168
|
+
findString: this._state.findString,
|
|
169
|
+
findDirection: this._state.findDirection,
|
|
170
|
+
findScope: this._state.findScope,
|
|
171
|
+
findBy: this._state.findBy,
|
|
172
|
+
replaceRevealed: this._state.replaceRevealed,
|
|
173
|
+
caseSensitive: this._state.caseSensitive,
|
|
174
|
+
matchesTheWholeCell: this._state.matchesTheWholeCell
|
|
175
|
+
})))).flat();
|
|
176
|
+
this._subscribeToModelsChanges(findModels);
|
|
177
|
+
const newMatches = this._matches = findModels.map((c) => c.getMatches()).flat();
|
|
178
|
+
this.replaceables$.next(newMatches.filter((m) => m.replaceable));
|
|
179
|
+
if (!newMatches.length) {
|
|
180
|
+
this._state.changeState({
|
|
181
|
+
matchesCount: 0,
|
|
182
|
+
matchesPosition: 0
|
|
183
|
+
});
|
|
184
|
+
return { results: [] };
|
|
185
|
+
}
|
|
186
|
+
this._moveToInitialMatch(findModels);
|
|
187
|
+
this._state.changeState({ matchesCount: newMatches.length });
|
|
188
|
+
return { results: newMatches };
|
|
189
|
+
}
|
|
190
|
+
/** Terminate the current searching session, when searching string is empty. */
|
|
191
|
+
_stopSearching() {
|
|
192
|
+
var _this$_currentSearchi;
|
|
193
|
+
this._providers.forEach((provider) => provider.terminate());
|
|
194
|
+
this._findModels = [];
|
|
195
|
+
this._matches = [];
|
|
196
|
+
this._matchingModel = null;
|
|
197
|
+
(_this$_currentSearchi = this._currentSearchingDisposables) === null || _this$_currentSearchi === void 0 || _this$_currentSearchi.dispose();
|
|
198
|
+
this._currentSearchingDisposables = null;
|
|
199
|
+
this.currentMatch$.next(null);
|
|
200
|
+
this.replaceables$.next([]);
|
|
201
|
+
this._state.changeState({
|
|
202
|
+
findCompleted: false,
|
|
203
|
+
matchesCount: 0,
|
|
204
|
+
matchesPosition: 0
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
_subscribeToModelsChanges(models) {
|
|
208
|
+
const disposables = this._currentSearchingDisposables = new _univerjs_core.DisposableCollection();
|
|
209
|
+
const matchesUpdateSubscription = (0, rxjs.combineLatest)(models.map((model) => model.matchesUpdate$)).pipe((0, rxjs.debounceTime)(220)).subscribe(([ ...allMatches]) => {
|
|
210
|
+
const newMatches = this._matches = allMatches.flat();
|
|
211
|
+
if (newMatches.length) {
|
|
212
|
+
this._moveToInitialMatch(this._findModels, true);
|
|
213
|
+
this._state.changeState({ matchesCount: newMatches.length });
|
|
214
|
+
this.replaceables$.next(newMatches.filter((m) => m.replaceable));
|
|
215
|
+
} else {
|
|
216
|
+
this._state.changeState({
|
|
217
|
+
matchesCount: 0,
|
|
218
|
+
matchesPosition: 0
|
|
219
|
+
});
|
|
220
|
+
this.replaceables$.next([]);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
models.forEach((model) => disposables.add((0, _univerjs_core.toDisposable)(model.activelyChangingMatch$.subscribe((match) => {
|
|
224
|
+
const index = this._matches.findIndex((m) => m === match);
|
|
225
|
+
this._state.changeState({ matchesPosition: index + 1 });
|
|
226
|
+
}))));
|
|
227
|
+
disposables.add((0, _univerjs_core.toDisposable)(matchesUpdateSubscription));
|
|
228
|
+
}
|
|
229
|
+
async replace() {
|
|
230
|
+
if (!this._matchingModel) return false;
|
|
231
|
+
return this._matchingModel.replace(this._state.replaceString);
|
|
232
|
+
}
|
|
233
|
+
async replaceAll() {
|
|
234
|
+
const result = await Promise.all(this._findModels.map((m) => m.replaceAll(this._state.replaceString))).then((results) => results.reduce((acc, cur) => {
|
|
235
|
+
acc.success += cur.success;
|
|
236
|
+
acc.failure += cur.failure;
|
|
237
|
+
return acc;
|
|
238
|
+
}, {
|
|
239
|
+
success: 0,
|
|
240
|
+
failure: 0
|
|
241
|
+
}));
|
|
242
|
+
if (result.failure === 0) this._stopSearching();
|
|
243
|
+
return result;
|
|
244
|
+
}
|
|
245
|
+
getCurrentMatch() {
|
|
246
|
+
return this._state.matchesPosition > 0 ? this._matches[this._state.matchesPosition - 1] : null;
|
|
247
|
+
}
|
|
248
|
+
_markMatch(match) {
|
|
249
|
+
const index = this._matches.findIndex((value) => value === match);
|
|
250
|
+
this.currentMatch$.next(match);
|
|
251
|
+
this._state.changeState({ matchesPosition: index + 1 });
|
|
252
|
+
}
|
|
253
|
+
moveToNextMatch() {
|
|
254
|
+
if (!this._matchingModel) return;
|
|
255
|
+
const loopInCurrentUnit = this._findModels.length === 1;
|
|
256
|
+
const nextMatch = this._matchingModel.moveToNextMatch({ loop: loopInCurrentUnit });
|
|
257
|
+
if (nextMatch) {
|
|
258
|
+
this._markMatch(nextMatch);
|
|
259
|
+
return nextMatch;
|
|
260
|
+
} else {
|
|
261
|
+
const currentModelIndex = this._findModels.findIndex((m) => m === this._matchingModel);
|
|
262
|
+
return this._moveToNextUnitMatch(currentModelIndex);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
_moveToNextUnitMatch(startingIndex) {
|
|
266
|
+
const l = this._findModels.length;
|
|
267
|
+
for (let i = (startingIndex + 1) % l; i !== startingIndex;) {
|
|
268
|
+
const nextPositionModel = this._findModels[i];
|
|
269
|
+
const nextMatch = nextPositionModel.moveToNextMatch({ ignoreSelection: true });
|
|
270
|
+
if (nextMatch) {
|
|
271
|
+
this._matchingModel = nextPositionModel;
|
|
272
|
+
this._markMatch(nextMatch);
|
|
273
|
+
return nextMatch;
|
|
274
|
+
}
|
|
275
|
+
i = (i + 1) % l;
|
|
276
|
+
}
|
|
277
|
+
if (this._matchingModel) {
|
|
278
|
+
const nextMatch = this._matchingModel.moveToNextMatch({ ignoreSelection: true });
|
|
279
|
+
if (nextMatch) this._markMatch(nextMatch);
|
|
280
|
+
return nextMatch;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
moveToPreviousMatch() {
|
|
284
|
+
if (!this._matchingModel) return;
|
|
285
|
+
const loopInCurrentUnit = this._findModels.length === 1;
|
|
286
|
+
const nextMatch = this._matchingModel.moveToPreviousMatch({ loop: loopInCurrentUnit });
|
|
287
|
+
if (nextMatch) {
|
|
288
|
+
const index = this._matches.findIndex((value) => value === nextMatch);
|
|
289
|
+
this.currentMatch$.next(nextMatch);
|
|
290
|
+
this._state.changeState({ matchesPosition: index + 1 });
|
|
291
|
+
return nextMatch;
|
|
292
|
+
} else {
|
|
293
|
+
const l = this._findModels.length;
|
|
294
|
+
const currentModelIndex = this._findModels.findIndex((m) => m === this._matchingModel);
|
|
295
|
+
for (let i = (currentModelIndex - 1 + l) % l; i !== currentModelIndex;) {
|
|
296
|
+
const nextPositionModel = this._findModels[i];
|
|
297
|
+
const nextMatch = nextPositionModel.moveToPreviousMatch({ ignoreSelection: true });
|
|
298
|
+
if (nextMatch) {
|
|
299
|
+
this._matchingModel = nextPositionModel;
|
|
300
|
+
this._markMatch(nextMatch);
|
|
301
|
+
return nextMatch;
|
|
302
|
+
}
|
|
303
|
+
i = (i - 1) % l;
|
|
304
|
+
}
|
|
305
|
+
const nextMatch = this._matchingModel.moveToPreviousMatch({ ignoreSelection: true });
|
|
306
|
+
if (nextMatch) this._markMatch(nextMatch);
|
|
307
|
+
return nextMatch;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
_moveToInitialMatch(findModels, noFocus = false) {
|
|
311
|
+
var _this$_univerInstance;
|
|
312
|
+
const focusedUnitId = (_this$_univerInstance = this._univerInstanceService.getFocusedUnit()) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getUnitId();
|
|
313
|
+
if (!focusedUnitId) return -1;
|
|
314
|
+
const i = findModels.findIndex((model) => model.unitId === focusedUnitId);
|
|
315
|
+
if (i !== -1) {
|
|
316
|
+
this._matchingModel = findModels[i];
|
|
317
|
+
const nextMatch = this._matchingModel.moveToNextMatch({
|
|
318
|
+
stayIfOnMatch: true,
|
|
319
|
+
noFocus
|
|
320
|
+
});
|
|
321
|
+
if (nextMatch) {
|
|
322
|
+
this._markMatch(nextMatch);
|
|
323
|
+
return i;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
this._moveToNextUnitMatch(i);
|
|
327
|
+
return 0;
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
FindReplaceModel = __decorate([__decorateParam(2, _univerjs_core.IUniverInstanceService), __decorateParam(3, _univerjs_core.ICommandService)], FindReplaceModel);
|
|
331
|
+
let FindDirection = /* @__PURE__ */ function(FindDirection) {
|
|
332
|
+
/** Default. */
|
|
333
|
+
FindDirection["ROW"] = "row";
|
|
334
|
+
FindDirection["COLUMN"] = "column";
|
|
335
|
+
return FindDirection;
|
|
336
|
+
}({});
|
|
337
|
+
let FindBy = /* @__PURE__ */ function(FindBy) {
|
|
338
|
+
FindBy["VALUE"] = "value";
|
|
339
|
+
FindBy["FORMULA"] = "formula";
|
|
340
|
+
return FindBy;
|
|
341
|
+
}({});
|
|
342
|
+
let FindScope = /* @__PURE__ */ function(FindScope) {
|
|
343
|
+
/** Default. */
|
|
344
|
+
FindScope["SUBUNIT"] = "subunit";
|
|
345
|
+
/** Find the scope in the current unit. */
|
|
346
|
+
FindScope["UNIT"] = "unit";
|
|
347
|
+
return FindScope;
|
|
348
|
+
}({});
|
|
349
|
+
function createInitFindReplaceState() {
|
|
350
|
+
return {
|
|
351
|
+
caseSensitive: false,
|
|
352
|
+
findBy: FindBy.VALUE,
|
|
353
|
+
findCompleted: false,
|
|
354
|
+
findDirection: FindDirection.ROW,
|
|
355
|
+
findScope: FindScope.SUBUNIT,
|
|
356
|
+
findString: "",
|
|
357
|
+
inputtingFindString: "",
|
|
358
|
+
matchesCount: 0,
|
|
359
|
+
matchesPosition: 0,
|
|
360
|
+
matchesTheWholeCell: false,
|
|
361
|
+
replaceRevealed: false,
|
|
362
|
+
replaceString: "",
|
|
363
|
+
revealed: true
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* This class stores find replace options state. These state are stored
|
|
368
|
+
* here instead of the React component so we can change state from
|
|
369
|
+
* operations.
|
|
370
|
+
*/
|
|
371
|
+
var FindReplaceState = class {
|
|
372
|
+
constructor() {
|
|
373
|
+
_defineProperty(this, "_stateUpdates$", new rxjs.Subject());
|
|
374
|
+
_defineProperty(this, "stateUpdates$", this._stateUpdates$.asObservable());
|
|
375
|
+
_defineProperty(this, "_state$", new rxjs.BehaviorSubject(createInitFindReplaceState()));
|
|
376
|
+
_defineProperty(this, "state$", this._state$.asObservable());
|
|
377
|
+
_defineProperty(this, "_findString", "");
|
|
378
|
+
_defineProperty(this, "_inputtingFindString", "");
|
|
379
|
+
_defineProperty(this, "_replaceString", "");
|
|
380
|
+
_defineProperty(this, "_revealed", false);
|
|
381
|
+
_defineProperty(this, "_replaceRevealed", false);
|
|
382
|
+
_defineProperty(this, "_matchesPosition", 0);
|
|
383
|
+
_defineProperty(this, "_matchesCount", 0);
|
|
384
|
+
_defineProperty(this, "_caseSensitive", true);
|
|
385
|
+
_defineProperty(this, "_matchesTheWholeCell", false);
|
|
386
|
+
_defineProperty(this, "_findDirection", FindDirection.ROW);
|
|
387
|
+
_defineProperty(this, "_findScope", FindScope.SUBUNIT);
|
|
388
|
+
_defineProperty(this, "_findBy", FindBy.VALUE);
|
|
389
|
+
_defineProperty(this, "_findCompleted", false);
|
|
390
|
+
}
|
|
391
|
+
get state() {
|
|
392
|
+
return this._state$.getValue();
|
|
393
|
+
}
|
|
394
|
+
get inputtingFindString() {
|
|
395
|
+
return this._inputtingFindString;
|
|
396
|
+
}
|
|
397
|
+
get findString() {
|
|
398
|
+
return this._findString;
|
|
399
|
+
}
|
|
400
|
+
get revealed() {
|
|
401
|
+
return this._revealed;
|
|
402
|
+
}
|
|
403
|
+
get replaceRevealed() {
|
|
404
|
+
return this._replaceRevealed;
|
|
405
|
+
}
|
|
406
|
+
get matchesPosition() {
|
|
407
|
+
return this._matchesPosition;
|
|
408
|
+
}
|
|
409
|
+
get matchesCount() {
|
|
410
|
+
return this._matchesCount;
|
|
411
|
+
}
|
|
412
|
+
get replaceString() {
|
|
413
|
+
return this._replaceString;
|
|
414
|
+
}
|
|
415
|
+
get caseSensitive() {
|
|
416
|
+
return this._caseSensitive;
|
|
417
|
+
}
|
|
418
|
+
get matchesTheWholeCell() {
|
|
419
|
+
return this._matchesTheWholeCell;
|
|
420
|
+
}
|
|
421
|
+
get findDirection() {
|
|
422
|
+
return this._findDirection;
|
|
423
|
+
}
|
|
424
|
+
get findScope() {
|
|
425
|
+
return this._findScope;
|
|
426
|
+
}
|
|
427
|
+
get findBy() {
|
|
428
|
+
return this._findBy;
|
|
429
|
+
}
|
|
430
|
+
get findCompleted() {
|
|
431
|
+
return this._findCompleted;
|
|
432
|
+
}
|
|
433
|
+
changeState(changes) {
|
|
434
|
+
let changed = false;
|
|
435
|
+
const changedState = {};
|
|
436
|
+
if (typeof changes.findString !== "undefined" && changes.findString !== this._findString) {
|
|
437
|
+
this._findString = changes.findString;
|
|
438
|
+
changedState.findString = this._findString;
|
|
439
|
+
changed = true;
|
|
440
|
+
}
|
|
441
|
+
if (typeof changes.revealed !== "undefined" && changes.revealed !== this._revealed) {
|
|
442
|
+
this._revealed = changes.revealed;
|
|
443
|
+
changedState.revealed = changes.revealed;
|
|
444
|
+
changed = true;
|
|
445
|
+
}
|
|
446
|
+
if (typeof changes.replaceRevealed !== "undefined" && changes.replaceRevealed !== this._replaceRevealed) {
|
|
447
|
+
this._replaceRevealed = changes.replaceRevealed;
|
|
448
|
+
changedState.replaceRevealed = changes.replaceRevealed;
|
|
449
|
+
changed = true;
|
|
450
|
+
}
|
|
451
|
+
if (typeof changes.replaceString !== "undefined" && changes.replaceString !== this._replaceString) {
|
|
452
|
+
this._replaceString = changes.replaceString;
|
|
453
|
+
changedState.replaceString = changes.replaceString;
|
|
454
|
+
changed = true;
|
|
455
|
+
}
|
|
456
|
+
if (typeof changes.matchesCount !== "undefined" && changes.matchesCount !== this._matchesCount) {
|
|
457
|
+
this._matchesCount = changes.matchesCount;
|
|
458
|
+
changedState.matchesCount = changes.matchesCount;
|
|
459
|
+
changed = true;
|
|
460
|
+
}
|
|
461
|
+
if (typeof changes.matchesPosition !== "undefined" && changes.matchesPosition !== this._matchesPosition) {
|
|
462
|
+
this._matchesPosition = changes.matchesPosition;
|
|
463
|
+
changedState.matchesPosition = changes.matchesPosition;
|
|
464
|
+
changed = true;
|
|
465
|
+
}
|
|
466
|
+
if (typeof changes.findBy !== "undefined" && changes.findBy !== this._findBy) {
|
|
467
|
+
this._findBy = changes.findBy;
|
|
468
|
+
changedState.findBy = changes.findBy;
|
|
469
|
+
changed = true;
|
|
470
|
+
}
|
|
471
|
+
if (typeof changes.findScope !== "undefined" && changes.findScope !== this._findScope) {
|
|
472
|
+
this._findScope = changes.findScope;
|
|
473
|
+
changedState.findScope = changes.findScope;
|
|
474
|
+
changed = true;
|
|
475
|
+
}
|
|
476
|
+
if (typeof changes.findDirection !== "undefined" && changes.findDirection !== this._findDirection) {
|
|
477
|
+
this._findDirection = changes.findDirection;
|
|
478
|
+
changedState.findDirection = changes.findDirection;
|
|
479
|
+
changed = true;
|
|
480
|
+
}
|
|
481
|
+
if (typeof changes.caseSensitive !== "undefined" && changes.caseSensitive !== this._caseSensitive) {
|
|
482
|
+
this._caseSensitive = changes.caseSensitive;
|
|
483
|
+
changedState.caseSensitive = changes.caseSensitive;
|
|
484
|
+
changed = true;
|
|
485
|
+
}
|
|
486
|
+
if (typeof changes.matchesTheWholeCell !== "undefined" && changes.matchesTheWholeCell !== this._matchesTheWholeCell) {
|
|
487
|
+
this._matchesTheWholeCell = changes.matchesTheWholeCell;
|
|
488
|
+
changedState.matchesTheWholeCell = changes.matchesTheWholeCell;
|
|
489
|
+
changed = true;
|
|
490
|
+
}
|
|
491
|
+
if (typeof changes.inputtingFindString !== "undefined" && changes.inputtingFindString !== this._inputtingFindString) {
|
|
492
|
+
this._inputtingFindString = changes.inputtingFindString;
|
|
493
|
+
changedState.inputtingFindString = changes.inputtingFindString;
|
|
494
|
+
changed = true;
|
|
495
|
+
}
|
|
496
|
+
if (typeof changes.findCompleted !== "undefined" && changes.findCompleted !== this._findCompleted) {
|
|
497
|
+
this._findCompleted = changes.findCompleted;
|
|
498
|
+
changedState.findCompleted = changes.findCompleted;
|
|
499
|
+
changed = true;
|
|
500
|
+
}
|
|
501
|
+
if (changed) {
|
|
502
|
+
this._state$.next({
|
|
503
|
+
caseSensitive: this._caseSensitive,
|
|
504
|
+
findBy: this._findBy,
|
|
505
|
+
findCompleted: this._findCompleted,
|
|
506
|
+
findDirection: this._findDirection,
|
|
507
|
+
findScope: this._findScope,
|
|
508
|
+
findString: this._findString,
|
|
509
|
+
inputtingFindString: this._inputtingFindString,
|
|
510
|
+
matchesCount: this._matchesCount,
|
|
511
|
+
matchesPosition: this._matchesPosition,
|
|
512
|
+
matchesTheWholeCell: this._matchesTheWholeCell,
|
|
513
|
+
replaceRevealed: this._replaceRevealed,
|
|
514
|
+
revealed: this._revealed
|
|
515
|
+
});
|
|
516
|
+
this._stateUpdates$.next(changedState);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
let FindReplaceService = class FindReplaceService extends _univerjs_core.Disposable {
|
|
521
|
+
get stateUpdates$() {
|
|
522
|
+
return this._state.stateUpdates$;
|
|
523
|
+
}
|
|
524
|
+
get state$() {
|
|
525
|
+
return this._state.state$;
|
|
526
|
+
}
|
|
527
|
+
get revealed() {
|
|
528
|
+
return this._state.revealed;
|
|
529
|
+
}
|
|
530
|
+
get replaceRevealed() {
|
|
531
|
+
return this._state.replaceRevealed;
|
|
532
|
+
}
|
|
533
|
+
constructor(_injector, _contextService) {
|
|
534
|
+
super();
|
|
535
|
+
this._injector = _injector;
|
|
536
|
+
this._contextService = _contextService;
|
|
537
|
+
_defineProperty(this, "_providers", /* @__PURE__ */ new Set());
|
|
538
|
+
_defineProperty(this, "_state", new FindReplaceState());
|
|
539
|
+
_defineProperty(this, "_model", void 0);
|
|
540
|
+
_defineProperty(this, "_currentMatch$", new rxjs.BehaviorSubject(null));
|
|
541
|
+
_defineProperty(this, "currentMatch$", this._currentMatch$.asObservable());
|
|
542
|
+
_defineProperty(this, "_replaceables$", new rxjs.BehaviorSubject([]));
|
|
543
|
+
_defineProperty(this, "replaceables$", this._replaceables$.asObservable());
|
|
544
|
+
_defineProperty(this, "_focusSignal$", new rxjs.Subject());
|
|
545
|
+
_defineProperty(this, "focusSignal$", this._focusSignal$.asObservable());
|
|
546
|
+
}
|
|
547
|
+
dispose() {
|
|
548
|
+
super.dispose();
|
|
549
|
+
this._currentMatch$.next(null);
|
|
550
|
+
this._currentMatch$.complete();
|
|
551
|
+
this._replaceables$.next([]);
|
|
552
|
+
this._replaceables$.complete();
|
|
553
|
+
this._focusSignal$.complete();
|
|
554
|
+
}
|
|
555
|
+
getProviders() {
|
|
556
|
+
return this._providers;
|
|
557
|
+
}
|
|
558
|
+
getCurrentMatch() {
|
|
559
|
+
var _this$_model;
|
|
560
|
+
return (_this$_model = this._model) === null || _this$_model === void 0 ? void 0 : _this$_model.getCurrentMatch();
|
|
561
|
+
}
|
|
562
|
+
getFindString() {
|
|
563
|
+
return this._state.findString;
|
|
564
|
+
}
|
|
565
|
+
changeFindString(findString) {
|
|
566
|
+
this._state.changeState({ findString });
|
|
567
|
+
}
|
|
568
|
+
focusFindInput() {
|
|
569
|
+
this._focusSignal$.next();
|
|
570
|
+
}
|
|
571
|
+
changeInputtingFindString(value) {
|
|
572
|
+
if (value) this._state.changeState({ inputtingFindString: value });
|
|
573
|
+
else this._state.changeState({
|
|
574
|
+
inputtingFindString: "",
|
|
575
|
+
findString: ""
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
changeReplaceString(replaceString) {
|
|
579
|
+
this._state.changeState({ replaceString });
|
|
580
|
+
}
|
|
581
|
+
changeMatchesTheWholeCell(matchesTheWholeCell) {
|
|
582
|
+
this._state.changeState({ matchesTheWholeCell });
|
|
583
|
+
}
|
|
584
|
+
changeCaseSensitive(caseSensitive) {
|
|
585
|
+
this._state.changeState({ caseSensitive });
|
|
586
|
+
}
|
|
587
|
+
changeFindBy(findBy) {
|
|
588
|
+
this._state.changeState({ findBy });
|
|
589
|
+
this._toggleDisplayRawFormula(findBy === FindBy.FORMULA);
|
|
590
|
+
}
|
|
591
|
+
changeFindScope(scope) {
|
|
592
|
+
this._state.changeState({ findScope: scope });
|
|
593
|
+
}
|
|
594
|
+
changeFindDirection(direction) {
|
|
595
|
+
this._state.changeState({ findDirection: direction });
|
|
596
|
+
}
|
|
597
|
+
moveToNextMatch() {
|
|
598
|
+
if (!this._model) return;
|
|
599
|
+
if (this._state.replaceRevealed && !this._model.searched) {
|
|
600
|
+
this._state.changeState({ findString: this._state.inputtingFindString });
|
|
601
|
+
this._model.start();
|
|
602
|
+
} else this._model.moveToNextMatch();
|
|
603
|
+
this._focusSignal$.next();
|
|
604
|
+
}
|
|
605
|
+
moveToPreviousMatch() {
|
|
606
|
+
if (!this._model) return;
|
|
607
|
+
if (this._state.replaceRevealed && !this._model.searched) {
|
|
608
|
+
this._state.changeState({ findString: this._state.inputtingFindString });
|
|
609
|
+
this._model.start();
|
|
610
|
+
} else this._model.moveToPreviousMatch();
|
|
611
|
+
this._focusSignal$.next();
|
|
612
|
+
}
|
|
613
|
+
async replace() {
|
|
614
|
+
if (!this._model) return false;
|
|
615
|
+
return this._model.replace();
|
|
616
|
+
}
|
|
617
|
+
async replaceAll() {
|
|
618
|
+
if (!this._model) throw new Error("[FindReplaceService] replaceAll: model is not initialized!");
|
|
619
|
+
return this._model.replaceAll();
|
|
620
|
+
}
|
|
621
|
+
revealReplace() {
|
|
622
|
+
this._state.changeState({
|
|
623
|
+
replaceRevealed: true,
|
|
624
|
+
inputtingFindString: this._state.findString
|
|
625
|
+
});
|
|
626
|
+
this._toggleRevealReplace(true);
|
|
627
|
+
}
|
|
628
|
+
focusSelection() {
|
|
629
|
+
var _this$_model2;
|
|
630
|
+
(_this$_model2 = this._model) === null || _this$_model2 === void 0 || _this$_model2.focusSelection();
|
|
631
|
+
}
|
|
632
|
+
start(revealReplace = false) {
|
|
633
|
+
if (this._providers.size === 0) return false;
|
|
634
|
+
this._model = this._injector.createInstance(FindReplaceModel, this._state, this._providers);
|
|
635
|
+
this._model.currentMatch$.subscribe((match) => this._currentMatch$.next(match));
|
|
636
|
+
this._model.replaceables$.subscribe((replaceables) => this._replaceables$.next(replaceables));
|
|
637
|
+
const newState = createInitFindReplaceState();
|
|
638
|
+
if (revealReplace) newState.replaceRevealed = true;
|
|
639
|
+
this._state.changeState(newState);
|
|
640
|
+
this._toggleRevealReplace(revealReplace);
|
|
641
|
+
return true;
|
|
642
|
+
}
|
|
643
|
+
find() {
|
|
644
|
+
var _this$_model3;
|
|
645
|
+
(_this$_model3 = this._model) === null || _this$_model3 === void 0 || _this$_model3.start();
|
|
646
|
+
}
|
|
647
|
+
terminate() {
|
|
648
|
+
var _this$_model4;
|
|
649
|
+
(_this$_model4 = this._model) === null || _this$_model4 === void 0 || _this$_model4.dispose();
|
|
650
|
+
this._model = null;
|
|
651
|
+
this._toggleDisplayRawFormula(false);
|
|
652
|
+
this._toggleRevealReplace(false);
|
|
653
|
+
}
|
|
654
|
+
registerFindReplaceProvider(provider) {
|
|
655
|
+
this._providers.add(provider);
|
|
656
|
+
return (0, _univerjs_core.toDisposable)(() => this._providers.delete(provider));
|
|
657
|
+
}
|
|
658
|
+
_toggleRevealReplace(revealReplace) {
|
|
659
|
+
this._contextService.setContextValue(FIND_REPLACE_REPLACE_REVEALED, revealReplace);
|
|
660
|
+
}
|
|
661
|
+
_toggleDisplayRawFormula(force) {
|
|
662
|
+
this._contextService.setContextValue(_univerjs_engine_render.RENDER_RAW_FORMULA_KEY, force);
|
|
663
|
+
}
|
|
664
|
+
};
|
|
665
|
+
FindReplaceService = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_core.Injector)), __decorateParam(1, _univerjs_core.IContextService)], FindReplaceService);
|
|
666
|
+
|
|
667
|
+
//#endregion
|
|
668
|
+
//#region src/commands/commands/replace.command.ts
|
|
669
|
+
const ReplaceCurrentMatchCommand = {
|
|
670
|
+
id: "ui.command.replace-current-match",
|
|
671
|
+
type: _univerjs_core.CommandType.COMMAND,
|
|
672
|
+
handler: (accessor) => {
|
|
673
|
+
return accessor.get(IFindReplaceService).replace();
|
|
674
|
+
}
|
|
675
|
+
};
|
|
676
|
+
const CONFIRM_REPLACE_ALL_ID = "CONFIRM_REPLACE_ALL";
|
|
677
|
+
const ReplaceAllMatchesCommand = {
|
|
678
|
+
id: "ui.command.replace-all-matches",
|
|
679
|
+
type: _univerjs_core.CommandType.COMMAND,
|
|
680
|
+
handler: async (accessor) => {
|
|
681
|
+
const confirmService = accessor.get(_univerjs_core.IConfirmService);
|
|
682
|
+
const localeService = accessor.get(_univerjs_core.LocaleService);
|
|
683
|
+
const messageService = accessor.get(_univerjs_ui.IMessageService);
|
|
684
|
+
if (!await confirmService.confirm({
|
|
685
|
+
id: CONFIRM_REPLACE_ALL_ID,
|
|
686
|
+
title: { title: localeService.t("find-replace.replace.confirm.title") },
|
|
687
|
+
cancelText: localeService.t("button.cancel"),
|
|
688
|
+
confirmText: localeService.t("button.confirm")
|
|
689
|
+
})) return false;
|
|
690
|
+
const { success, failure } = await accessor.get(IFindReplaceService).replaceAll();
|
|
691
|
+
if (failure > 0) {
|
|
692
|
+
if (success === 0) messageService.show({
|
|
693
|
+
type: _univerjs_design.MessageType.Error,
|
|
694
|
+
content: localeService.t("find-replace.replace.all-failure")
|
|
695
|
+
});
|
|
696
|
+
else messageService.show({
|
|
697
|
+
type: _univerjs_design.MessageType.Warning,
|
|
698
|
+
content: localeService.t("find-replace.replace.partial-success", `${success}`, `${failure}`)
|
|
699
|
+
});
|
|
700
|
+
return false;
|
|
701
|
+
}
|
|
702
|
+
messageService.show({
|
|
703
|
+
type: _univerjs_design.MessageType.Success,
|
|
704
|
+
content: localeService.t("find-replace.replace.all-success", `${success}`)
|
|
705
|
+
});
|
|
706
|
+
return true;
|
|
707
|
+
}
|
|
708
|
+
};
|
|
709
|
+
|
|
710
|
+
//#endregion
|
|
711
|
+
//#region src/commands/operations/find-replace.operation.ts
|
|
712
|
+
const OpenFindDialogOperation = {
|
|
713
|
+
id: "ui.operation.open-find-dialog",
|
|
714
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
715
|
+
handler: (accessor) => {
|
|
716
|
+
const findReplaceService = accessor.get(IFindReplaceService);
|
|
717
|
+
if (!findReplaceService.revealed) findReplaceService.start();
|
|
718
|
+
else findReplaceService.focusFindInput();
|
|
719
|
+
return true;
|
|
720
|
+
}
|
|
721
|
+
};
|
|
722
|
+
const OpenReplaceDialogOperation = {
|
|
723
|
+
id: "ui.operation.open-replace-dialog",
|
|
724
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
725
|
+
handler: (accessor) => {
|
|
726
|
+
const findReplaceService = accessor.get(IFindReplaceService);
|
|
727
|
+
if (!findReplaceService.revealed) findReplaceService.start(true);
|
|
728
|
+
else if (!findReplaceService.replaceRevealed) findReplaceService.revealReplace();
|
|
729
|
+
else findReplaceService.focusFindInput();
|
|
730
|
+
return true;
|
|
731
|
+
}
|
|
732
|
+
};
|
|
733
|
+
const GoToNextMatchOperation = {
|
|
734
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
735
|
+
id: "ui.operation.go-to-next-match",
|
|
736
|
+
handler: (accessor) => {
|
|
737
|
+
accessor.get(IFindReplaceService).moveToNextMatch();
|
|
738
|
+
return true;
|
|
739
|
+
}
|
|
740
|
+
};
|
|
741
|
+
const GoToPreviousMatchOperation = {
|
|
742
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
743
|
+
id: "ui.operation.go-to-previous-match",
|
|
744
|
+
handler: (accessor) => {
|
|
745
|
+
accessor.get(IFindReplaceService).moveToPreviousMatch();
|
|
746
|
+
return true;
|
|
747
|
+
}
|
|
748
|
+
};
|
|
749
|
+
const FocusSelectionOperation = {
|
|
750
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
751
|
+
id: "ui.operation.focus-selection",
|
|
752
|
+
handler: (accessor) => {
|
|
753
|
+
accessor.get(IFindReplaceService).focusSelection();
|
|
754
|
+
return true;
|
|
755
|
+
}
|
|
756
|
+
};
|
|
757
|
+
|
|
758
|
+
//#endregion
|
|
759
|
+
//#region src/menu/find-replace.menu.ts
|
|
760
|
+
function FindReplaceMenuItemFactory(accessor) {
|
|
761
|
+
const contextService = accessor.get(_univerjs_core.IContextService);
|
|
762
|
+
return {
|
|
763
|
+
id: OpenFindDialogOperation.id,
|
|
764
|
+
icon: "SearchIcon",
|
|
765
|
+
tooltip: "find-replace.toolbar",
|
|
766
|
+
type: _univerjs_ui.MenuItemType.BUTTON,
|
|
767
|
+
hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_SHEET),
|
|
768
|
+
disabled$: (0, rxjs.combineLatest)([contextService.subscribeContextValue$(_univerjs_core.EDITOR_ACTIVATED), contextService.subscribeContextValue$(_univerjs_core.FOCUSING_SHEET)]).pipe((0, rxjs.map)(([editorActivated, focusingSheet]) => editorActivated || !focusingSheet))
|
|
769
|
+
};
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
//#endregion
|
|
773
|
+
//#region src/menu/schema.ts
|
|
774
|
+
const menuSchema = { [_univerjs_ui.RibbonDataGroup.ORGANIZATION]: { [OpenFindDialogOperation.id]: {
|
|
775
|
+
order: 2,
|
|
776
|
+
menuItemFactory: FindReplaceMenuItemFactory
|
|
777
|
+
} } };
|
|
778
|
+
|
|
779
|
+
//#endregion
|
|
780
|
+
//#region src/views/dialog/SearchInput.tsx
|
|
781
|
+
function SearchInput(props) {
|
|
782
|
+
const { findCompleted: findComplete, localeService, matchesCount, matchesPosition, initialFindString, findReplaceService, onChange, ...rest } = props;
|
|
783
|
+
const [value, setValue] = (0, react.useState)(initialFindString);
|
|
784
|
+
const text = findComplete && matchesCount === 0 ? localeService.t("find-replace.dialog.no-result") : matchesCount === 0 ? " " : void 0;
|
|
785
|
+
function handleChangePosition(newIndex) {
|
|
786
|
+
if (matchesPosition === matchesCount && newIndex === 1) findReplaceService.moveToNextMatch();
|
|
787
|
+
else if (matchesPosition === 1 && newIndex === matchesCount) findReplaceService.moveToPreviousMatch();
|
|
788
|
+
else if (newIndex < matchesPosition) findReplaceService.moveToPreviousMatch();
|
|
789
|
+
else findReplaceService.moveToNextMatch();
|
|
790
|
+
}
|
|
791
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
792
|
+
className: "univer-relative univer-flex univer-items-center univer-gap-2",
|
|
793
|
+
onDrag: (e) => e.stopPropagation(),
|
|
794
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
|
|
795
|
+
"data-u-comp": "search-input",
|
|
796
|
+
autoFocus: true,
|
|
797
|
+
placeholder: localeService.t("find-replace.dialog.find-placeholder"),
|
|
798
|
+
value,
|
|
799
|
+
onChange: (value) => {
|
|
800
|
+
setValue(value);
|
|
801
|
+
onChange === null || onChange === void 0 || onChange(value);
|
|
802
|
+
},
|
|
803
|
+
slot: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Pager, {
|
|
804
|
+
loop: true,
|
|
805
|
+
text,
|
|
806
|
+
value: matchesPosition,
|
|
807
|
+
total: matchesCount,
|
|
808
|
+
onChange: handleChangePosition
|
|
809
|
+
}),
|
|
810
|
+
...rest
|
|
811
|
+
})
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
//#endregion
|
|
816
|
+
//#region src/views/dialog/FindReplaceDialog.tsx
|
|
817
|
+
function useFindInputFocus(findReplaceService, ref) {
|
|
818
|
+
const focus = (0, react.useCallback)(() => {
|
|
819
|
+
var _document$querySelect;
|
|
820
|
+
(_document$querySelect = document.querySelector(".univer-find-input input")) === null || _document$querySelect === void 0 || _document$querySelect.focus();
|
|
821
|
+
}, []);
|
|
822
|
+
const selectHasFocus = (0, react.useCallback)(() => {
|
|
823
|
+
const allInputs = document.querySelectorAll("[data-u-comp=find-replace-dialog] [data-u-comp=search-input]");
|
|
824
|
+
return Array.from(allInputs).some((input) => input === document.activeElement);
|
|
825
|
+
}, []);
|
|
826
|
+
(0, react.useImperativeHandle)(ref, () => ({
|
|
827
|
+
focus,
|
|
828
|
+
selectHasFocus
|
|
829
|
+
}));
|
|
830
|
+
(0, react.useEffect)(() => {
|
|
831
|
+
const subscription = findReplaceService.focusSignal$.subscribe(() => focus());
|
|
832
|
+
return () => subscription.unsubscribe();
|
|
833
|
+
}, [findReplaceService, focus]);
|
|
834
|
+
return {
|
|
835
|
+
focus,
|
|
836
|
+
selectHasFocus
|
|
837
|
+
};
|
|
838
|
+
}
|
|
839
|
+
const FindDialog = (0, react.forwardRef)(function FindDialogImpl(_props, ref) {
|
|
840
|
+
const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
|
|
841
|
+
const findReplaceService = (0, _univerjs_ui.useDependency)(IFindReplaceService);
|
|
842
|
+
const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
|
|
843
|
+
const { findCompleted, findString, matchesCount, matchesPosition } = (0, _univerjs_ui.useObservable)(findReplaceService.state$, void 0, true);
|
|
844
|
+
const revealReplace = (0, react.useCallback)(() => {
|
|
845
|
+
commandService.executeCommand(OpenReplaceDialogOperation.id);
|
|
846
|
+
}, [commandService]);
|
|
847
|
+
const onFindStringChange = (0, _univerjs_ui.useDebounceFn)((findString) => {
|
|
848
|
+
return findReplaceService.changeFindString(findString);
|
|
849
|
+
}, 500);
|
|
850
|
+
useFindInputFocus(findReplaceService, ref);
|
|
851
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SearchInput, {
|
|
852
|
+
findCompleted,
|
|
853
|
+
matchesCount,
|
|
854
|
+
matchesPosition,
|
|
855
|
+
findReplaceService,
|
|
856
|
+
localeService,
|
|
857
|
+
initialFindString: findString,
|
|
858
|
+
onChange: onFindStringChange
|
|
859
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
860
|
+
className: "univer-mt-4 univer-text-center",
|
|
861
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
|
|
862
|
+
className: "hover:univer-text-primary-500/80 univer-cursor-pointer univer-text-sm univer-text-primary-500 univer-transition-colors",
|
|
863
|
+
onClick: revealReplace,
|
|
864
|
+
children: localeService.t("find-replace.dialog.advanced-finding")
|
|
865
|
+
})
|
|
866
|
+
})] });
|
|
867
|
+
});
|
|
868
|
+
const ReplaceDialog = (0, react.forwardRef)(function ReplaceDialogImpl(_props, ref) {
|
|
869
|
+
const findReplaceService = (0, _univerjs_ui.useDependency)(IFindReplaceService);
|
|
870
|
+
const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
|
|
871
|
+
const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
|
|
872
|
+
const messageService = (0, _univerjs_ui.useDependency)(_univerjs_ui.IMessageService);
|
|
873
|
+
const currentMatch = (0, _univerjs_ui.useObservable)(findReplaceService.currentMatch$, void 0, true);
|
|
874
|
+
const replaceables = (0, _univerjs_ui.useObservable)(findReplaceService.replaceables$, void 0, true);
|
|
875
|
+
const { matchesCount, matchesPosition, findString, inputtingFindString, replaceString, caseSensitive, matchesTheWholeCell, findDirection, findScope, findBy, findCompleted } = (0, _univerjs_ui.useObservable)(findReplaceService.state$, void 0, true);
|
|
876
|
+
const findDisabled = inputtingFindString.length === 0;
|
|
877
|
+
const replaceDisabled = matchesCount === 0 || !(currentMatch === null || currentMatch === void 0 ? void 0 : currentMatch.replaceable);
|
|
878
|
+
const replaceAllDisabled = replaceables.length === 0;
|
|
879
|
+
const onFindStringChange = (0, react.useCallback)((newValue) => findReplaceService.changeInputtingFindString(newValue), [findReplaceService]);
|
|
880
|
+
const onReplaceStringChange = (0, react.useCallback)((replaceString) => findReplaceService.changeReplaceString(replaceString), [findReplaceService]);
|
|
881
|
+
const { focus } = useFindInputFocus(findReplaceService, ref);
|
|
882
|
+
const onClickFindButton = (0, react.useCallback)(() => {
|
|
883
|
+
if (findString === inputtingFindString) findReplaceService.moveToNextMatch();
|
|
884
|
+
else {
|
|
885
|
+
findReplaceService.changeFindString(inputtingFindString);
|
|
886
|
+
findReplaceService.find();
|
|
887
|
+
}
|
|
888
|
+
}, [
|
|
889
|
+
findString,
|
|
890
|
+
inputtingFindString,
|
|
891
|
+
findReplaceService
|
|
892
|
+
]);
|
|
893
|
+
const onClickReplaceButton = (0, react.useCallback)(() => commandService.executeCommand(ReplaceCurrentMatchCommand.id), [commandService]);
|
|
894
|
+
const onClickReplaceAllButton = (0, react.useCallback)(async () => {
|
|
895
|
+
await commandService.executeCommand(ReplaceAllMatchesCommand.id);
|
|
896
|
+
focus();
|
|
897
|
+
}, [commandService]);
|
|
898
|
+
const onChangeFindDirection = (0, react.useCallback)((findDirection) => {
|
|
899
|
+
findReplaceService.changeFindDirection(findDirection);
|
|
900
|
+
}, [findReplaceService]);
|
|
901
|
+
const onChangeFindScope = (0, react.useCallback)((findScope) => {
|
|
902
|
+
findReplaceService.changeFindScope(findScope);
|
|
903
|
+
}, [findReplaceService]);
|
|
904
|
+
const onChangeFindBy = (0, react.useCallback)((findBy) => {
|
|
905
|
+
findReplaceService.changeFindBy(findBy);
|
|
906
|
+
}, [findReplaceService]);
|
|
907
|
+
const findScopeOptions = useFindScopeOptions(localeService);
|
|
908
|
+
const findDirectionOptions = useFindDirectionOptions(localeService);
|
|
909
|
+
const findByOptions = useFindByOptions(localeService);
|
|
910
|
+
(0, react.useEffect)(() => {
|
|
911
|
+
if (findCompleted && matchesCount === 0) messageService.show({
|
|
912
|
+
content: localeService.t("find-replace.dialog.no-match"),
|
|
913
|
+
type: _univerjs_design.MessageType.Warning,
|
|
914
|
+
duration: 5e3
|
|
915
|
+
});
|
|
916
|
+
}, [
|
|
917
|
+
findCompleted,
|
|
918
|
+
matchesCount,
|
|
919
|
+
messageService,
|
|
920
|
+
localeService
|
|
921
|
+
]);
|
|
922
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [
|
|
923
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
|
|
924
|
+
label: localeService.t("find-replace.dialog.find"),
|
|
925
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SearchInput, {
|
|
926
|
+
findCompleted,
|
|
927
|
+
className: "univer-find-input",
|
|
928
|
+
matchesCount,
|
|
929
|
+
matchesPosition,
|
|
930
|
+
findReplaceService,
|
|
931
|
+
localeService,
|
|
932
|
+
initialFindString: inputtingFindString,
|
|
933
|
+
onChange: onFindStringChange
|
|
934
|
+
})
|
|
935
|
+
}),
|
|
936
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
|
|
937
|
+
label: localeService.t("find-replace.dialog.replace"),
|
|
938
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
|
|
939
|
+
placeholder: localeService.t("find-replace.dialog.replace-placeholder"),
|
|
940
|
+
value: replaceString,
|
|
941
|
+
onChange: (value) => onReplaceStringChange(value)
|
|
942
|
+
})
|
|
943
|
+
}),
|
|
944
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
|
|
945
|
+
label: localeService.t("find-replace.dialog.find-direction.title"),
|
|
946
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Select, {
|
|
947
|
+
value: findDirection,
|
|
948
|
+
options: findDirectionOptions,
|
|
949
|
+
onChange: onChangeFindDirection
|
|
950
|
+
})
|
|
951
|
+
}),
|
|
952
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormDualColumnLayout, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
|
|
953
|
+
label: localeService.t("find-replace.dialog.find-scope.title"),
|
|
954
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Select, {
|
|
955
|
+
value: findScope,
|
|
956
|
+
options: findScopeOptions,
|
|
957
|
+
onChange: onChangeFindScope
|
|
958
|
+
})
|
|
959
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
|
|
960
|
+
label: localeService.t("find-replace.dialog.find-by.title"),
|
|
961
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Select, {
|
|
962
|
+
value: findBy,
|
|
963
|
+
options: findByOptions,
|
|
964
|
+
onChange: onChangeFindBy
|
|
965
|
+
})
|
|
966
|
+
})] }) }),
|
|
967
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormDualColumnLayout, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Checkbox, {
|
|
968
|
+
checked: caseSensitive,
|
|
969
|
+
onChange: (checked) => {
|
|
970
|
+
findReplaceService.changeCaseSensitive(checked);
|
|
971
|
+
},
|
|
972
|
+
children: localeService.t("find-replace.dialog.case-sensitive")
|
|
973
|
+
}) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Checkbox, {
|
|
974
|
+
checked: matchesTheWholeCell,
|
|
975
|
+
onChange: (checked) => {
|
|
976
|
+
findReplaceService.changeMatchesTheWholeCell(checked);
|
|
977
|
+
},
|
|
978
|
+
children: localeService.t("find-replace.dialog.match-the-whole-cell")
|
|
979
|
+
}) })] }) }),
|
|
980
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
981
|
+
className: "univer-mt-6 univer-flex univer-justify-between",
|
|
982
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
|
|
983
|
+
variant: "primary",
|
|
984
|
+
onClick: onClickFindButton,
|
|
985
|
+
disabled: findDisabled,
|
|
986
|
+
children: localeService.t("find-replace.dialog.find")
|
|
987
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
988
|
+
className: "univer-inline-flex univer-gap-2",
|
|
989
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
|
|
990
|
+
disabled: replaceDisabled,
|
|
991
|
+
onClick: onClickReplaceButton,
|
|
992
|
+
children: localeService.t("find-replace.dialog.replace")
|
|
993
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
|
|
994
|
+
disabled: replaceAllDisabled,
|
|
995
|
+
onClick: onClickReplaceAllButton,
|
|
996
|
+
children: localeService.t("find-replace.dialog.replace-all")
|
|
997
|
+
})]
|
|
998
|
+
})]
|
|
999
|
+
})
|
|
1000
|
+
] });
|
|
1001
|
+
});
|
|
1002
|
+
function FindReplaceDialog() {
|
|
1003
|
+
const findReplaceService = (0, _univerjs_ui.useDependency)(IFindReplaceService);
|
|
1004
|
+
const layoutService = (0, _univerjs_ui.useDependency)(_univerjs_ui.ILayoutService);
|
|
1005
|
+
const contextService = (0, _univerjs_ui.useDependency)(_univerjs_core.IContextService);
|
|
1006
|
+
const state = (0, _univerjs_ui.useObservable)(findReplaceService.state$, void 0, true);
|
|
1007
|
+
const dialogContainerRef = (0, react.useRef)(null);
|
|
1008
|
+
(0, react.useEffect)(() => {
|
|
1009
|
+
let disposable;
|
|
1010
|
+
if (dialogContainerRef.current) disposable = layoutService.registerContainerElement(dialogContainerRef.current);
|
|
1011
|
+
return () => disposable === null || disposable === void 0 ? void 0 : disposable.dispose();
|
|
1012
|
+
}, [layoutService]);
|
|
1013
|
+
const focusRef = (0, react.useRef)(null);
|
|
1014
|
+
const setDialogContainerFocus = (0, react.useCallback)((focused) => contextService.setContextValue(FIND_REPLACE_DIALOG_FOCUS, focused), [contextService]);
|
|
1015
|
+
const setDialogInputFocus = (0, react.useCallback)((focused) => contextService.setContextValue(FIND_REPLACE_INPUT_FOCUS, focused), [contextService]);
|
|
1016
|
+
(0, react.useEffect)(() => {
|
|
1017
|
+
var _focusRef$current;
|
|
1018
|
+
const focusSubscription = (0, rxjs.fromEvent)(document, "focusin").subscribe((event) => {
|
|
1019
|
+
var _dialogContainerRef$c;
|
|
1020
|
+
if (event.target && ((_dialogContainerRef$c = dialogContainerRef.current) === null || _dialogContainerRef$c === void 0 ? void 0 : _dialogContainerRef$c.contains(event.target))) setDialogContainerFocus(true);
|
|
1021
|
+
else setDialogContainerFocus(false);
|
|
1022
|
+
if (!focusRef.current || !focusRef.current.selectHasFocus()) setDialogInputFocus(false);
|
|
1023
|
+
else setDialogInputFocus(true);
|
|
1024
|
+
});
|
|
1025
|
+
(_focusRef$current = focusRef.current) === null || _focusRef$current === void 0 || _focusRef$current.focus();
|
|
1026
|
+
setDialogContainerFocus(true);
|
|
1027
|
+
setDialogInputFocus(true);
|
|
1028
|
+
return () => {
|
|
1029
|
+
focusSubscription.unsubscribe();
|
|
1030
|
+
setDialogContainerFocus(false);
|
|
1031
|
+
};
|
|
1032
|
+
}, [setDialogContainerFocus, setDialogInputFocus]);
|
|
1033
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1034
|
+
ref: dialogContainerRef,
|
|
1035
|
+
"data-u-comp": "find-replace-dialog",
|
|
1036
|
+
children: !state.replaceRevealed ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FindDialog, { ref: focusRef }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ReplaceDialog, { ref: focusRef })
|
|
1037
|
+
});
|
|
1038
|
+
}
|
|
1039
|
+
function useFindScopeOptions(localeService) {
|
|
1040
|
+
return (0, react.useMemo)(() => {
|
|
1041
|
+
return [{
|
|
1042
|
+
label: localeService.t("find-replace.dialog.find-scope.current-sheet"),
|
|
1043
|
+
value: FindScope.SUBUNIT
|
|
1044
|
+
}, {
|
|
1045
|
+
label: localeService.t("find-replace.dialog.find-scope.workbook"),
|
|
1046
|
+
value: FindScope.UNIT
|
|
1047
|
+
}];
|
|
1048
|
+
}, [localeService.getCurrentLocale()]);
|
|
1049
|
+
}
|
|
1050
|
+
function useFindDirectionOptions(localeService) {
|
|
1051
|
+
return (0, react.useMemo)(() => {
|
|
1052
|
+
return [{
|
|
1053
|
+
label: localeService.t("find-replace.dialog.find-direction.row"),
|
|
1054
|
+
value: FindDirection.ROW
|
|
1055
|
+
}, {
|
|
1056
|
+
label: localeService.t("find-replace.dialog.find-direction.column"),
|
|
1057
|
+
value: FindDirection.COLUMN
|
|
1058
|
+
}];
|
|
1059
|
+
}, [localeService.getCurrentLocale()]);
|
|
1060
|
+
}
|
|
1061
|
+
function useFindByOptions(localeService) {
|
|
1062
|
+
return (0, react.useMemo)(() => {
|
|
1063
|
+
return [{
|
|
1064
|
+
label: localeService.t("find-replace.dialog.find-by.value"),
|
|
1065
|
+
value: FindBy.VALUE
|
|
1066
|
+
}, {
|
|
1067
|
+
label: localeService.t("find-replace.dialog.find-by.formula"),
|
|
1068
|
+
value: FindBy.FORMULA
|
|
1069
|
+
}];
|
|
1070
|
+
}, [localeService.getCurrentLocale()]);
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
//#endregion
|
|
1074
|
+
//#region src/controllers/find-replace.shortcut.ts
|
|
1075
|
+
function whenFindReplaceDialogFocused(contextService) {
|
|
1076
|
+
return contextService.getContextValue(FIND_REPLACE_DIALOG_FOCUS);
|
|
1077
|
+
}
|
|
1078
|
+
function whenReplaceRevealed(contextService) {
|
|
1079
|
+
return contextService.getContextValue(FIND_REPLACE_REPLACE_REVEALED);
|
|
1080
|
+
}
|
|
1081
|
+
function whenFindReplaceInputFocused(contextService) {
|
|
1082
|
+
return contextService.getContextValue(FIND_REPLACE_INPUT_FOCUS);
|
|
1083
|
+
}
|
|
1084
|
+
const FIND_REPLACE_SHORTCUT_GROUP = "7_find-replace-shortcuts";
|
|
1085
|
+
function whenSheetFocused(contextService) {
|
|
1086
|
+
return contextService.getContextValue(_univerjs_core.FOCUSING_SHEET);
|
|
1087
|
+
}
|
|
1088
|
+
function whenEditorNotActivated(contextService) {
|
|
1089
|
+
return !contextService.getContextValue(_univerjs_core.EDITOR_ACTIVATED);
|
|
1090
|
+
}
|
|
1091
|
+
const OpenFindDialogShortcutItem = {
|
|
1092
|
+
id: OpenFindDialogOperation.id,
|
|
1093
|
+
description: "find-replace.shortcut.open-find-dialog",
|
|
1094
|
+
binding: _univerjs_ui.KeyCode.F | _univerjs_ui.MetaKeys.CTRL_COMMAND,
|
|
1095
|
+
group: FIND_REPLACE_SHORTCUT_GROUP,
|
|
1096
|
+
preconditions(contextService) {
|
|
1097
|
+
return !whenFindReplaceDialogFocused(contextService) && whenSheetFocused(contextService) && whenEditorNotActivated(contextService);
|
|
1098
|
+
}
|
|
1099
|
+
};
|
|
1100
|
+
const MacOpenFindDialogShortcutItem = {
|
|
1101
|
+
id: OpenFindDialogOperation.id,
|
|
1102
|
+
description: "find-replace.shortcut.open-find-dialog",
|
|
1103
|
+
binding: _univerjs_ui.KeyCode.F | _univerjs_ui.MetaKeys.CTRL_COMMAND,
|
|
1104
|
+
mac: _univerjs_ui.KeyCode.F | _univerjs_ui.MetaKeys.MAC_CTRL,
|
|
1105
|
+
preconditions(contextService) {
|
|
1106
|
+
return !whenFindReplaceDialogFocused(contextService) && whenSheetFocused(contextService) && whenEditorNotActivated(contextService);
|
|
1107
|
+
}
|
|
1108
|
+
};
|
|
1109
|
+
const OpenReplaceDialogShortcutItem = {
|
|
1110
|
+
id: OpenReplaceDialogOperation.id,
|
|
1111
|
+
description: "find-replace.shortcut.open-replace-dialog",
|
|
1112
|
+
binding: _univerjs_ui.KeyCode.H | _univerjs_ui.MetaKeys.CTRL_COMMAND,
|
|
1113
|
+
mac: _univerjs_ui.KeyCode.H | _univerjs_ui.MetaKeys.MAC_CTRL,
|
|
1114
|
+
group: FIND_REPLACE_SHORTCUT_GROUP,
|
|
1115
|
+
preconditions(contextService) {
|
|
1116
|
+
return whenSheetFocused(contextService) && whenEditorNotActivated(contextService) && (!whenFindReplaceDialogFocused(contextService) || !whenReplaceRevealed(contextService));
|
|
1117
|
+
}
|
|
1118
|
+
};
|
|
1119
|
+
const GoToNextFindMatchShortcutItem = {
|
|
1120
|
+
id: GoToNextMatchOperation.id,
|
|
1121
|
+
description: "find-replace.shortcut.go-to-next-match",
|
|
1122
|
+
binding: _univerjs_ui.KeyCode.ENTER,
|
|
1123
|
+
group: FIND_REPLACE_SHORTCUT_GROUP,
|
|
1124
|
+
priority: 1e3,
|
|
1125
|
+
preconditions(contextService) {
|
|
1126
|
+
return whenFindReplaceInputFocused(contextService) && whenFindReplaceDialogFocused(contextService);
|
|
1127
|
+
}
|
|
1128
|
+
};
|
|
1129
|
+
const GoToPreviousFindMatchShortcutItem = {
|
|
1130
|
+
id: GoToPreviousMatchOperation.id,
|
|
1131
|
+
description: "find-replace.shortcut.go-to-previous-match",
|
|
1132
|
+
binding: _univerjs_ui.KeyCode.ENTER | _univerjs_ui.MetaKeys.SHIFT,
|
|
1133
|
+
group: FIND_REPLACE_SHORTCUT_GROUP,
|
|
1134
|
+
priority: 1e3,
|
|
1135
|
+
preconditions(contextService) {
|
|
1136
|
+
return whenFindReplaceInputFocused(contextService) && whenFindReplaceDialogFocused(contextService);
|
|
1137
|
+
}
|
|
1138
|
+
};
|
|
1139
|
+
const FocusSelectionShortcutItem = {
|
|
1140
|
+
id: FocusSelectionOperation.id,
|
|
1141
|
+
description: "find-replace.shortcut.focus-selection",
|
|
1142
|
+
binding: _univerjs_ui.KeyCode.ESC,
|
|
1143
|
+
group: FIND_REPLACE_SHORTCUT_GROUP,
|
|
1144
|
+
priority: 1e3,
|
|
1145
|
+
preconditions(contextService) {
|
|
1146
|
+
return whenFindReplaceDialogFocused(contextService);
|
|
1147
|
+
}
|
|
1148
|
+
};
|
|
1149
|
+
|
|
1150
|
+
//#endregion
|
|
1151
|
+
//#region src/controllers/find-replace.controller.ts
|
|
1152
|
+
const FIND_REPLACE_DIALOG_ID = "DESKTOP_FIND_REPLACE_DIALOG";
|
|
1153
|
+
const FIND_REPLACE_PANEL_WIDTH = 350;
|
|
1154
|
+
const FIND_REPLACE_PANEL_RIGHT_PADDING = 20;
|
|
1155
|
+
const FIND_REPLACE_PANEL_TOP_PADDING = 64;
|
|
1156
|
+
let FindReplaceController = class FindReplaceController extends _univerjs_core.RxDisposable {
|
|
1157
|
+
constructor(_univerInstanceService, _menuManagerService, _shortcutService, _commandService, _findReplaceService, _dialogService, _layoutService, _localeService, _componentManager) {
|
|
1158
|
+
super();
|
|
1159
|
+
this._univerInstanceService = _univerInstanceService;
|
|
1160
|
+
this._menuManagerService = _menuManagerService;
|
|
1161
|
+
this._shortcutService = _shortcutService;
|
|
1162
|
+
this._commandService = _commandService;
|
|
1163
|
+
this._findReplaceService = _findReplaceService;
|
|
1164
|
+
this._dialogService = _dialogService;
|
|
1165
|
+
this._layoutService = _layoutService;
|
|
1166
|
+
this._localeService = _localeService;
|
|
1167
|
+
this._componentManager = _componentManager;
|
|
1168
|
+
_defineProperty(this, "_closingListenerDisposable", void 0);
|
|
1169
|
+
this._initCommands();
|
|
1170
|
+
this._initUI();
|
|
1171
|
+
this._initShortcuts();
|
|
1172
|
+
}
|
|
1173
|
+
dispose() {
|
|
1174
|
+
var _this$_closingListene;
|
|
1175
|
+
super.dispose();
|
|
1176
|
+
(_this$_closingListene = this._closingListenerDisposable) === null || _this$_closingListene === void 0 || _this$_closingListene.dispose();
|
|
1177
|
+
this._closingListenerDisposable = null;
|
|
1178
|
+
}
|
|
1179
|
+
_initCommands() {
|
|
1180
|
+
[
|
|
1181
|
+
OpenFindDialogOperation,
|
|
1182
|
+
OpenReplaceDialogOperation,
|
|
1183
|
+
GoToNextMatchOperation,
|
|
1184
|
+
GoToPreviousMatchOperation,
|
|
1185
|
+
ReplaceAllMatchesCommand,
|
|
1186
|
+
ReplaceCurrentMatchCommand,
|
|
1187
|
+
FocusSelectionOperation
|
|
1188
|
+
].forEach((c) => {
|
|
1189
|
+
this.disposeWithMe(this._commandService.registerCommand(c));
|
|
1190
|
+
});
|
|
1191
|
+
}
|
|
1192
|
+
_initShortcuts() {
|
|
1193
|
+
[
|
|
1194
|
+
OpenReplaceDialogShortcutItem,
|
|
1195
|
+
OpenFindDialogShortcutItem,
|
|
1196
|
+
MacOpenFindDialogShortcutItem,
|
|
1197
|
+
GoToPreviousFindMatchShortcutItem,
|
|
1198
|
+
GoToNextFindMatchShortcutItem,
|
|
1199
|
+
FocusSelectionShortcutItem
|
|
1200
|
+
].forEach((s) => this.disposeWithMe(this._shortcutService.registerShortcut(s)));
|
|
1201
|
+
}
|
|
1202
|
+
_initUI() {
|
|
1203
|
+
[["FindReplaceDialog", FindReplaceDialog], ["SearchIcon", _univerjs_icons.SearchIcon]].forEach(([key, comp]) => {
|
|
1204
|
+
this.disposeWithMe(this._componentManager.register(key, comp));
|
|
1205
|
+
});
|
|
1206
|
+
this._menuManagerService.mergeMenu(menuSchema);
|
|
1207
|
+
this._findReplaceService.stateUpdates$.pipe((0, rxjs.takeUntil)(this.dispose$)).subscribe((newState) => {
|
|
1208
|
+
if (newState.revealed === true) this._openPanel();
|
|
1209
|
+
});
|
|
1210
|
+
}
|
|
1211
|
+
_openPanel() {
|
|
1212
|
+
this._dialogService.open({
|
|
1213
|
+
id: FIND_REPLACE_DIALOG_ID,
|
|
1214
|
+
draggable: true,
|
|
1215
|
+
width: FIND_REPLACE_PANEL_WIDTH,
|
|
1216
|
+
title: { title: this._localeService.t("find-replace.dialog.title") },
|
|
1217
|
+
children: { label: "FindReplaceDialog" },
|
|
1218
|
+
destroyOnClose: true,
|
|
1219
|
+
mask: false,
|
|
1220
|
+
maskClosable: false,
|
|
1221
|
+
defaultPosition: getFindReplaceDialogDefaultPosition(),
|
|
1222
|
+
preservePositionOnDestroy: true,
|
|
1223
|
+
onClose: () => this.closePanel()
|
|
1224
|
+
});
|
|
1225
|
+
this._closingListenerDisposable = (0, _univerjs_core.toDisposable)(this._univerInstanceService.focused$.pipe((0, rxjs.takeUntil)(this.dispose$)).subscribe((focused) => {
|
|
1226
|
+
if (!focused || !this._univerInstanceService.getUniverSheetInstance(focused)) this.closePanel();
|
|
1227
|
+
}));
|
|
1228
|
+
}
|
|
1229
|
+
closePanel() {
|
|
1230
|
+
if (!this._closingListenerDisposable) return;
|
|
1231
|
+
this._closingListenerDisposable.dispose();
|
|
1232
|
+
this._closingListenerDisposable = null;
|
|
1233
|
+
this._dialogService.close(FIND_REPLACE_DIALOG_ID);
|
|
1234
|
+
this._findReplaceService.terminate();
|
|
1235
|
+
queueMicrotask(() => this._layoutService.focus());
|
|
1236
|
+
}
|
|
1237
|
+
};
|
|
1238
|
+
FindReplaceController = __decorate([
|
|
1239
|
+
__decorateParam(0, _univerjs_core.IUniverInstanceService),
|
|
1240
|
+
__decorateParam(1, _univerjs_ui.IMenuManagerService),
|
|
1241
|
+
__decorateParam(2, _univerjs_ui.IShortcutService),
|
|
1242
|
+
__decorateParam(3, _univerjs_core.ICommandService),
|
|
1243
|
+
__decorateParam(4, IFindReplaceService),
|
|
1244
|
+
__decorateParam(5, _univerjs_ui.IDialogService),
|
|
1245
|
+
__decorateParam(6, _univerjs_ui.ILayoutService),
|
|
1246
|
+
__decorateParam(7, (0, _univerjs_core.Inject)(_univerjs_core.LocaleService)),
|
|
1247
|
+
__decorateParam(8, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager))
|
|
1248
|
+
], FindReplaceController);
|
|
1249
|
+
function getFindReplaceDialogDefaultPosition() {
|
|
1250
|
+
const { innerWidth } = window;
|
|
1251
|
+
return {
|
|
1252
|
+
x: innerWidth - FIND_REPLACE_PANEL_WIDTH - FIND_REPLACE_PANEL_RIGHT_PADDING,
|
|
1253
|
+
y: FIND_REPLACE_PANEL_TOP_PADDING
|
|
1254
|
+
};
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
//#endregion
|
|
1258
|
+
//#region package.json
|
|
1259
|
+
var name = "@univerjs/find-replace";
|
|
1260
|
+
var version = "0.21.0-insiders.20260422-d7fcb4d";
|
|
1261
|
+
|
|
1262
|
+
//#endregion
|
|
1263
|
+
//#region src/config/config.ts
|
|
1264
|
+
const FIND_REPLACE_PLUGIN_CONFIG_KEY = "find-replace.config";
|
|
1265
|
+
const configSymbol = Symbol(FIND_REPLACE_PLUGIN_CONFIG_KEY);
|
|
1266
|
+
const defaultPluginConfig = {};
|
|
1267
|
+
|
|
1268
|
+
//#endregion
|
|
1269
|
+
//#region src/plugin.ts
|
|
1270
|
+
let UniverFindReplacePlugin = class UniverFindReplacePlugin extends _univerjs_core.Plugin {
|
|
1271
|
+
constructor(_config = defaultPluginConfig, _injector, _configService) {
|
|
1272
|
+
super();
|
|
1273
|
+
this._config = _config;
|
|
1274
|
+
this._injector = _injector;
|
|
1275
|
+
this._configService = _configService;
|
|
1276
|
+
const { ...rest } = (0, _univerjs_core.merge)({}, defaultPluginConfig, this._config);
|
|
1277
|
+
this._configService.setConfig(FIND_REPLACE_PLUGIN_CONFIG_KEY, rest);
|
|
1278
|
+
}
|
|
1279
|
+
onStarting() {
|
|
1280
|
+
[[FindReplaceController], [IFindReplaceService, { useClass: FindReplaceService }]].forEach((d) => this._injector.add(d));
|
|
1281
|
+
}
|
|
1282
|
+
onRendered() {
|
|
1283
|
+
this._injector.get(FindReplaceController);
|
|
1284
|
+
}
|
|
1285
|
+
};
|
|
1286
|
+
_defineProperty(UniverFindReplacePlugin, "pluginName", "UNIVER_FIND_REPLACE_PLUGIN");
|
|
1287
|
+
_defineProperty(UniverFindReplacePlugin, "packageName", name);
|
|
1288
|
+
_defineProperty(UniverFindReplacePlugin, "version", version);
|
|
1289
|
+
UniverFindReplacePlugin = __decorate([__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)), __decorateParam(2, _univerjs_core.IConfigService)], UniverFindReplacePlugin);
|
|
1290
|
+
|
|
1291
|
+
//#endregion
|
|
1292
|
+
exports.FindBy = FindBy;
|
|
1293
|
+
exports.FindDirection = FindDirection;
|
|
1294
|
+
exports.FindModel = FindModel;
|
|
1295
|
+
Object.defineProperty(exports, 'FindReplaceController', {
|
|
1296
|
+
enumerable: true,
|
|
1297
|
+
get: function () {
|
|
1298
|
+
return FindReplaceController;
|
|
1299
|
+
}
|
|
1300
|
+
});
|
|
1301
|
+
Object.defineProperty(exports, 'FindReplaceModel', {
|
|
1302
|
+
enumerable: true,
|
|
1303
|
+
get: function () {
|
|
1304
|
+
return FindReplaceModel;
|
|
1305
|
+
}
|
|
1306
|
+
});
|
|
1307
|
+
exports.FindReplaceState = FindReplaceState;
|
|
1308
|
+
exports.FindScope = FindScope;
|
|
1309
|
+
exports.GoToNextMatchOperation = GoToNextMatchOperation;
|
|
1310
|
+
exports.GoToPreviousMatchOperation = GoToPreviousMatchOperation;
|
|
1311
|
+
exports.IFindReplaceService = IFindReplaceService;
|
|
1312
|
+
exports.OpenFindDialogOperation = OpenFindDialogOperation;
|
|
1313
|
+
exports.OpenReplaceDialogOperation = OpenReplaceDialogOperation;
|
|
1314
|
+
exports.ReplaceAllMatchesCommand = ReplaceAllMatchesCommand;
|
|
1315
|
+
exports.ReplaceCurrentMatchCommand = ReplaceCurrentMatchCommand;
|
|
1316
|
+
Object.defineProperty(exports, 'UniverFindReplacePlugin', {
|
|
1317
|
+
enumerable: true,
|
|
1318
|
+
get: function () {
|
|
1319
|
+
return UniverFindReplacePlugin;
|
|
1320
|
+
}
|
|
1321
|
+
});
|
|
1322
|
+
exports.createInitFindReplaceState = createInitFindReplaceState;
|