@univerjs/preset-sheets-find-replace 0.18.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/umd/index.js +2 -5
  2. package/package.json +5 -5
package/lib/umd/index.js CHANGED
@@ -1,11 +1,8 @@
1
1
  // @univerjs/find-replace/index
2
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/design`),require(`@univerjs/ui`),require(`@univerjs/engine-render`),require(`rxjs`),require(`react`),require(`react/jsx-runtime`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/design`,`@univerjs/ui`,`@univerjs/engine-render`,`rxjs`,`react`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverFindReplace={},e.UniverCore,e.UniverDesign,e.UniverUi,e.UniverEngineRender,e.rxjs,e.React,e.React))})(this,function(e,t,n,r,i,a,o,s){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let 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 t.Disposable{};let v=(0,t.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 t.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 a.BehaviorSubject(null)),m(this,`replaceables$`,new a.BehaviorSubject([])),m(this,`_findModels`,[]),m(this,`_matchingModel`,null),m(this,`_matches`,[]),m(this,`_currentSearchingDisposables`,null),this.disposeWithMe(this._state.stateUpdates$.pipe((0,a.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(e){let n=this._currentSearchingDisposables=new t.DisposableCollection,r=(0,a.combineLatest)(e.map(e=>e.matchesUpdate$)).pipe((0,a.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([]))});e.forEach(e=>n.add((0,t.toDisposable)(e.activelyChangingMatch$.subscribe(e=>{let t=this._matches.findIndex(t=>t===e);this._state.changeState({matchesPosition:t+1})})))),n.add((0,t.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,t.IUniverInstanceService),h(3,t.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 a.Subject),m(this,`stateUpdates$`,this._stateUpdates$.asObservable()),m(this,`_state$`,new a.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 t.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 a.BehaviorSubject(null)),m(this,`currentMatch$`,this._currentMatch$.asObservable()),m(this,`_replaceables$`,new a.BehaviorSubject([])),m(this,`replaceables$`,this._replaceables$.asObservable()),m(this,`_focusSignal$`,new a.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(e){return this._providers.add(e),(0,t.toDisposable)(()=>this._providers.delete(e))}_toggleRevealReplace(e){this._contextService.setContextValue(u,e)}_toggleDisplayRawFormula(e){this._contextService.setContextValue(i.RENDER_RAW_FORMULA_KEY,e)}};E=g([h(0,(0,t.Inject)(t.Injector)),h(1,t.IContextService)],E);let D={id:`ui.command.replace-current-match`,type:t.CommandType.COMMAND,handler:e=>e.get(v).replace()},O={id:`ui.command.replace-all-matches`,type:t.CommandType.COMMAND,handler:async e=>{let i=e.get(t.IConfirmService),a=e.get(t.LocaleService),o=e.get(r.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 e.get(v).replaceAll();return c>0?(s===0?o.show({type:n.MessageType.Error,content:a.t(`find-replace.replace.all-failure`)}):o.show({type:n.MessageType.Warning,content:a.t(`find-replace.replace.partial-success`,`${s}`,`${c}`)}),!1):(o.show({type:n.MessageType.Success,content:a.t(`find-replace.replace.all-success`,`${s}`)}),!0)}},k={id:`ui.operation.open-find-dialog`,type:t.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:t.CommandType.OPERATION,handler:e=>{let t=e.get(v);return t.revealed?t.replaceRevealed?t.focusFindInput():t.revealReplace():t.start(!0),!0}},j={type:t.CommandType.OPERATION,id:`ui.operation.go-to-next-match`,handler:e=>(e.get(v).moveToNextMatch(),!0)},M={type:t.CommandType.OPERATION,id:`ui.operation.go-to-previous-match`,handler:e=>(e.get(v).moveToPreviousMatch(),!0)},N={type:t.CommandType.OPERATION,id:`ui.operation.focus-selection`,handler:e=>(e.get(v).focusSelection(),!0)};function P({ref:e,...t}){let{icon:n,id:r,className:i,extend:a,...s}=t,c=`univerjs-icon univerjs-icon-${r} ${i||``}`.trim(),l=(0,o.useRef)(`_${R()}`);return F(n,`${r}`,{defIds:n.defIds,idSuffix:l.current},{ref:e,className:c,...s},a)}function F(e,t,n,r,i){return(0,o.createElement)(e.tag,{key:t,...I(e,n,i),...r},(L(e,n).children||[]).map((r,a)=>F(r,`${t}-${e.tag}-${a}`,n,void 0,i)))}function I(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),e.tag===`mask`&&r.id&&(r.id+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{e===`mask`&&typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});let{defIds:i}=t;return!i||i.length===0?r:(e.tag===`use`&&r[`xlink:href`]&&(r[`xlink:href`]+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))}),r)}function L(e,t){var n;let{defIds:r}=t;return!r||r.length===0?e:e.tag===`defs`&&(n=e.children)!=null&&n.length?{...e,children:e.children.map(e=>typeof e.attrs.id==`string`&&r&&r.includes(e.attrs.id)?{...e,attrs:{...e.attrs,id:e.attrs.id+t.idSuffix}}:e)}:e}function R(){return Math.random().toString(36).substring(2,8)}P.displayName=`UniverIcon`;let z={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M7.71899 1.36938C4.37604 1.36938 1.66602 4.07941 1.66602 7.42236C1.66602 10.7653 4.37604 13.4753 7.71899 13.4753C9.16744 13.4753 10.4971 12.9666 11.5389 12.118L13.6598 14.4109C13.8848 14.6542 14.2644 14.669 14.5077 14.444C14.7509 14.219 14.7657 13.8393 14.5407 13.5961L12.3906 11.2716C13.2536 10.2254 13.772 8.88442 13.772 7.42236C13.772 4.07941 11.0619 1.36938 7.71899 1.36938ZM2.86602 7.42236C2.86602 4.74215 5.03878 2.56938 7.71899 2.56938C10.3992 2.56938 12.572 4.74215 12.572 7.42236C12.572 10.1026 10.3992 12.2753 7.71899 12.2753C5.03878 12.2753 2.86602 10.1026 2.86602 7.42236Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},B=(0,o.forwardRef)(function(e,t){return(0,o.createElement)(P,Object.assign({},e,{id:`search-icon`,ref:t,icon:z}))});B.displayName=`SearchIcon`;function V(e){let n=e.get(t.IContextService);return{id:k.id,icon:`SearchIcon`,tooltip:`find-replace.toolbar`,type:r.MenuItemType.BUTTON,hidden$:(0,r.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:(0,a.combineLatest)([n.subscribeContextValue$(t.EDITOR_ACTIVATED),n.subscribeContextValue$(t.FOCUSING_SHEET)]).pipe((0,a.map)(([e,t])=>e||!t))}}let ee={[r.RibbonDataGroup.ORGANIZATION]:{[k.id]:{order:2,menuItemFactory:V}}};function H(e){let{findCompleted:t,localeService:r,matchesCount:i,matchesPosition:a,initialFindString:c,findReplaceService:l,onChange:u,...d}=e,[f,p]=(0,o.useState)(c),m=t&&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)(n.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)(n.Pager,{loop:!0,text:m,value:a,total:i,onChange:h}),...d})})}function U(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}}let te=(0,o.forwardRef)(function(e,n){let i=(0,r.useDependency)(t.LocaleService),a=(0,r.useDependency)(v),c=(0,r.useDependency)(t.ICommandService),{findCompleted:l,findString:u,matchesCount:d,matchesPosition:f}=(0,r.useObservable)(a.state$,void 0,!0),p=(0,o.useCallback)(()=>{c.executeCommand(A.id)},[c]),m=(0,r.useDebounceFn)(e=>a.changeFindString(e),500);return U(a,n),(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(H,{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:`
3
- hover:univer-text-primary-500/80
4
- univer-cursor-pointer univer-text-sm univer-text-primary-500 univer-transition-colors
5
- `,onClick:p,children:i.t(`find-replace.dialog.advanced-finding`)})})]})}),ne=(0,o.forwardRef)(function(e,i){let a=(0,r.useDependency)(v),c=(0,r.useDependency)(t.LocaleService),l=(0,r.useDependency)(t.ICommandService),u=(0,r.useDependency)(r.IMessageService),d=(0,r.useObservable)(a.currentMatch$,void 0,!0),f=(0,r.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,r.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}=U(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]),I=(0,o.useCallback)(e=>{a.changeFindDirection(e)},[a]),L=(0,o.useCallback)(e=>{a.changeFindScope(e)},[a]),R=(0,o.useCallback)(e=>{a.changeFindBy(e)},[a]),z=ie(c),B=ae(c),V=oe(c);return(0,o.useEffect)(()=>{w&&p===0&&u.show({content:c.t(`find-replace.dialog.no-match`),type:n.MessageType.Warning,duration:5e3})},[w,p,u,c]),(0,s.jsxs)(`div`,{children:[(0,s.jsx)(n.FormLayout,{label:c.t(`find-replace.dialog.find`),children:(0,s.jsx)(H,{findCompleted:w,className:`univer-find-input`,matchesCount:p,matchesPosition:m,findReplaceService:a,localeService:c,initialFindString:g,onChange:A})}),(0,s.jsx)(n.FormLayout,{label:c.t(`find-replace.dialog.replace`),children:(0,s.jsx)(n.Input,{placeholder:c.t(`find-replace.dialog.replace-placeholder`),value:_,onChange:e=>j(e)})}),(0,s.jsx)(n.FormLayout,{label:c.t(`find-replace.dialog.find-direction.title`),children:(0,s.jsx)(n.Select,{value:x,options:B,onChange:I})}),(0,s.jsx)(n.FormDualColumnLayout,{children:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.FormLayout,{label:c.t(`find-replace.dialog.find-scope.title`),children:(0,s.jsx)(n.Select,{value:S,options:z,onChange:L})}),(0,s.jsx)(n.FormLayout,{label:c.t(`find-replace.dialog.find-by.title`),children:(0,s.jsx)(n.Select,{value:C,options:V,onChange:R})})]})}),(0,s.jsx)(n.FormDualColumnLayout,{children:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.FormLayout,{children:(0,s.jsx)(n.Checkbox,{checked:y,onChange:e=>{a.changeCaseSensitive(e)},children:c.t(`find-replace.dialog.case-sensitive`)})}),(0,s.jsx)(n.FormLayout,{children:(0,s.jsx)(n.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)(n.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)(n.Button,{disabled:E,onClick:P,children:c.t(`find-replace.dialog.replace`)}),(0,s.jsx)(n.Button,{disabled:k,onClick:F,children:c.t(`find-replace.dialog.replace-all`)})]})]})]})});function re(){let e=(0,r.useDependency)(v),n=(0,r.useDependency)(r.ILayoutService),i=(0,r.useDependency)(t.IContextService),u=(0,r.useObservable)(e.state$,void 0,!0),d=(0,o.useRef)(null);(0,o.useEffect)(()=>{let e;return d.current&&(e=n.registerContainerElement(d.current)),()=>e==null?void 0:e.dispose()},[n]);let f=(0,o.useRef)(null),p=(0,o.useCallback)(e=>i.setContextValue(l,e),[i]),m=(0,o.useCallback)(e=>i.setContextValue(c,e),[i]);return(0,o.useEffect)(()=>{var e;let t=(0,a.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)(ne,{ref:f}):(0,s.jsx)(te,{ref:f})})}function ie(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 ae(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 oe(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 W(e){return e.getContextValue(l)}function se(e){return e.getContextValue(u)}function G(e){return e.getContextValue(c)}let K=`7_find-replace-shortcuts`;function q(e){return e.getContextValue(t.FOCUSING_SHEET)}function J(e){return!e.getContextValue(t.EDITOR_ACTIVATED)}let ce={id:k.id,description:`find-replace.shortcut.open-find-dialog`,binding:r.KeyCode.F|r.MetaKeys.CTRL_COMMAND,group:K,preconditions(e){return!W(e)&&q(e)&&J(e)}},le={id:k.id,description:`find-replace.shortcut.open-find-dialog`,binding:r.KeyCode.F|r.MetaKeys.CTRL_COMMAND,mac:r.KeyCode.F|r.MetaKeys.MAC_CTRL,preconditions(e){return!W(e)&&q(e)&&J(e)}},ue={id:A.id,description:`find-replace.shortcut.open-replace-dialog`,binding:r.KeyCode.H|r.MetaKeys.CTRL_COMMAND,mac:r.KeyCode.H|r.MetaKeys.MAC_CTRL,group:K,preconditions(e){return q(e)&&J(e)&&(!W(e)||!se(e))}},de={id:j.id,description:`find-replace.shortcut.go-to-next-match`,binding:r.KeyCode.ENTER,group:K,priority:1e3,preconditions(e){return G(e)&&W(e)}},fe={id:M.id,description:`find-replace.shortcut.go-to-previous-match`,binding:r.KeyCode.ENTER|r.MetaKeys.SHIFT,group:K,priority:1e3,preconditions(e){return G(e)&&W(e)}},pe={id:N.id,description:`find-replace.shortcut.focus-selection`,binding:r.KeyCode.ESC,group:K,priority:1e3,preconditions(e){return W(e)}},Y=`DESKTOP_FIND_REPLACE_DIALOG`,X=class extends t.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(){[ue,ce,le,fe,de,pe].forEach(e=>this.disposeWithMe(this._shortcutService.registerShortcut(e)))}_initUI(){[[`FindReplaceDialog`,re],[`SearchIcon`,B]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))}),this._menuManagerService.mergeMenu(ee),this._findReplaceService.stateUpdates$.pipe((0,a.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:me(),preservePositionOnDestroy:!0,onClose:()=>this.closePanel()}),this._closingListenerDisposable=(0,t.toDisposable)(this._univerInstanceService.focused$.pipe((0,a.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,t.IUniverInstanceService),h(1,r.IMenuManagerService),h(2,r.IShortcutService),h(3,t.ICommandService),h(4,v),h(5,r.IDialogService),h(6,r.ILayoutService),h(7,(0,t.Inject)(t.LocaleService)),h(8,(0,t.Inject)(r.ComponentManager))],X);function me(){let{innerWidth:e}=window;return{x:e-350-20,y:64}}var he=`@univerjs/find-replace`,ge=`0.18.0`;let Z=`find-replace.config`;Symbol(Z);let Q={},$=class extends t.Plugin{constructor(e=Q,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{...i}=(0,t.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`,he),m($,`version`,ge),$=g([h(1,(0,t.Inject)(t.Injector)),h(2,t.IConfigService)],$),e.FindBy=S,e.FindDirection=x,e.FindModel=_,Object.defineProperty(e,`FindReplaceController`,{enumerable:!0,get:function(){return X}}),Object.defineProperty(e,`FindReplaceModel`,{enumerable:!0,get:function(){return b}}),e.FindReplaceState=T,e.FindScope=C,e.GoToNextMatchOperation=j,e.GoToPreviousMatchOperation=M,e.IFindReplaceService=v,e.OpenFindDialogOperation=k,e.OpenReplaceDialogOperation=A,e.ReplaceAllMatchesCommand=O,e.ReplaceCurrentMatchCommand=D,Object.defineProperty(e,`UniverFindReplacePlugin`,{enumerable:!0,get:function(){return $}}),e.createInitFindReplaceState=w});
2
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/design`),require(`@univerjs/ui`),require(`@univerjs/engine-render`),require(`rxjs`),require(`react`),require(`react/jsx-runtime`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/design`,`@univerjs/ui`,`@univerjs/engine-render`,`rxjs`,`react`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverFindReplace={},e.UniverCore,e.UniverDesign,e.UniverUi,e.UniverEngineRender,e.rxjs,e.React,e.React))})(this,function(e,t,n,r,i,a,o,s){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let 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 t.Disposable{};let v=(0,t.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 t.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 a.BehaviorSubject(null)),m(this,`replaceables$`,new a.BehaviorSubject([])),m(this,`_findModels`,[]),m(this,`_matchingModel`,null),m(this,`_matches`,[]),m(this,`_currentSearchingDisposables`,null),this.disposeWithMe(this._state.stateUpdates$.pipe((0,a.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(e){let n=this._currentSearchingDisposables=new t.DisposableCollection,r=(0,a.combineLatest)(e.map(e=>e.matchesUpdate$)).pipe((0,a.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([]))});e.forEach(e=>n.add((0,t.toDisposable)(e.activelyChangingMatch$.subscribe(e=>{let t=this._matches.findIndex(t=>t===e);this._state.changeState({matchesPosition:t+1})})))),n.add((0,t.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,t.IUniverInstanceService),h(3,t.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 a.Subject),m(this,`stateUpdates$`,this._stateUpdates$.asObservable()),m(this,`_state$`,new a.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 t.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 a.BehaviorSubject(null)),m(this,`currentMatch$`,this._currentMatch$.asObservable()),m(this,`_replaceables$`,new a.BehaviorSubject([])),m(this,`replaceables$`,this._replaceables$.asObservable()),m(this,`_focusSignal$`,new a.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(e){return this._providers.add(e),(0,t.toDisposable)(()=>this._providers.delete(e))}_toggleRevealReplace(e){this._contextService.setContextValue(u,e)}_toggleDisplayRawFormula(e){this._contextService.setContextValue(i.RENDER_RAW_FORMULA_KEY,e)}};E=g([h(0,(0,t.Inject)(t.Injector)),h(1,t.IContextService)],E);let D={id:`ui.command.replace-current-match`,type:t.CommandType.COMMAND,handler:e=>e.get(v).replace()},O={id:`ui.command.replace-all-matches`,type:t.CommandType.COMMAND,handler:async e=>{let i=e.get(t.IConfirmService),a=e.get(t.LocaleService),o=e.get(r.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 e.get(v).replaceAll();return c>0?(s===0?o.show({type:n.MessageType.Error,content:a.t(`find-replace.replace.all-failure`)}):o.show({type:n.MessageType.Warning,content:a.t(`find-replace.replace.partial-success`,`${s}`,`${c}`)}),!1):(o.show({type:n.MessageType.Success,content:a.t(`find-replace.replace.all-success`,`${s}`)}),!0)}},k={id:`ui.operation.open-find-dialog`,type:t.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:t.CommandType.OPERATION,handler:e=>{let t=e.get(v);return t.revealed?t.replaceRevealed?t.focusFindInput():t.revealReplace():t.start(!0),!0}},j={type:t.CommandType.OPERATION,id:`ui.operation.go-to-next-match`,handler:e=>(e.get(v).moveToNextMatch(),!0)},M={type:t.CommandType.OPERATION,id:`ui.operation.go-to-previous-match`,handler:e=>(e.get(v).moveToPreviousMatch(),!0)},N={type:t.CommandType.OPERATION,id:`ui.operation.focus-selection`,handler:e=>(e.get(v).focusSelection(),!0)};function P({ref:e,...t}){let{icon:n,id:r,className:i,extend:a,...s}=t,c=`univerjs-icon univerjs-icon-${r} ${i||``}`.trim(),l=(0,o.useRef)(`_${R()}`);return F(n,`${r}`,{defIds:n.defIds,idSuffix:l.current},{ref:e,className:c,...s},a)}function F(e,t,n,r,i){return(0,o.createElement)(e.tag,{key:t,...I(e,n,i),...r},(L(e,n).children||[]).map((r,a)=>F(r,`${t}-${e.tag}-${a}`,n,void 0,i)))}function I(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),e.tag===`mask`&&r.id&&(r.id+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{e===`mask`&&typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});let{defIds:i}=t;return!i||i.length===0?r:(e.tag===`use`&&r[`xlink:href`]&&(r[`xlink:href`]+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))}),r)}function L(e,t){var n;let{defIds:r}=t;return!r||r.length===0?e:e.tag===`defs`&&(n=e.children)!=null&&n.length?{...e,children:e.children.map(e=>typeof e.attrs.id==`string`&&r&&r.includes(e.attrs.id)?{...e,attrs:{...e.attrs,id:e.attrs.id+t.idSuffix}}:e)}:e}function R(){return Math.random().toString(36).substring(2,8)}P.displayName=`UniverIcon`;let z={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M7.71899 1.36938C4.37604 1.36938 1.66602 4.07941 1.66602 7.42236C1.66602 10.7653 4.37604 13.4753 7.71899 13.4753C9.16744 13.4753 10.4971 12.9666 11.5389 12.118L13.6598 14.4109C13.8848 14.6542 14.2644 14.669 14.5077 14.444C14.7509 14.219 14.7657 13.8393 14.5407 13.5961L12.3906 11.2716C13.2536 10.2254 13.772 8.88442 13.772 7.42236C13.772 4.07941 11.0619 1.36938 7.71899 1.36938ZM2.86602 7.42236C2.86602 4.74215 5.03878 2.56938 7.71899 2.56938C10.3992 2.56938 12.572 4.74215 12.572 7.42236C12.572 10.1026 10.3992 12.2753 7.71899 12.2753C5.03878 12.2753 2.86602 10.1026 2.86602 7.42236Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},B=(0,o.forwardRef)(function(e,t){return(0,o.createElement)(P,Object.assign({},e,{id:`search-icon`,ref:t,icon:z}))});B.displayName=`SearchIcon`;function V(e){let n=e.get(t.IContextService);return{id:k.id,icon:`SearchIcon`,tooltip:`find-replace.toolbar`,type:r.MenuItemType.BUTTON,hidden$:(0,r.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:(0,a.combineLatest)([n.subscribeContextValue$(t.EDITOR_ACTIVATED),n.subscribeContextValue$(t.FOCUSING_SHEET)]).pipe((0,a.map)(([e,t])=>e||!t))}}let ee={[r.RibbonDataGroup.ORGANIZATION]:{[k.id]:{order:2,menuItemFactory:V}}};function H(e){let{findCompleted:t,localeService:r,matchesCount:i,matchesPosition:a,initialFindString:c,findReplaceService:l,onChange:u,...d}=e,[f,p]=(0,o.useState)(c),m=t&&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)(n.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)(n.Pager,{loop:!0,text:m,value:a,total:i,onChange:h}),...d})})}function U(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}}let te=(0,o.forwardRef)(function(e,n){let i=(0,r.useDependency)(t.LocaleService),a=(0,r.useDependency)(v),c=(0,r.useDependency)(t.ICommandService),{findCompleted:l,findString:u,matchesCount:d,matchesPosition:f}=(0,r.useObservable)(a.state$,void 0,!0),p=(0,o.useCallback)(()=>{c.executeCommand(A.id)},[c]),m=(0,r.useDebounceFn)(e=>a.changeFindString(e),500);return U(a,n),(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(H,{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`)})})]})}),ne=(0,o.forwardRef)(function(e,i){let a=(0,r.useDependency)(v),c=(0,r.useDependency)(t.LocaleService),l=(0,r.useDependency)(t.ICommandService),u=(0,r.useDependency)(r.IMessageService),d=(0,r.useObservable)(a.currentMatch$,void 0,!0),f=(0,r.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,r.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}=U(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]),I=(0,o.useCallback)(e=>{a.changeFindDirection(e)},[a]),L=(0,o.useCallback)(e=>{a.changeFindScope(e)},[a]),R=(0,o.useCallback)(e=>{a.changeFindBy(e)},[a]),z=ie(c),B=ae(c),V=oe(c);return(0,o.useEffect)(()=>{w&&p===0&&u.show({content:c.t(`find-replace.dialog.no-match`),type:n.MessageType.Warning,duration:5e3})},[w,p,u,c]),(0,s.jsxs)(`div`,{children:[(0,s.jsx)(n.FormLayout,{label:c.t(`find-replace.dialog.find`),children:(0,s.jsx)(H,{findCompleted:w,className:`univer-find-input`,matchesCount:p,matchesPosition:m,findReplaceService:a,localeService:c,initialFindString:g,onChange:A})}),(0,s.jsx)(n.FormLayout,{label:c.t(`find-replace.dialog.replace`),children:(0,s.jsx)(n.Input,{placeholder:c.t(`find-replace.dialog.replace-placeholder`),value:_,onChange:e=>j(e)})}),(0,s.jsx)(n.FormLayout,{label:c.t(`find-replace.dialog.find-direction.title`),children:(0,s.jsx)(n.Select,{value:x,options:B,onChange:I})}),(0,s.jsx)(n.FormDualColumnLayout,{children:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.FormLayout,{label:c.t(`find-replace.dialog.find-scope.title`),children:(0,s.jsx)(n.Select,{value:S,options:z,onChange:L})}),(0,s.jsx)(n.FormLayout,{label:c.t(`find-replace.dialog.find-by.title`),children:(0,s.jsx)(n.Select,{value:C,options:V,onChange:R})})]})}),(0,s.jsx)(n.FormDualColumnLayout,{children:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.FormLayout,{children:(0,s.jsx)(n.Checkbox,{checked:y,onChange:e=>{a.changeCaseSensitive(e)},children:c.t(`find-replace.dialog.case-sensitive`)})}),(0,s.jsx)(n.FormLayout,{children:(0,s.jsx)(n.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)(n.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)(n.Button,{disabled:E,onClick:P,children:c.t(`find-replace.dialog.replace`)}),(0,s.jsx)(n.Button,{disabled:k,onClick:F,children:c.t(`find-replace.dialog.replace-all`)})]})]})]})});function re(){let e=(0,r.useDependency)(v),n=(0,r.useDependency)(r.ILayoutService),i=(0,r.useDependency)(t.IContextService),u=(0,r.useObservable)(e.state$,void 0,!0),d=(0,o.useRef)(null);(0,o.useEffect)(()=>{let e;return d.current&&(e=n.registerContainerElement(d.current)),()=>e==null?void 0:e.dispose()},[n]);let f=(0,o.useRef)(null),p=(0,o.useCallback)(e=>i.setContextValue(l,e),[i]),m=(0,o.useCallback)(e=>i.setContextValue(c,e),[i]);return(0,o.useEffect)(()=>{var e;let t=(0,a.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)(ne,{ref:f}):(0,s.jsx)(te,{ref:f})})}function ie(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 ae(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 oe(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 W(e){return e.getContextValue(l)}function se(e){return e.getContextValue(u)}function G(e){return e.getContextValue(c)}let K=`7_find-replace-shortcuts`;function q(e){return e.getContextValue(t.FOCUSING_SHEET)}function J(e){return!e.getContextValue(t.EDITOR_ACTIVATED)}let ce={id:k.id,description:`find-replace.shortcut.open-find-dialog`,binding:r.KeyCode.F|r.MetaKeys.CTRL_COMMAND,group:K,preconditions(e){return!W(e)&&q(e)&&J(e)}},le={id:k.id,description:`find-replace.shortcut.open-find-dialog`,binding:r.KeyCode.F|r.MetaKeys.CTRL_COMMAND,mac:r.KeyCode.F|r.MetaKeys.MAC_CTRL,preconditions(e){return!W(e)&&q(e)&&J(e)}},ue={id:A.id,description:`find-replace.shortcut.open-replace-dialog`,binding:r.KeyCode.H|r.MetaKeys.CTRL_COMMAND,mac:r.KeyCode.H|r.MetaKeys.MAC_CTRL,group:K,preconditions(e){return q(e)&&J(e)&&(!W(e)||!se(e))}},de={id:j.id,description:`find-replace.shortcut.go-to-next-match`,binding:r.KeyCode.ENTER,group:K,priority:1e3,preconditions(e){return G(e)&&W(e)}},fe={id:M.id,description:`find-replace.shortcut.go-to-previous-match`,binding:r.KeyCode.ENTER|r.MetaKeys.SHIFT,group:K,priority:1e3,preconditions(e){return G(e)&&W(e)}},pe={id:N.id,description:`find-replace.shortcut.focus-selection`,binding:r.KeyCode.ESC,group:K,priority:1e3,preconditions(e){return W(e)}},Y=`DESKTOP_FIND_REPLACE_DIALOG`,X=class extends t.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(){[ue,ce,le,fe,de,pe].forEach(e=>this.disposeWithMe(this._shortcutService.registerShortcut(e)))}_initUI(){[[`FindReplaceDialog`,re],[`SearchIcon`,B]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))}),this._menuManagerService.mergeMenu(ee),this._findReplaceService.stateUpdates$.pipe((0,a.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:me(),preservePositionOnDestroy:!0,onClose:()=>this.closePanel()}),this._closingListenerDisposable=(0,t.toDisposable)(this._univerInstanceService.focused$.pipe((0,a.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,t.IUniverInstanceService),h(1,r.IMenuManagerService),h(2,r.IShortcutService),h(3,t.ICommandService),h(4,v),h(5,r.IDialogService),h(6,r.ILayoutService),h(7,(0,t.Inject)(t.LocaleService)),h(8,(0,t.Inject)(r.ComponentManager))],X);function me(){let{innerWidth:e}=window;return{x:e-350-20,y:64}}var he=`@univerjs/find-replace`,ge=`0.19.0`;let Z=`find-replace.config`;Symbol(Z);let Q={},$=class extends t.Plugin{constructor(e=Q,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{...i}=(0,t.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`,he),m($,`version`,ge),$=g([h(1,(0,t.Inject)(t.Injector)),h(2,t.IConfigService)],$),e.FindBy=S,e.FindDirection=x,e.FindModel=_,Object.defineProperty(e,`FindReplaceController`,{enumerable:!0,get:function(){return X}}),Object.defineProperty(e,`FindReplaceModel`,{enumerable:!0,get:function(){return b}}),e.FindReplaceState=T,e.FindScope=C,e.GoToNextMatchOperation=j,e.GoToPreviousMatchOperation=M,e.IFindReplaceService=v,e.OpenFindDialogOperation=k,e.OpenReplaceDialogOperation=A,e.ReplaceAllMatchesCommand=O,e.ReplaceCurrentMatchCommand=D,Object.defineProperty(e,`UniverFindReplacePlugin`,{enumerable:!0,get:function(){return $}}),e.createInitFindReplaceState=w});
6
3
 
7
4
  // @univerjs/sheets-find-replace/index
8
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/sheets`),require(`@univerjs/engine-render`),require(`@univerjs/find-replace`),require(`@univerjs/sheets-ui`),require(`rxjs`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets`,`@univerjs/engine-render`,`@univerjs/find-replace`,`@univerjs/sheets-ui`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsFindReplace={},e.UniverCore,e.UniverSheets,e.UniverEngineRender,e.UniverFindReplace,e.UniverSheetsUi,e.rxjs))})(this,function(e,t,n,r,i,a,o){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let s={id:`sheet.command.replace`,type:t.CommandType.COMMAND,handler:async(e,r)=>{let i=e.get(t.IUndoRedoService),a=e.get(t.ICommandService),{unitId:o,replacements:s}=r,l=i.__tempBatchingUndoRedo(o),u=await Promise.all(s.map(e=>a.executeCommand(n.SetRangeValuesCommand.id,{unitId:o,subUnitId:e.subUnitId,value:e.value})));return l.dispose(),c(u,s)}};function c(e,t){let n=0,r=0;return e.forEach((e,i)=>{let a=t[i].count;e?n+=a:r+=a}),{success:n,failure:r}}function l(e){"@babel/helpers - typeof";return l=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},l(e)}function u(e,t){if(l(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(l(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function d(e){var t=u(e,`string`);return l(t)==`symbol`?t:t+``}function f(e,t,n){return(t=d(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var p=class extends r.Shape{constructor(e,t){super(e,t),f(this,`_activated`,!1),f(this,`_inHiddenRange`,!1),f(this,`_color`,void 0),t&&this.setShapeProps(t)}setShapeProps(e){this._activated=!!e.activated,e.inHiddenRange!==void 0&&(this._inHiddenRange=e.inHiddenRange),e.color!==void 0&&(this._color=e.color),this.transformByState({width:e.width,height:e.height})}_draw(e){let t=this._activated,n=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 0.35)`,i=`rgb(${this._color.r}, ${this._color.g}, ${this._color.b})`;r.Rect.drawWith(e,{width:this.width,height:this.height,fill:n,stroke:t?i:void 0,strokeWidth:t?2:0,evented:!1})}};function m(e,t){return e.startRow===t.startRow&&e.startColumn===t.startColumn}function h(e,t){return e.startRow<t.startRow||e.startRow===t.startRow&&e.startColumn<=t.startColumn}function g(e,t){return e.startColumn<t.startColumn||e.startColumn===t.startColumn&&e.startRow<=t.startRow}function _(e,t){return e.startRow>t.startRow||e.startRow===t.startRow&&e.startColumn>=t.startColumn}function v(e,t){return e.startColumn>t.startColumn||e.startColumn===t.startColumn&&e.startRow>=t.startRow}function y(e,n){let{range:r}=e,{startRow:i,startColumn:a}=r,o=n.getMergedCell(i,a);return o?t.Rectangle.equals(r,o):r.endRow===r.startRow&&r.endColumn===r.startColumn}function b(e,t){return function(n,r){t(n,r,e)}}function x(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}let S=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._injector=e,this._findReplaceController=t,this._contextService=n,this._findReplaceService=r,this._commandService=i,f(this,`_provider`,void 0),this._init(),this._initCommands()}dispose(){super.dispose(),this._findReplaceController.closePanel(),this._provider.dispose()}_init(){let e=this._injector.createInstance(T);this._provider=e,this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(e)),this.disposeWithMe(this._contextService.subscribeContextValue$(t.EDITOR_ACTIVATED).pipe((0,o.filter)(e=>!!e)).subscribe(()=>this._findReplaceController.closePanel()))}_initCommands(){[s].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}};S=x([b(0,(0,t.Inject)(t.Injector)),b(1,(0,t.Inject)(i.FindReplaceController)),b(2,t.IContextService),b(3,i.IFindReplaceService),b(4,t.ICommandService)],S);let C=class extends i.FindModel{get _matchesCount(){return this._matches.length}get unitId(){return this._workbook.getUnitId()}get matchesCount(){return this._matchesCount}get matchesPosition(){return this._matchesPosition}get currentMatch(){return this._matchesPosition>0?this._matches[this._matchesPosition-1]:null}constructor(e,t,n,r,i,a,s,c){super(),this._workbook=e,this._sheetSkeletonManagerService=t,this._univerInstanceService=n,this._renderManagerService=r,this._commandService=i,this._contextService=a,this._themeService=s,f(this,`_matchesUpdate$`,new o.Subject),f(this,`matchesUpdate$`,this._matchesUpdate$.asObservable()),f(this,`_activelyChangingMatch$`,new o.Subject),f(this,`activelyChangingMatch$`,this._activelyChangingMatch$.asObservable()),f(this,`_matchesByWorksheet`,new Map),f(this,`_matches`,[]),f(this,`_matchesPosition`,0),f(this,`_activeHighlightIndex`,-1),f(this,`_highlightShapes`,[]),f(this,`_currentHighlightShape`,null),f(this,`_query`,null),f(this,`_workbookSelections`,void 0),this._workbookSelections=c.getWorkbookSelections(this.unitId)}dispose(){super.dispose(),this._disposeHighlights(),this._toggleDisplayRawFormula(!1)}getMatches(){return this._matches}start(e){switch(this._query=e,e.findBy===i.FindBy.FORMULA?this._toggleDisplayRawFormula(!0):this._toggleDisplayRawFormula(!1),e.findScope){case i.FindScope.UNIT:this.findInWorkbook(e);break;case i.FindScope.SUBUNIT:default:this.findInActiveWorksheet(e);break}}focusSelection(){let e=this.currentMatch;e&&this._commandService.executeCommand(n.SelectRangeCommand.id,{unitId:e.unitId,subUnit:e.range.subUnitId,range:e.range.range})}_toggleDisplayRawFormula(e){this._contextService.setContextValue(r.RENDER_RAW_FORMULA_KEY,e)}findInWorkbook(e){let r=this._workbook.getUnitId(),i,a=!0,s=()=>{this._matches=this._workbook.getSheets().filter(e=>!e.isSheetHidden()).map(t=>{let n=this._findInWorksheet(t,e,r),i=t.getSheetId(),{results:a}=n;return a.length?this._matchesByWorksheet.set(i,n.results):this._matchesByWorksheet.delete(i),n}).map(e=>e.results).flat(),this._updateFindHighlight(),a?(i={results:this._matches},a=!1):this._matchesUpdate$.next(this._matches)};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>{this._updateFindHighlight(),this._updateCurrentHighlightShape(this._activeHighlightIndex)})),this.disposeWithMe((0,t.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0,o.filter)(([e,t])=>e.id===n.SetWorksheetActiveOperation.id&&!(t!=null&&t.fromFindReplace))).subscribe(()=>{let e=this._workbook.getActiveSheet();if(!e)return;let t=e.getSheetId();this._matchesByWorksheet.has(t)&&this._findNextMatchOnActiveSheetChange(e)})),this.disposeWithMe((0,t.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0,o.filter)(([e])=>e.type===t.CommandType.MUTATION&&e.params.unitId===this._workbook.getUnitId()),(0,o.throttleTime)(600,void 0,{leading:!1,trailing:!0})).subscribe(()=>s())),s(),i}_findNextMatchOnActiveSheetChange(e){let t,n,r=0,i=this._matchesByWorksheet.get(e.getSheetId()),a=this._workbookSelections.getCurrentSelections();a!=null&&a.length?([t,r]=this._findNextMatchByRange(i,a[0].range),n=i.findIndex(e=>e===t)):(t=i[0],n=0,r=this._matches.findIndex(e=>e===t)),this._matchesPosition=r+1,this._activelyChangingMatch$.next(t),this._activeHighlightIndex=n,this._updateFindHighlight(),this._updateCurrentHighlightShape(n)}findInActiveWorksheet(e){let r=this._workbook.getUnitId(),i=()=>{var e;let t=this._workbook.getActiveSheet();if(!t)return!1;let n=this._workbookSelections.getCurrentSelections();return(e=n==null?void 0:n.some(e=>!y(e,t)))==null?!1:e},a,s=!0,c=!1,l=()=>{let t=this._workbook.getActiveSheet();if(!t)return{results:[]};let n=this.currentMatch;c=i();let o=this._workbookSelections.getCurrentSelections(),l=c?this._findInSelections(t,o,e,r):this._findInWorksheet(t,e,r);return this._matches=l.results,this._matchesPosition=this._tryRestoreLastMatchesPosition(n,this._matches),s?(a=l,s=!1):this._matchesUpdate$.next(this._matches),this._updateFindHighlight(),l};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>this._updateFindHighlight())),this.disposeWithMe((0,o.merge)((0,t.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0,o.filter)(([e])=>{if(e.type===t.CommandType.MUTATION&&e.params.unitId===this._workbook.getUnitId())return!0;if(e.id===n.SetSelectionsOperation.id&&e.params.unitId===r){let e=i();return e===!1&&c===!1?!1:(c=e,!0)}return!1})),this._workbook.activeSheet$.pipe((0,o.skip)(1))).pipe((0,o.debounceTime)(200)).subscribe(()=>l())),l(),a}_findInRange(e,t,n,r,a){let o=[],s=e.getSheetId(),c=(t.findDirection===i.FindDirection.COLUMN?e.iterateByColumn:e.iterateByRow).bind(e)(n);for(let n of c){let{row:i,col:c,colSpan:l,rowSpan:u,value:d}=n;if(a!=null&&a(i,c)||!d||e.getRowFiltered(i))continue;let{hit:f,replaceable:p,isFormula:m}=D(e,i,c,t,d);if(f){let e={provider:`sheets-find-replace-provider`,unitId:r,replaceable:p,isFormula:m,range:{subUnitId:s,range:{startRow:i,startColumn:c,endColumn:c+(l==null?1:l)-1,endRow:i+(u==null?1:u)-1}}};o.push(e)}}return{results:o}}_findInSelections(e,t,n,r){let{findDirection:a}=n,o=a===i.FindDirection.ROW?h:g,s=new Set;return{results:t.map(t=>this._findInRange(e,n,t.range,r,(e,t)=>{let n=`${e}-${t}`;return s.has(n)?!0:(s.add(n),!1)}).results).flat().sort((e,t)=>o(e.range.range,t.range.range)?-1:1)}}_findInWorksheet(e,t,n){let r=e.getRowCount(),i=e.getColumnCount(),a={startRow:0,startColumn:0,endRow:r-1,endColumn:i-1};return this._findInRange(e,t,a,n)}_disposeHighlights(){var e;this._highlightShapes.forEach(e=>{var t;(t=e.getScene())==null||t.makeDirty(),e.dispose()}),this._highlightShapes=[],(e=this._currentHighlightShape)==null||e.dispose(),this._currentHighlightShape=null}_updateFindHighlight(){var e;this._disposeHighlights();let n=(e=this._sheetSkeletonManagerService.getCurrent())==null?void 0:e.skeleton;if(!n)return;let r=this._workbook.getUnitId(),i=this._renderManagerService.getRenderById(r);if(i==null)return;let{scene:o}=i,s=this._matches,c=new t.ColorKit(this._themeService.getColorFromTheme(`yellow.400`)).toRgb(),l=this._workbook.getActiveSheet();if(!l)return;let u=l.getSheetId(),d=s.filter(e=>e.range.subUnitId===u).map((e,t)=>{let{startColumn:r,startRow:i,endColumn:s,endRow:u}=e.range.range,d=(0,a.getCoordByCell)(i,r,o,n),f=(0,a.getCoordByCell)(u,s,o,n),{startX:m,startY:h}=d,{endX:g,endY:_}=f,v=!0;for(let e=i;e<=u;e++)if(l.getRowRawVisible(e)){v=!1;break}let y=!0;for(let e=r;e<=s;e++)if(l.getColVisible(e)){y=!1;break}let b=v||y,x={left:m,top:h,color:c,width:y?2:g-m,height:v?2:_-h,evented:!1,inHiddenRange:b,zIndex:1e4};return new p(`find-highlight-${t}`,x)});o.addObjects(d),this._highlightShapes=d,o.makeDirty()}_updateCurrentHighlightShape(e){var t;if((t=this._currentHighlightShape)==null||t.setShapeProps({activated:!1}),this._currentHighlightShape=null,e!==void 0){let t=this._highlightShapes[e];if(!t)return;this._currentHighlightShape=t,t.setShapeProps({activated:!0})}}_getSheetObject(){return(0,a.getSheetObject)(this._univerInstanceService,this._renderManagerService)}_focusMatch(e){var t;let r=e.range.subUnitId;r!==((t=this._workbook.getActiveSheet())==null?void 0:t.getSheetId())&&this._commandService.executeCommand(n.SetWorksheetActivateCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:r},{fromFindReplace:!0}),this._commandService.executeCommand(a.ScrollToCellCommand.id,{range:e.range.range},{fromFindReplace:!0})}_tryRestoreLastMatchesPosition(e,t){if(!e)return 0;let{subUnitId:n}=e.range,{startColumn:r,startRow:i}=e.range.range,a=t.findIndex(e=>{if(n!==e.range.subUnitId)return!1;let{startColumn:t,startRow:a}=e.range.range;return t===r&&a===i});return a>-1?a+1:0}moveToNextMatch(e){var t,n,r,a;if(!this._matches.length)return null;let o=(t=e==null?void 0:e.loop)==null?!1:t,s=(n=e==null?void 0:e.stayIfOnMatch)==null?!1:n,c=(r=e==null?void 0:e.noFocus)==null?!1:r,l=(a=e==null?void 0:e.ignoreSelection)==null?!1:a,u=this._findNextMatch(o,s,l);if(u){var d;let[e,t]=u;return this._matchesPosition=t+1,this._query.findScope===i.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(e.range.subUnitId).findIndex(t=>t===e):this._activeHighlightIndex=t,c||this._focusMatch(e),((d=this._workbook.getActiveSheet())==null?void 0:d.getSheetId())===e.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),e}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}moveToPreviousMatch(e){var t,n,r,a;if(!this._matches.length)return null;let o=(t=e==null?void 0:e.loop)==null?!1:t,s=(n=e==null?void 0:e.stayIfOnMatch)==null?!1:n,c=(r=e==null?void 0:e.noFocus)==null?!1:r,l=(a=e==null?void 0:e.ignoreSelection)==null?!1:a,u=this._findPreviousMatch(o,s,l);if(u){var d;let[e,t]=u;return this._matchesPosition=t+1,this._query.findScope===i.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(e.range.subUnitId).findIndex(t=>t===e):this._activeHighlightIndex=t,c||this._focusMatch(e),((d=this._workbook.getActiveSheet())==null?void 0:d.getSheetId())===e.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),e}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}_findPreviousMatch(e=!1,t=!1,n=!1){var r;if(this.currentMatch){let n=this._matches.findIndex(e=>e===this.currentMatch);if(t)return[this.currentMatch,n];let r=n-1;if(!e&&r<0)return null;let i=this._matches.length,a=(r+i)%i;return[this._matches[a],a]}let a=this._workbookSelections.getCurrentLastSelection();if(n||!a){let e=this._matches.length-1;return[this._matches[e],e]}if(this._query.findScope!==i.FindScope.UNIT)return this._findPreviousMatchByRange(this._matches,a.range);let o=(r=this._workbook.getActiveSheet())==null?void 0:r.getSheetId();if(!o)return null;let s=this._findPreviousWorksheetThatHasAMatch(o,e);return s?this._findPreviousMatchByRange(this._matchesByWorksheet.get(s),a.range):null}_findNextMatch(e=!1,t=!1,n=!1){var r;if(this.currentMatch){let n=this._matches.findIndex(e=>e===this.currentMatch);if(t)return[this.currentMatch,n];let r=n+1,i=this._matches.length;if(!e&&r>=i)return null;let a=r%i;return[this._matches[a],a]}let a=this._workbookSelections.getCurrentLastSelection();if(n||!a)return[this._matches[0],0];if(this._query.findScope!==i.FindScope.UNIT)return this._findNextMatchByRange(this._matches,a.range,t);let o=(r=this._workbook.getActiveSheet())==null?void 0:r.getSheetId();if(!o)return null;let s=this._findNextWorksheetThatHasAMatch(o,e);return s?this._findNextMatchByRange(this._matchesByWorksheet.get(s),a.range):null}_findPreviousWorksheetThatHasAMatch(e,n=!1){let r=this._workbook.getSheetOrders(),i=r.findIndex(t=>t===e),a=(n?(0,t.rotate)(r,i+1):r.slice(0,i+1)).findLast(e=>this._matchesByWorksheet.has(e));return a==null?null:a}_findNextWorksheetThatHasAMatch(e,n=!1){let r=this._workbook.getSheetOrders(),i=r.findIndex(t=>t===e),a=(n?(0,t.rotate)(r,i):r.slice(i)).find(e=>this._matchesByWorksheet.has(e));return a==null?null:a}_findNextMatchByRange(e,t,n=!1){let r=this._query.findDirection===i.FindDirection.ROW,a=e.findIndex(e=>{let i=e.range.range;if(!(r?h(t,i):g(t,i)))return!1;let a=m(t,i);return n?a:!a});a===-1&&(a=e.length-1);let o=e[a];return[o,this._matches.findIndex(e=>e===o)]}_findPreviousMatchByRange(e,t,n=!1){let r=this._query.findDirection===i.FindDirection.ROW,a=this._matches.findLastIndex(e=>{let i=e.range.range;if(!(r?_(t,i):v(t,i)))return!1;let a=m(t,i);return n?a:!a});a===-1&&(a=0);let o=e[a];return[o,this._matches.findIndex(e=>e===o)]}async replace(e){if(this._matchesCount===0||!this.currentMatch||!this._query||!this.currentMatch.replaceable)return!1;let t=this.currentMatch.range,r=this._workbook.getSheetBySheetId(this.currentMatch.range.subUnitId),a=this._getReplacedCellData(this.currentMatch,r,this._query.findBy===i.FindBy.FORMULA,this._query.findString,e,this._query.caseSensitive?`g`:`ig`),o={unitId:this.currentMatch.unitId,subUnitId:t.subUnitId,value:{[t.range.startRow]:{[t.range.startColumn]:a}}};return this._commandService.executeCommand(n.SetRangeValuesCommand.id,o)}async replaceAll(e){if(this._matchesCount===0||!this._query)return{success:0,failure:0};let n=this._workbook.getUnitId(),{findString:r,caseSensitive:a,findBy:o}=this._query,c=o===i.FindBy.FORMULA,l=a?`g`:`ig`,u=[];return(0,t.groupBy)(this._matches.filter(e=>e.replaceable),e=>e.range.subUnitId).forEach((n,i)=>{let a=new t.ObjectMatrix,o=this._workbook.getSheetBySheetId(i);n.forEach(t=>{let{startColumn:n,startRow:i}=t.range.range,s=this._getReplacedCellData(t,o,c,r,e,l);s&&a.setValue(i,n,s)}),u.push({count:n.length,subUnitId:i,value:a.getMatrix()})}),u?this._commandService.executeCommand(s.id,{unitId:n,replacements:u}):{success:0,failure:0}}_getReplacedCellData(e,n,r,i,a,o){var s;let{startRow:c,startColumn:l}=e.range.range,u=n.getCellRaw(c,l);if(e.isFormula)return r?{f:u.f.replace(new RegExp(w(i),o),a),v:null}:null;if((s=u.p)!=null&&s.body){let e=t.Tools.deepClone(u.p);return(0,t.replaceInDocumentBody)(e.body,i,a,this._query.caseSensitive),{p:e}}return{v:u.v.toString().replace(new RegExp(w(i),o),a)}}};C=x([b(2,t.IUniverInstanceService),b(3,r.IRenderManagerService),b(4,t.ICommandService),b(5,t.IContextService),b(6,(0,t.Inject)(t.ThemeService)),b(7,(0,t.Inject)(n.SheetsSelectionsService))],C);function w(e){return e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,`\\$&`)}let T=class extends t.Disposable{constructor(e,t,n){super(),this._univerInstanceService=e,this._renderManagerService=t,this._injector=n,f(this,`_findModelsByUnitId`,new Map)}async find(e){this._terminate();let n=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET);if(!n)return[];let r=this._preprocessQuery(e),i=this._renderManagerService.getRenderById(n.getUnitId()).with(a.SheetSkeletonManagerService),o=this._injector.createInstance(C,n,i);return this._findModelsByUnitId.set(n.getUnitId(),o),o.start(r),[o]}terminate(){this._terminate()}_terminate(){this._findModelsByUnitId.forEach(e=>e.dispose()),this._findModelsByUnitId.clear()}_preprocessQuery(e){let t=e.caseSensitive?e.findString:e.findString.toLowerCase();return t=t.trim(),{...e,findString:t}}};T=x([b(0,t.IUniverInstanceService),b(1,r.IRenderManagerService),b(2,(0,t.Inject)(t.Injector))],T);let E={hit:!1,replaceable:!1,isFormula:!1,rawData:null};function D(e,t,n,r,a){let{findBy:o}=r,s=o===i.FindBy.FORMULA,c=e.getCellRaw(t,n);return E.rawData=c,c!=null&&c.f?(E.isFormula=!0,s?O({v:c.f},r)?(E.hit=!0,E.replaceable=!0,E):(E.hit=!1,E.replaceable=!1,E):(E.replaceable=!1,O(a,r)?E.hit=!0:E.hit=!1,E)):(E.isFormula=!1,O(a,r)?c?(E.hit=!0,E.replaceable=!0):(E.hit=!0,E.replaceable=!1):(E.hit=!1,E.replaceable=!1),E)}function O(e,t){let n=k(e);return n?t.matchesTheWholeCell?(n=A(n),t.caseSensitive?n===t.findString:n.toLowerCase()===t.findString):t.caseSensitive?n.indexOf(t.findString)>-1:n.toLowerCase().indexOf(t.findString)>-1:!1}function k(e){var t,n;let r=(t=e==null||(n=e.p)==null||(n=n.body)==null?void 0:n.dataStream)==null?e==null?void 0:e.v:t;return typeof r==`number`?`${r}`:typeof r==`boolean`?r?`1`:`0`:r}function A(e){return e.replace(/^ +/g,``).replace(/ +$/g,``)}var j=`@univerjs/sheets-find-replace`,M=`0.18.0`;let N=`sheets-find-replace.config`;Symbol(N);let P={},F=class extends t.Plugin{constructor(e=P,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{...i}=(0,t.merge)({},P,this._config);this._configService.setConfig(N,i)}onStarting(){[[S]].forEach(e=>this._injector.add(e))}onSteady(){this._injector.get(S)}};f(F,`pluginName`,`SHEET_FIND_REPLACE_PLUGIN`),f(F,`packageName`,j),f(F,`version`,M),f(F,`type`,t.UniverInstanceType.UNIVER_SHEET),F=x([(0,t.DependentOn)(n.UniverSheetsPlugin,n.UniverSheetsPlugin,i.UniverFindReplacePlugin),b(1,(0,t.Inject)(t.Injector)),b(2,t.IConfigService)],F),e.SheetReplaceCommand=s,Object.defineProperty(e,`SheetsFindReplaceController`,{enumerable:!0,get:function(){return S}}),Object.defineProperty(e,`UniverSheetsFindReplacePlugin`,{enumerable:!0,get:function(){return F}})});
5
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/sheets`),require(`@univerjs/engine-render`),require(`@univerjs/find-replace`),require(`@univerjs/sheets-ui`),require(`rxjs`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets`,`@univerjs/engine-render`,`@univerjs/find-replace`,`@univerjs/sheets-ui`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsFindReplace={},e.UniverCore,e.UniverSheets,e.UniverEngineRender,e.UniverFindReplace,e.UniverSheetsUi,e.rxjs))})(this,function(e,t,n,r,i,a,o){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let s={id:`sheet.command.replace`,type:t.CommandType.COMMAND,handler:async(e,r)=>{let i=e.get(t.IUndoRedoService),a=e.get(t.ICommandService),{unitId:o,replacements:s}=r,l=i.__tempBatchingUndoRedo(o),u=await Promise.all(s.map(e=>a.executeCommand(n.SetRangeValuesCommand.id,{unitId:o,subUnitId:e.subUnitId,value:e.value})));return l.dispose(),c(u,s)}};function c(e,t){let n=0,r=0;return e.forEach((e,i)=>{let a=t[i].count;e?n+=a:r+=a}),{success:n,failure:r}}function l(e){"@babel/helpers - typeof";return l=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},l(e)}function u(e,t){if(l(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(l(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function d(e){var t=u(e,`string`);return l(t)==`symbol`?t:t+``}function f(e,t,n){return(t=d(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var p=class extends r.Shape{constructor(e,t){super(e,t),f(this,`_activated`,!1),f(this,`_inHiddenRange`,!1),f(this,`_color`,void 0),t&&this.setShapeProps(t)}setShapeProps(e){this._activated=!!e.activated,e.inHiddenRange!==void 0&&(this._inHiddenRange=e.inHiddenRange),e.color!==void 0&&(this._color=e.color),this.transformByState({width:e.width,height:e.height})}_draw(e){let t=this._activated,n=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 0.35)`,i=`rgb(${this._color.r}, ${this._color.g}, ${this._color.b})`;r.Rect.drawWith(e,{width:this.width,height:this.height,fill:n,stroke:t?i:void 0,strokeWidth:t?2:0,evented:!1})}};function m(e,t){return e.startRow===t.startRow&&e.startColumn===t.startColumn}function h(e,t){return e.startRow<t.startRow||e.startRow===t.startRow&&e.startColumn<=t.startColumn}function g(e,t){return e.startColumn<t.startColumn||e.startColumn===t.startColumn&&e.startRow<=t.startRow}function _(e,t){return e.startRow>t.startRow||e.startRow===t.startRow&&e.startColumn>=t.startColumn}function v(e,t){return e.startColumn>t.startColumn||e.startColumn===t.startColumn&&e.startRow>=t.startRow}function y(e,n){let{range:r}=e,{startRow:i,startColumn:a}=r,o=n.getMergedCell(i,a);return o?t.Rectangle.equals(r,o):r.endRow===r.startRow&&r.endColumn===r.startColumn}function b(e,t){return function(n,r){t(n,r,e)}}function x(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}let S=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._injector=e,this._findReplaceController=t,this._contextService=n,this._findReplaceService=r,this._commandService=i,f(this,`_provider`,void 0),this._init(),this._initCommands()}dispose(){super.dispose(),this._findReplaceController.closePanel(),this._provider.dispose()}_init(){let e=this._injector.createInstance(T);this._provider=e,this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(e)),this.disposeWithMe(this._contextService.subscribeContextValue$(t.EDITOR_ACTIVATED).pipe((0,o.filter)(e=>!!e)).subscribe(()=>this._findReplaceController.closePanel()))}_initCommands(){[s].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}};S=x([b(0,(0,t.Inject)(t.Injector)),b(1,(0,t.Inject)(i.FindReplaceController)),b(2,t.IContextService),b(3,i.IFindReplaceService),b(4,t.ICommandService)],S);let C=class extends i.FindModel{get _matchesCount(){return this._matches.length}get unitId(){return this._workbook.getUnitId()}get matchesCount(){return this._matchesCount}get matchesPosition(){return this._matchesPosition}get currentMatch(){return this._matchesPosition>0?this._matches[this._matchesPosition-1]:null}constructor(e,t,n,r,i,a,s,c){super(),this._workbook=e,this._sheetSkeletonManagerService=t,this._univerInstanceService=n,this._renderManagerService=r,this._commandService=i,this._contextService=a,this._themeService=s,f(this,`_matchesUpdate$`,new o.Subject),f(this,`matchesUpdate$`,this._matchesUpdate$.asObservable()),f(this,`_activelyChangingMatch$`,new o.Subject),f(this,`activelyChangingMatch$`,this._activelyChangingMatch$.asObservable()),f(this,`_matchesByWorksheet`,new Map),f(this,`_matches`,[]),f(this,`_matchesPosition`,0),f(this,`_activeHighlightIndex`,-1),f(this,`_highlightShapes`,[]),f(this,`_currentHighlightShape`,null),f(this,`_query`,null),f(this,`_workbookSelections`,void 0),this._workbookSelections=c.getWorkbookSelections(this.unitId)}dispose(){super.dispose(),this._disposeHighlights(),this._toggleDisplayRawFormula(!1)}getMatches(){return this._matches}start(e){switch(this._query=e,e.findBy===i.FindBy.FORMULA?this._toggleDisplayRawFormula(!0):this._toggleDisplayRawFormula(!1),e.findScope){case i.FindScope.UNIT:this.findInWorkbook(e);break;case i.FindScope.SUBUNIT:default:this.findInActiveWorksheet(e);break}}focusSelection(){let e=this.currentMatch;e&&this._commandService.executeCommand(n.SelectRangeCommand.id,{unitId:e.unitId,subUnit:e.range.subUnitId,range:e.range.range})}_toggleDisplayRawFormula(e){this._contextService.setContextValue(r.RENDER_RAW_FORMULA_KEY,e)}findInWorkbook(e){let r=this._workbook.getUnitId(),i,a=!0,s=()=>{this._matches=this._workbook.getSheets().filter(e=>!e.isSheetHidden()).map(t=>{let n=this._findInWorksheet(t,e,r),i=t.getSheetId(),{results:a}=n;return a.length?this._matchesByWorksheet.set(i,n.results):this._matchesByWorksheet.delete(i),n}).map(e=>e.results).flat(),this._updateFindHighlight(),a?(i={results:this._matches},a=!1):this._matchesUpdate$.next(this._matches)};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>{this._updateFindHighlight(),this._updateCurrentHighlightShape(this._activeHighlightIndex)})),this.disposeWithMe((0,t.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0,o.filter)(([e,t])=>e.id===n.SetWorksheetActiveOperation.id&&!(t!=null&&t.fromFindReplace))).subscribe(()=>{let e=this._workbook.getActiveSheet();if(!e)return;let t=e.getSheetId();this._matchesByWorksheet.has(t)&&this._findNextMatchOnActiveSheetChange(e)})),this.disposeWithMe((0,t.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0,o.filter)(([e])=>e.type===t.CommandType.MUTATION&&e.params.unitId===this._workbook.getUnitId()),(0,o.throttleTime)(600,void 0,{leading:!1,trailing:!0})).subscribe(()=>s())),s(),i}_findNextMatchOnActiveSheetChange(e){let t,n,r=0,i=this._matchesByWorksheet.get(e.getSheetId()),a=this._workbookSelections.getCurrentSelections();a!=null&&a.length?([t,r]=this._findNextMatchByRange(i,a[0].range),n=i.findIndex(e=>e===t)):(t=i[0],n=0,r=this._matches.findIndex(e=>e===t)),this._matchesPosition=r+1,this._activelyChangingMatch$.next(t),this._activeHighlightIndex=n,this._updateFindHighlight(),this._updateCurrentHighlightShape(n)}findInActiveWorksheet(e){let r=this._workbook.getUnitId(),i=()=>{var e;let t=this._workbook.getActiveSheet();if(!t)return!1;let n=this._workbookSelections.getCurrentSelections();return(e=n==null?void 0:n.some(e=>!y(e,t)))==null?!1:e},a,s=!0,c=!1,l=()=>{let t=this._workbook.getActiveSheet();if(!t)return{results:[]};let n=this.currentMatch;c=i();let o=this._workbookSelections.getCurrentSelections(),l=c?this._findInSelections(t,o,e,r):this._findInWorksheet(t,e,r);return this._matches=l.results,this._matchesPosition=this._tryRestoreLastMatchesPosition(n,this._matches),s?(a=l,s=!1):this._matchesUpdate$.next(this._matches),this._updateFindHighlight(),l};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>this._updateFindHighlight())),this.disposeWithMe((0,o.merge)((0,t.fromCallback)(this._commandService.onCommandExecuted.bind(this._commandService)).pipe((0,o.filter)(([e])=>{if(e.type===t.CommandType.MUTATION&&e.params.unitId===this._workbook.getUnitId())return!0;if(e.id===n.SetSelectionsOperation.id&&e.params.unitId===r){let e=i();return e===!1&&c===!1?!1:(c=e,!0)}return!1})),this._workbook.activeSheet$.pipe((0,o.skip)(1))).pipe((0,o.debounceTime)(200)).subscribe(()=>l())),l(),a}_findInRange(e,t,n,r,a){let o=[],s=e.getSheetId(),c=(t.findDirection===i.FindDirection.COLUMN?e.iterateByColumn:e.iterateByRow).bind(e)(n);for(let n of c){let{row:i,col:c,colSpan:l,rowSpan:u,value:d}=n;if(a!=null&&a(i,c)||!d||e.getRowFiltered(i))continue;let{hit:f,replaceable:p,isFormula:m}=D(e,i,c,t,d);if(f){let e={provider:`sheets-find-replace-provider`,unitId:r,replaceable:p,isFormula:m,range:{subUnitId:s,range:{startRow:i,startColumn:c,endColumn:c+(l==null?1:l)-1,endRow:i+(u==null?1:u)-1}}};o.push(e)}}return{results:o}}_findInSelections(e,t,n,r){let{findDirection:a}=n,o=a===i.FindDirection.ROW?h:g,s=new Set;return{results:t.map(t=>this._findInRange(e,n,t.range,r,(e,t)=>{let n=`${e}-${t}`;return s.has(n)?!0:(s.add(n),!1)}).results).flat().sort((e,t)=>o(e.range.range,t.range.range)?-1:1)}}_findInWorksheet(e,t,n){let r=e.getRowCount(),i=e.getColumnCount(),a={startRow:0,startColumn:0,endRow:r-1,endColumn:i-1};return this._findInRange(e,t,a,n)}_disposeHighlights(){var e;this._highlightShapes.forEach(e=>{var t;(t=e.getScene())==null||t.makeDirty(),e.dispose()}),this._highlightShapes=[],(e=this._currentHighlightShape)==null||e.dispose(),this._currentHighlightShape=null}_updateFindHighlight(){var e;this._disposeHighlights();let n=(e=this._sheetSkeletonManagerService.getCurrent())==null?void 0:e.skeleton;if(!n)return;let r=this._workbook.getUnitId(),i=this._renderManagerService.getRenderById(r);if(i==null)return;let{scene:o}=i,s=this._matches,c=new t.ColorKit(this._themeService.getColorFromTheme(`yellow.400`)).toRgb(),l=this._workbook.getActiveSheet();if(!l)return;let u=l.getSheetId(),d=s.filter(e=>e.range.subUnitId===u).map((e,t)=>{let{startColumn:r,startRow:i,endColumn:s,endRow:u}=e.range.range,d=(0,a.getCoordByCell)(i,r,o,n),f=(0,a.getCoordByCell)(u,s,o,n),{startX:m,startY:h}=d,{endX:g,endY:_}=f,v=!0;for(let e=i;e<=u;e++)if(l.getRowRawVisible(e)){v=!1;break}let y=!0;for(let e=r;e<=s;e++)if(l.getColVisible(e)){y=!1;break}let b=v||y,x={left:m,top:h,color:c,width:y?2:g-m,height:v?2:_-h,evented:!1,inHiddenRange:b,zIndex:1e4};return new p(`find-highlight-${t}`,x)});o.addObjects(d),this._highlightShapes=d,o.makeDirty()}_updateCurrentHighlightShape(e){var t;if((t=this._currentHighlightShape)==null||t.setShapeProps({activated:!1}),this._currentHighlightShape=null,e!==void 0){let t=this._highlightShapes[e];if(!t)return;this._currentHighlightShape=t,t.setShapeProps({activated:!0})}}_getSheetObject(){return(0,a.getSheetObject)(this._univerInstanceService,this._renderManagerService)}_focusMatch(e){var t;let r=e.range.subUnitId;r!==((t=this._workbook.getActiveSheet())==null?void 0:t.getSheetId())&&this._commandService.executeCommand(n.SetWorksheetActivateCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:r},{fromFindReplace:!0}),this._commandService.executeCommand(a.ScrollToCellCommand.id,{range:e.range.range},{fromFindReplace:!0})}_tryRestoreLastMatchesPosition(e,t){if(!e)return 0;let{subUnitId:n}=e.range,{startColumn:r,startRow:i}=e.range.range,a=t.findIndex(e=>{if(n!==e.range.subUnitId)return!1;let{startColumn:t,startRow:a}=e.range.range;return t===r&&a===i});return a>-1?a+1:0}moveToNextMatch(e){var t,n,r,a;if(!this._matches.length)return null;let o=(t=e==null?void 0:e.loop)==null?!1:t,s=(n=e==null?void 0:e.stayIfOnMatch)==null?!1:n,c=(r=e==null?void 0:e.noFocus)==null?!1:r,l=(a=e==null?void 0:e.ignoreSelection)==null?!1:a,u=this._findNextMatch(o,s,l);if(u){var d;let[e,t]=u;return this._matchesPosition=t+1,this._query.findScope===i.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(e.range.subUnitId).findIndex(t=>t===e):this._activeHighlightIndex=t,c||this._focusMatch(e),((d=this._workbook.getActiveSheet())==null?void 0:d.getSheetId())===e.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),e}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}moveToPreviousMatch(e){var t,n,r,a;if(!this._matches.length)return null;let o=(t=e==null?void 0:e.loop)==null?!1:t,s=(n=e==null?void 0:e.stayIfOnMatch)==null?!1:n,c=(r=e==null?void 0:e.noFocus)==null?!1:r,l=(a=e==null?void 0:e.ignoreSelection)==null?!1:a,u=this._findPreviousMatch(o,s,l);if(u){var d;let[e,t]=u;return this._matchesPosition=t+1,this._query.findScope===i.FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(e.range.subUnitId).findIndex(t=>t===e):this._activeHighlightIndex=t,c||this._focusMatch(e),((d=this._workbook.getActiveSheet())==null?void 0:d.getSheetId())===e.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),e}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}_findPreviousMatch(e=!1,t=!1,n=!1){var r;if(this.currentMatch){let n=this._matches.findIndex(e=>e===this.currentMatch);if(t)return[this.currentMatch,n];let r=n-1;if(!e&&r<0)return null;let i=this._matches.length,a=(r+i)%i;return[this._matches[a],a]}let a=this._workbookSelections.getCurrentLastSelection();if(n||!a){let e=this._matches.length-1;return[this._matches[e],e]}if(this._query.findScope!==i.FindScope.UNIT)return this._findPreviousMatchByRange(this._matches,a.range);let o=(r=this._workbook.getActiveSheet())==null?void 0:r.getSheetId();if(!o)return null;let s=this._findPreviousWorksheetThatHasAMatch(o,e);return s?this._findPreviousMatchByRange(this._matchesByWorksheet.get(s),a.range):null}_findNextMatch(e=!1,t=!1,n=!1){var r;if(this.currentMatch){let n=this._matches.findIndex(e=>e===this.currentMatch);if(t)return[this.currentMatch,n];let r=n+1,i=this._matches.length;if(!e&&r>=i)return null;let a=r%i;return[this._matches[a],a]}let a=this._workbookSelections.getCurrentLastSelection();if(n||!a)return[this._matches[0],0];if(this._query.findScope!==i.FindScope.UNIT)return this._findNextMatchByRange(this._matches,a.range,t);let o=(r=this._workbook.getActiveSheet())==null?void 0:r.getSheetId();if(!o)return null;let s=this._findNextWorksheetThatHasAMatch(o,e);return s?this._findNextMatchByRange(this._matchesByWorksheet.get(s),a.range):null}_findPreviousWorksheetThatHasAMatch(e,n=!1){let r=this._workbook.getSheetOrders(),i=r.findIndex(t=>t===e),a=(n?(0,t.rotate)(r,i+1):r.slice(0,i+1)).findLast(e=>this._matchesByWorksheet.has(e));return a==null?null:a}_findNextWorksheetThatHasAMatch(e,n=!1){let r=this._workbook.getSheetOrders(),i=r.findIndex(t=>t===e),a=(n?(0,t.rotate)(r,i):r.slice(i)).find(e=>this._matchesByWorksheet.has(e));return a==null?null:a}_findNextMatchByRange(e,t,n=!1){let r=this._query.findDirection===i.FindDirection.ROW,a=e.findIndex(e=>{let i=e.range.range;if(!(r?h(t,i):g(t,i)))return!1;let a=m(t,i);return n?a:!a});a===-1&&(a=e.length-1);let o=e[a];return[o,this._matches.findIndex(e=>e===o)]}_findPreviousMatchByRange(e,t,n=!1){let r=this._query.findDirection===i.FindDirection.ROW,a=this._matches.findLastIndex(e=>{let i=e.range.range;if(!(r?_(t,i):v(t,i)))return!1;let a=m(t,i);return n?a:!a});a===-1&&(a=0);let o=e[a];return[o,this._matches.findIndex(e=>e===o)]}async replace(e){if(this._matchesCount===0||!this.currentMatch||!this._query||!this.currentMatch.replaceable)return!1;let t=this.currentMatch.range,r=this._workbook.getSheetBySheetId(this.currentMatch.range.subUnitId),a=this._getReplacedCellData(this.currentMatch,r,this._query.findBy===i.FindBy.FORMULA,this._query.findString,e,this._query.caseSensitive?`g`:`ig`),o={unitId:this.currentMatch.unitId,subUnitId:t.subUnitId,value:{[t.range.startRow]:{[t.range.startColumn]:a}}};return this._commandService.executeCommand(n.SetRangeValuesCommand.id,o)}async replaceAll(e){if(this._matchesCount===0||!this._query)return{success:0,failure:0};let n=this._workbook.getUnitId(),{findString:r,caseSensitive:a,findBy:o}=this._query,c=o===i.FindBy.FORMULA,l=a?`g`:`ig`,u=[];return(0,t.groupBy)(this._matches.filter(e=>e.replaceable),e=>e.range.subUnitId).forEach((n,i)=>{let a=new t.ObjectMatrix,o=this._workbook.getSheetBySheetId(i);n.forEach(t=>{let{startColumn:n,startRow:i}=t.range.range,s=this._getReplacedCellData(t,o,c,r,e,l);s&&a.setValue(i,n,s)}),u.push({count:n.length,subUnitId:i,value:a.getMatrix()})}),u?this._commandService.executeCommand(s.id,{unitId:n,replacements:u}):{success:0,failure:0}}_getReplacedCellData(e,n,r,i,a,o){var s;let{startRow:c,startColumn:l}=e.range.range,u=n.getCellRaw(c,l);if(e.isFormula)return r?{f:u.f.replace(new RegExp(w(i),o),a),v:null}:null;if((s=u.p)!=null&&s.body){let e=t.Tools.deepClone(u.p);return(0,t.replaceInDocumentBody)(e.body,i,a,this._query.caseSensitive),{p:e}}return{v:u.v.toString().replace(new RegExp(w(i),o),a)}}};C=x([b(2,t.IUniverInstanceService),b(3,r.IRenderManagerService),b(4,t.ICommandService),b(5,t.IContextService),b(6,(0,t.Inject)(t.ThemeService)),b(7,(0,t.Inject)(n.SheetsSelectionsService))],C);function w(e){return e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,`\\$&`)}let T=class extends t.Disposable{constructor(e,t,n){super(),this._univerInstanceService=e,this._renderManagerService=t,this._injector=n,f(this,`_findModelsByUnitId`,new Map)}async find(e){this._terminate();let n=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET);if(!n)return[];let r=this._preprocessQuery(e),i=this._renderManagerService.getRenderById(n.getUnitId()).with(a.SheetSkeletonManagerService),o=this._injector.createInstance(C,n,i);return this._findModelsByUnitId.set(n.getUnitId(),o),o.start(r),[o]}terminate(){this._terminate()}_terminate(){this._findModelsByUnitId.forEach(e=>e.dispose()),this._findModelsByUnitId.clear()}_preprocessQuery(e){let t=e.caseSensitive?e.findString:e.findString.toLowerCase();return t=t.trim(),{...e,findString:t}}};T=x([b(0,t.IUniverInstanceService),b(1,r.IRenderManagerService),b(2,(0,t.Inject)(t.Injector))],T);let E={hit:!1,replaceable:!1,isFormula:!1,rawData:null};function D(e,t,n,r,a){let{findBy:o}=r,s=o===i.FindBy.FORMULA,c=e.getCellRaw(t,n);return E.rawData=c,c!=null&&c.f?(E.isFormula=!0,s?O({v:c.f},r)?(E.hit=!0,E.replaceable=!0,E):(E.hit=!1,E.replaceable=!1,E):(E.replaceable=!1,O(a,r)?E.hit=!0:E.hit=!1,E)):(E.isFormula=!1,O(a,r)?c?(E.hit=!0,E.replaceable=!0):(E.hit=!0,E.replaceable=!1):(E.hit=!1,E.replaceable=!1),E)}function O(e,t){let n=k(e);return n?t.matchesTheWholeCell?(n=A(n),t.caseSensitive?n===t.findString:n.toLowerCase()===t.findString):t.caseSensitive?n.indexOf(t.findString)>-1:n.toLowerCase().indexOf(t.findString)>-1:!1}function k(e){var t,n;let r=(t=e==null||(n=e.p)==null||(n=n.body)==null?void 0:n.dataStream)==null?e==null?void 0:e.v:t;return typeof r==`number`?`${r}`:typeof r==`boolean`?r?`1`:`0`:r}function A(e){return e.replace(/^ +/g,``).replace(/ +$/g,``)}var j=`@univerjs/sheets-find-replace`,M=`0.19.0`;let N=`sheets-find-replace.config`;Symbol(N);let P={},F=class extends t.Plugin{constructor(e=P,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{...i}=(0,t.merge)({},P,this._config);this._configService.setConfig(N,i)}onStarting(){[[S]].forEach(e=>this._injector.add(e))}onSteady(){this._injector.get(S)}};f(F,`pluginName`,`SHEET_FIND_REPLACE_PLUGIN`),f(F,`packageName`,j),f(F,`version`,M),f(F,`type`,t.UniverInstanceType.UNIVER_SHEET),F=x([(0,t.DependentOn)(n.UniverSheetsPlugin,n.UniverSheetsPlugin,i.UniverFindReplacePlugin),b(1,(0,t.Inject)(t.Injector)),b(2,t.IConfigService)],F),e.SheetReplaceCommand=s,Object.defineProperty(e,`SheetsFindReplaceController`,{enumerable:!0,get:function(){return S}}),Object.defineProperty(e,`UniverSheetsFindReplacePlugin`,{enumerable:!0,get:function(){return F}})});
9
6
 
10
7
  // @univerjs/sheets-find-replace/facade
11
8
  (function(e,t){typeof exports==`object`&&typeof module<`u`?t(require(`@univerjs/core`),require(`@univerjs/find-replace`),require(`@univerjs/sheets/facade`),require(`@univerjs/core/facade`)):typeof define==`function`&&define.amd?define([`@univerjs/core`,`@univerjs/find-replace`,`@univerjs/sheets/facade`,`@univerjs/core/facade`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverCore,e.UniverFindReplace,e.UniverSheetsFacade,e.UniverCoreFacade))})(this,function(e,t,n,r){function i(e){"@babel/helpers - typeof";return i=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},i(e)}function a(e,t){if(i(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(i(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function o(e){var t=a(e,`string`);return i(t)==`symbol`?t:t+``}function s(e,t,n){return(t=o(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function c(e,t){return function(n,r){t(n,r,e)}}function l(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}let u=class extends e.Disposable{constructor(e,n,r,i){super(),this._injector=n,this._univerInstanceService=r,this._findReplaceService=i,s(this,`_state`,new t.FindReplaceState),s(this,`_model`,void 0),s(this,`_complete`,void 0);let a=this._findReplaceService.getProviders();this._model=this._injector.createInstance(t.FindReplaceModel,this._state,a);let o={...(0,t.createInitFindReplaceState)(),...e};this._state.changeState(o)}findAll(){return!this._state.findCompleted||!this._complete?[]:this._complete.results.map(e=>this._findMatchToFRange(e))}findNext(){var e;if(!this._state.findCompleted||!this._complete)return null;let t=(e=this._model)==null?void 0:e.moveToNextMatch();return t?this._findMatchToFRange(t):null}findPrevious(){var e;let t=(e=this._model)==null?void 0:e.moveToPreviousMatch();return t?this._findMatchToFRange(t):null}getCurrentMatch(){var e;if(!this._state.findCompleted||!this._complete)throw Error(`Find operation is not completed.`);let t=(e=this._model)==null?void 0:e.currentMatch$.value;return t?this._findMatchToFRange(t):null}async matchCaseAsync(e){return this._state.changeState({caseSensitive:e,findCompleted:!1}),new Promise(e=>{let t=this._state.stateUpdates$.subscribe(async n=>{n.findCompleted===!0&&(t.unsubscribe(),await this.ensureCompleteAsync(),e(this))})})}async matchEntireCellAsync(e){return this._state.changeState({matchesTheWholeCell:e,findCompleted:!1}),new Promise(e=>{let t=this._state.stateUpdates$.subscribe(async n=>{n.findCompleted===!0&&(t.unsubscribe(),await this.ensureCompleteAsync(),e(this))})})}async matchFormulaTextAsync(e){return this._state.changeState({findBy:e?t.FindBy.FORMULA:t.FindBy.VALUE,findCompleted:!1}),new Promise(e=>{let t=this._state.stateUpdates$.subscribe(async n=>{n.findCompleted===!0&&(t.unsubscribe(),await this.ensureCompleteAsync(),e(this))})})}async replaceAllWithAsync(e){var t,n,r;await this._state.changeState({replaceRevealed:!0,replaceString:e});let i=(t=(n=await((r=this._model)==null?void 0:r.replaceAll()))==null?void 0:n.success)==null?0:t;return this._state.changeState({replaceRevealed:!1}),i}async replaceWithAsync(e){var t;return await this._state.changeState({replaceRevealed:!0,replaceString:e}),await((t=this._model)==null?void 0:t.replace()),this._state.changeState({replaceRevealed:!1}),!0}async ensureCompleteAsync(){var e;this._complete=await((e=this._model)==null?void 0:e.start())}_findMatchToFRange(e){let{unitId:t}=e,{subUnitId:r,range:i}=e.range,a=this._univerInstanceService.getUnit(t),o=a.getSheetBySheetId(r);return this._injector.createInstance(n.FRange,a,o,i)}};u=l([c(1,(0,e.Inject)(e.Injector)),c(2,e.IUniverInstanceService),c(3,t.IFindReplaceService)],u);var d=class extends r.FUniver{async createTextFinderAsync(e){let t={findString:e},n=this._injector.createInstance(u,t);return await n.ensureCompleteAsync(),n}};r.FUniver.extend(d)});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/preset-sheets-find-replace",
3
- "version": "0.18.0",
3
+ "version": "0.19.0",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum Co., Ltd. <developer@univer.ai>",
@@ -58,16 +58,16 @@
58
58
  "rxjs": ">=7.0.0"
59
59
  },
60
60
  "dependencies": {
61
- "@univerjs/find-replace": "0.18.0",
62
- "@univerjs/sheets-find-replace": "0.18.0"
61
+ "@univerjs/find-replace": "0.19.0",
62
+ "@univerjs/sheets-find-replace": "0.19.0"
63
63
  },
64
64
  "devDependencies": {
65
- "@univerjs/core": "0.18.0",
65
+ "@univerjs/core": "0.19.0",
66
66
  "react": "18.3.1",
67
67
  "react-dom": "18.3.1",
68
68
  "rxjs": "7.8.2",
69
69
  "typescript": "^5.9.3",
70
- "@univerjs-infra/shared": "0.18.0"
70
+ "@univerjs-infra/shared": "0.19.0"
71
71
  },
72
72
  "scripts": {
73
73
  "prebuild:preset": "tsx prepare.ts",