@univerjs/find-replace 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,12 +5,16 @@
5
5
 
6
6
  ## Introduction
7
7
 
8
- > TODO: Introduction
8
+ TODO: Not yet written.
9
9
 
10
10
  ## Usage
11
11
 
12
12
  ### Installation
13
13
 
14
14
  ```shell
15
- npm i @univerjs/find-replace
15
+ # Using npm
16
+ npm install @univerjs/find-replace
17
+
18
+ # Using pnpm
19
+ pnpm add @univerjs/find-replace
16
20
  ```
package/lib/cjs/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var J=Object.defineProperty;var Y=(t,e,n)=>e in t?J(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var u=(t,e,n)=>(Y(t,typeof e!="symbol"?e+"":e,n),n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("@univerjs/core"),S=require("@wendellhu/redi"),d=require("@univerjs/ui"),O=require("rxjs"),p=require("react"),f=require("@univerjs/design"),P=require("@wendellhu/redi/react-bindings");var _=function(){return _=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++){e=arguments[n];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])}return t},_.apply(this,arguments)},Q=function(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,i=Object.getOwnPropertySymbols(t);r<i.length;r++)e.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(t,i[r])&&(n[i[r]]=t[i[r]]);return n},N=p.forwardRef(function(t,e){var n=t.icon,i=t.id,r=t.className,o=t.extend,a=Q(t,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(i," ").concat(r||"").trim(),v=p.useRef("_".concat(te()));return U(n,"".concat(i),{defIds:n.defIds,idSuffix:v.current},_({ref:e,className:c},a),o)});function U(t,e,n,i,r){return p.createElement(t.tag,_(_({key:e},X(t,n,r)),i),(ee(t,n).children||[]).map(function(o,a){return U(o,"".concat(e,"-").concat(t.tag,"-").concat(a),n,void 0,r)}))}function X(t,e,n){var i=_({},t.attrs);n!=null&&n.colorChannel1&&i.fill==="colorChannel1"&&(i.fill=n.colorChannel1);var r=e.defIds;return!r||r.length===0||(t.tag==="use"&&i["xlink:href"]&&(i["xlink:href"]=i["xlink:href"]+e.idSuffix),Object.entries(i).forEach(function(o){var a=o[0],c=o[1];typeof c=="string"&&(i[a]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),i}function ee(t,e){var n,i=e.defIds;return!i||i.length===0?t:t.tag==="defs"&&(!((n=t.children)===null||n===void 0)&&n.length)?_(_({},t),{children:t.children.map(function(r){return typeof r.attrs.id=="string"&&i&&i.indexOf(r.attrs.id)>-1?_(_({},r),{attrs:_(_({},r.attrs),{id:r.attrs.id+e.idSuffix})}):r})}):t}function te(){return Math.random().toString(36).substring(2,8)}N.displayName="UniverIcon";var ie={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_217_40",style:{maskType:"alpha"},width:17,height:17,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#D9D9D9",d:"M0.9 0.09H16.9V16.09H0.9z"}}]},{tag:"g",attrs:{mask:"url(#mask0_217_40)"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.39551 7.37266C2.39551 4.18105 4.98281 1.59375 8.17441 1.59375C11.366 1.59375 13.9533 4.18105 13.9533 7.37266C13.9533 8.72342 13.4898 9.96603 12.7133 10.95L15.1964 13.4331C15.4619 13.6986 15.4619 14.1291 15.1964 14.3946C14.9309 14.6601 14.5004 14.6601 14.2349 14.3946L11.7518 11.9115C10.7678 12.6881 9.52525 13.1516 8.17441 13.1516C4.98281 13.1516 2.39551 10.5642 2.39551 7.37266ZM8.17441 2.95349C5.73378 2.95349 3.75525 4.93202 3.75525 7.37266C3.75525 9.81333 5.73378 11.7918 8.17441 11.7918C10.6151 11.7918 12.5936 9.81333 12.5936 7.37266C12.5936 4.93202 10.6151 2.95349 8.17441 2.95349Z",fillRule:"evenodd",clipRule:"evenodd"}}]}]},$=p.forwardRef(function(t,e){return p.createElement(N,Object.assign({},t,{id:"search-single-16",ref:e,icon:ie}))});$.displayName="SearchSingle16";var ne=Object.defineProperty,re=Object.getOwnPropertyDescriptor,L=(t,e,n,i)=>{for(var r=i>1?void 0:i?re(e,n):e,o=t.length-1,a;o>=0;o--)(a=t[o])&&(r=(i?a(e,n,r):a(r))||r);return i&&r&&ne(e,n,r),r},I=(t,e)=>(n,i)=>e(n,i,t);class oe extends s.Disposable{}const m=S.createIdentifier("univer.find-replace.service");let T=class extends s.Disposable{constructor(e,n,i,r){super();u(this,"_matchPositionFindModel",null);u(this,"_findModels",[]);u(this,"_matches",[]);u(this,"_positionModel",null);this._state=e,this._providers=n,this._logService=i,this._univerInstanceService=r,this._state.stateUpdates$.subscribe(o=>{typeof o.findString<"u"&&(o.findString?this.find():this._cancelFinding())})}async find(){this._cancelFinding();const e=Array.from(this._providers),n=this._findModels=(await Promise.all(e.map(o=>o.find({text:this._state.findString})))).flat(),i=n.map(o=>o.getMatches()).flat();if(this._matches=i,!i.length)return{results:[]};const r=this._moveToInitialMatch(n,i);return this._state.changeState({matchesCount:i.length,matchesPosition:r+1}),{results:i}}moveToNextMatch(){if(!this._positionModel)return;const e=this._findModels.length===1,n=this._positionModel.moveToNextMatch(e);if(n){const i=this._matches.findIndex(r=>r===n);this._state.changeState({matchesPosition:i+1})}else{const i=this._findModels.findIndex(c=>c===this._positionModel),r=this._findModels[(i+1)%this._findModels.length],o=r.moveToNextMatch(),a=this._matches.findIndex(c=>c===o);this._positionModel=r,this._state.changeState({matchesPosition:a+1})}}moveToPreviousMatch(){if(!this._positionModel)return;const e=this._findModels.length===1,n=this._positionModel.moveToPreviousMatch(e);if(n){const i=this._matches.findIndex(r=>r===n);this._state.changeState({matchesPosition:i+1})}else{const i=this._findModels.findIndex(c=>c===this._positionModel),r=this._findModels[(i-1+this._findModels.length)%this._findModels.length],o=r.moveToPreviousMatch(),a=this._matches.findIndex(c=>c===o);this._positionModel=r,this._state.changeState({matchesPosition:a+1})}}_moveToInitialMatch(e,n){var c;const i=(c=this._univerInstanceService.getFocusedUniverInstance())==null?void 0:c.getUnitId();if(!i)return-1;const r=e.find(v=>v.unitId===i);if(r){this._positionModel=r;const v=r.moveToNextMatch();return n.findIndex(C=>C===v)}this._positionModel=e[0];const o=this._positionModel.moveToNextMatch();return this._matches.findIndex(v=>v===o)}_cancelFinding(){this._providers.forEach(e=>e.cancel()),this._state.changeState({matchesCount:0,matchesPosition:0})}};T=L([I(2,s.ILogService),I(3,s.IUniverInstanceService)],T);function A(){return{revealed:!0,findString:"",replaceRevealed:!1,matchesPosition:0,matchesCount:0}}class ae{constructor(){u(this,"_stateUpdates$",new O.Subject);u(this,"stateUpdates$",this._stateUpdates$.asObservable());u(this,"_state$",new O.BehaviorSubject(A()));u(this,"state$",this._state$.asObservable());u(this,"_findString","");u(this,"_revealed",!1);u(this,"_replaceRevealed",!1);u(this,"_matchesPosition",0);u(this,"_matchesCount",0)}get state(){return this._state$.getValue()}get findString(){return this._findString}changeState(e){let n=!1;const i={};typeof e.findString<"u"&&e.findString!==this._findString&&(this._findString=e.findString,i.findString=this._findString,n=!0),typeof e.revealed<"u"&&e.revealed!==this._revealed&&(this._revealed=e.revealed,i.revealed=e.revealed,n=!0),typeof e.replaceRevealed<"u"&&e.replaceRevealed!==this._replaceRevealed&&(this._replaceRevealed=e.replaceRevealed,i.replaceRevealed=e.replaceRevealed,n=!0),typeof e.matchesCount<"u"&&e.matchesCount!==this._matchesCount&&(this._matchesCount=e.matchesCount,i.matchesCount=e.matchesCount,n=!0),typeof e.matchesPosition<"u"&&e.matchesPosition!==this._matchesPosition&&(this._matchesPosition=e.matchesPosition,i.matchesPosition=e.matchesPosition,n=!0),n&&(this._stateUpdates$.next(i),this._state$.next({findString:this._findString,revealed:this._revealed,replaceRevealed:this._replaceRevealed,matchesCount:this._matchesCount,matchesPosition:this._matchesPosition}))}}let b=class extends s.Disposable{constructor(e,n,i){super();u(this,"_providers",new Set);u(this,"_state",new ae);u(this,"_model");this._injector=e,this._univerInstanceService=n,this._logService=i}get stateUpdates$(){return this._state.stateUpdates$}get state$(){return this._state.state$}changeFindString(e){this._state.changeState({findString:e})}moveToNextMatch(){var e;this._model&&((e=this._model)==null||e.moveToNextMatch())}moveToPreviousMatch(){var e;this._model&&((e=this._model)==null||e.moveToPreviousMatch())}replace(){return!0}replaceAll(){return!0}revealReplace(){this._state.changeState({replaceRevealed:!0})}disposeModel(){var e;(e=this._model)==null||e.dispose(),this._model=null}start(){if(this._providers.size===0)return!1;this._model=this._injector.createInstance(T,this._state,this._providers);const e=A();return e.revealed=!0,this._state.changeState(e),!0}end(){return this._state.changeState({revealed:!1,replaceRevealed:!1}),!0}registerFindReplaceProvider(e){return this._providers.add(e),s.toDisposable(()=>this._providers.delete(e))}};b=L([I(0,S.Inject(S.Injector)),I(1,s.IUniverInstanceService),I(2,s.ILogService)],b);const j={id:"ui.operation.open-find-dialog",type:s.CommandType.OPERATION,handler:t=>(t.get(m).start(),!0)},w={id:"ui.operation.open-replace-dialog",type:s.CommandType.OPERATION,handler:t=>(t.get(m).start(),!0)},se={id:"ui.operation.toggle-replace-dialog",type:s.CommandType.OPERATION,handler:t=>(t.get(m),!0)},B={id:"ui.operation.close-find-replace-dialog",type:s.CommandType.OPERATION,handler:t=>!0},V={type:s.CommandType.OPERATION,id:"ui.operation.go-to-next-match",handler:t=>(t.get(m).moveToNextMatch(),!0)},q={type:s.CommandType.OPERATION,id:"ui.operation.go-to-previous-match",handler:t=>(t.get(m).moveToPreviousMatch(),!0)},x="FIND_REPLACE_ACTIVATED";var K={exports:{}},y={};/**
1
+ "use strict";var J=Object.defineProperty;var Y=(t,e,n)=>e in t?J(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var u=(t,e,n)=>(Y(t,typeof e!="symbol"?e+"":e,n),n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("@univerjs/core"),S=require("@wendellhu/redi"),d=require("@univerjs/ui"),O=require("rxjs"),p=require("react"),f=require("@univerjs/design"),P=require("@wendellhu/redi/react-bindings");var _=function(){return _=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++){e=arguments[n];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])}return t},_.apply(this,arguments)},Q=function(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,i=Object.getOwnPropertySymbols(t);r<i.length;r++)e.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(t,i[r])&&(n[i[r]]=t[i[r]]);return n},N=p.forwardRef(function(t,e){var n=t.icon,i=t.id,r=t.className,o=t.extend,a=Q(t,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(i," ").concat(r||"").trim(),v=p.useRef("_".concat(te()));return U(n,"".concat(i),{defIds:n.defIds,idSuffix:v.current},_({ref:e,className:c},a),o)});function U(t,e,n,i,r){return p.createElement(t.tag,_(_({key:e},X(t,n,r)),i),(ee(t,n).children||[]).map(function(o,a){return U(o,"".concat(e,"-").concat(t.tag,"-").concat(a),n,void 0,r)}))}function X(t,e,n){var i=_({},t.attrs);n!=null&&n.colorChannel1&&i.fill==="colorChannel1"&&(i.fill=n.colorChannel1);var r=e.defIds;return!r||r.length===0||(t.tag==="use"&&i["xlink:href"]&&(i["xlink:href"]=i["xlink:href"]+e.idSuffix),Object.entries(i).forEach(function(o){var a=o[0],c=o[1];typeof c=="string"&&(i[a]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),i}function ee(t,e){var n,i=e.defIds;return!i||i.length===0?t:t.tag==="defs"&&(!((n=t.children)===null||n===void 0)&&n.length)?_(_({},t),{children:t.children.map(function(r){return typeof r.attrs.id=="string"&&i&&i.indexOf(r.attrs.id)>-1?_(_({},r),{attrs:_(_({},r.attrs),{id:r.attrs.id+e.idSuffix})}):r})}):t}function te(){return Math.random().toString(36).substring(2,8)}N.displayName="UniverIcon";var ie={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_217_40",style:{maskType:"alpha"},width:17,height:17,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#D9D9D9",d:"M0.9 0.09H16.9V16.09H0.9z"}}]},{tag:"g",attrs:{mask:"url(#mask0_217_40)"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.39551 7.37266C2.39551 4.18105 4.98281 1.59375 8.17441 1.59375C11.366 1.59375 13.9533 4.18105 13.9533 7.37266C13.9533 8.72342 13.4898 9.96603 12.7133 10.95L15.1964 13.4331C15.4619 13.6986 15.4619 14.1291 15.1964 14.3946C14.9309 14.6601 14.5004 14.6601 14.2349 14.3946L11.7518 11.9115C10.7678 12.6881 9.52525 13.1516 8.17441 13.1516C4.98281 13.1516 2.39551 10.5642 2.39551 7.37266ZM8.17441 2.95349C5.73378 2.95349 3.75525 4.93202 3.75525 7.37266C3.75525 9.81333 5.73378 11.7918 8.17441 11.7918C10.6151 11.7918 12.5936 9.81333 12.5936 7.37266C12.5936 4.93202 10.6151 2.95349 8.17441 2.95349Z",fillRule:"evenodd",clipRule:"evenodd"}}]}]},$=p.forwardRef(function(t,e){return p.createElement(N,Object.assign({},t,{id:"search-single-16",ref:e,icon:ie}))});$.displayName="SearchSingle16";var ne=Object.defineProperty,re=Object.getOwnPropertyDescriptor,L=(t,e,n,i)=>{for(var r=i>1?void 0:i?re(e,n):e,o=t.length-1,a;o>=0;o--)(a=t[o])&&(r=(i?a(e,n,r):a(r))||r);return i&&r&&ne(e,n,r),r},I=(t,e)=>(n,i)=>e(n,i,t);class oe extends s.Disposable{}const m=S.createIdentifier("univer.find-replace.service");class ae{constructor(){u(this,"_stateUpdates$",new O.Subject);u(this,"stateUpdates$",this._stateUpdates$.asObservable());u(this,"_state$",new O.BehaviorSubject(A()));u(this,"state$",this._state$.asObservable());u(this,"_findString","");u(this,"_revealed",!1);u(this,"_replaceRevealed",!1);u(this,"_matchesPosition",0);u(this,"_matchesCount",0)}get state(){return this._state$.getValue()}get findString(){return this._findString}changeState(e){let n=!1;const i={};typeof e.findString<"u"&&e.findString!==this._findString&&(this._findString=e.findString,i.findString=this._findString,n=!0),typeof e.revealed<"u"&&e.revealed!==this._revealed&&(this._revealed=e.revealed,i.revealed=e.revealed,n=!0),typeof e.replaceRevealed<"u"&&e.replaceRevealed!==this._replaceRevealed&&(this._replaceRevealed=e.replaceRevealed,i.replaceRevealed=e.replaceRevealed,n=!0),typeof e.matchesCount<"u"&&e.matchesCount!==this._matchesCount&&(this._matchesCount=e.matchesCount,i.matchesCount=e.matchesCount,n=!0),typeof e.matchesPosition<"u"&&e.matchesPosition!==this._matchesPosition&&(this._matchesPosition=e.matchesPosition,i.matchesPosition=e.matchesPosition,n=!0),n&&(this._stateUpdates$.next(i),this._state$.next({findString:this._findString,revealed:this._revealed,replaceRevealed:this._replaceRevealed,matchesCount:this._matchesCount,matchesPosition:this._matchesPosition}))}}let T=class extends s.Disposable{constructor(e,n,i,r){super();u(this,"_matchPositionFindModel",null);u(this,"_findModels",[]);u(this,"_matches",[]);u(this,"_positionModel",null);this._state=e,this._providers=n,this._logService=i,this._univerInstanceService=r,this._state.stateUpdates$.subscribe(o=>{typeof o.findString<"u"&&(o.findString?this.find():this._cancelFinding())})}async find(){this._cancelFinding();const e=Array.from(this._providers),n=this._findModels=(await Promise.all(e.map(o=>o.find({text:this._state.findString})))).flat(),i=n.map(o=>o.getMatches()).flat();if(this._matches=i,!i.length)return{results:[]};const r=this._moveToInitialMatch(n,i);return this._state.changeState({matchesCount:i.length,matchesPosition:r+1}),{results:i}}moveToNextMatch(){if(!this._positionModel)return;const e=this._findModels.length===1,n=this._positionModel.moveToNextMatch(e);if(n){const i=this._matches.findIndex(r=>r===n);this._state.changeState({matchesPosition:i+1})}else{const i=this._findModels.findIndex(c=>c===this._positionModel),r=this._findModels[(i+1)%this._findModels.length],o=r.moveToNextMatch(),a=this._matches.findIndex(c=>c===o);this._positionModel=r,this._state.changeState({matchesPosition:a+1})}}moveToPreviousMatch(){if(!this._positionModel)return;const e=this._findModels.length===1,n=this._positionModel.moveToPreviousMatch(e);if(n){const i=this._matches.findIndex(r=>r===n);this._state.changeState({matchesPosition:i+1})}else{const i=this._findModels.findIndex(c=>c===this._positionModel),r=this._findModels[(i-1+this._findModels.length)%this._findModels.length],o=r.moveToPreviousMatch(),a=this._matches.findIndex(c=>c===o);this._positionModel=r,this._state.changeState({matchesPosition:a+1})}}_moveToInitialMatch(e,n){var c;const i=(c=this._univerInstanceService.getFocusedUniverInstance())==null?void 0:c.getUnitId();if(!i)return-1;const r=e.find(v=>v.unitId===i);if(r){this._positionModel=r;const v=r.moveToNextMatch();return n.findIndex(C=>C===v)}this._positionModel=e[0];const o=this._positionModel.moveToNextMatch();return this._matches.findIndex(v=>v===o)}_cancelFinding(){this._providers.forEach(e=>e.cancel()),this._state.changeState({matchesCount:0,matchesPosition:0})}};T=L([I(2,s.ILogService),I(3,s.IUniverInstanceService)],T);function A(){return{revealed:!0,findString:"",replaceRevealed:!1,matchesPosition:0,matchesCount:0}}let b=class extends s.Disposable{constructor(e,n,i){super();u(this,"_providers",new Set);u(this,"_state",new ae);u(this,"_model");this._injector=e,this._univerInstanceService=n,this._logService=i}get stateUpdates$(){return this._state.stateUpdates$}get state$(){return this._state.state$}changeFindString(e){this._state.changeState({findString:e})}moveToNextMatch(){var e;this._model&&((e=this._model)==null||e.moveToNextMatch())}moveToPreviousMatch(){var e;this._model&&((e=this._model)==null||e.moveToPreviousMatch())}replace(){return!0}replaceAll(){return!0}revealReplace(){this._state.changeState({replaceRevealed:!0})}disposeModel(){var e;(e=this._model)==null||e.dispose(),this._model=null}start(){if(this._providers.size===0)return!1;this._model=this._injector.createInstance(T,this._state,this._providers);const e=A();return e.revealed=!0,this._state.changeState(e),!0}end(){return this._state.changeState({revealed:!1,replaceRevealed:!1}),!0}registerFindReplaceProvider(e){return this._providers.add(e),s.toDisposable(()=>this._providers.delete(e))}};b=L([I(0,S.Inject(S.Injector)),I(1,s.IUniverInstanceService),I(2,s.ILogService)],b);const j={id:"ui.operation.open-find-dialog",type:s.CommandType.OPERATION,handler:t=>(t.get(m).start(),!0)},w={id:"ui.operation.open-replace-dialog",type:s.CommandType.OPERATION,handler:t=>(t.get(m).start(),!0)},se={id:"ui.operation.toggle-replace-dialog",type:s.CommandType.OPERATION,handler:t=>(t.get(m),!0)},B={id:"ui.operation.close-find-replace-dialog",type:s.CommandType.OPERATION,handler:t=>!0},V={type:s.CommandType.OPERATION,id:"ui.operation.go-to-next-match",handler:t=>(t.get(m).moveToNextMatch(),!0)},q={type:s.CommandType.OPERATION,id:"ui.operation.go-to-previous-match",handler:t=>(t.get(m).moveToPreviousMatch(),!0)},x="FIND_REPLACE_ACTIVATED";var K={exports:{}},y={};/**
2
2
  * @license React
3
3
  * react-jsx-runtime.production.min.js
4
4
  *
package/lib/es/index.js CHANGED
@@ -107,6 +107,37 @@ var He = Object.defineProperty, We = Object.getOwnPropertyDescriptor, Y = (t, e,
107
107
  class Ct extends E {
108
108
  }
109
109
  const f = xe("univer.find-replace.service");
110
+ class ke {
111
+ constructor() {
112
+ l(this, "_stateUpdates$", new be());
113
+ l(this, "stateUpdates$", this._stateUpdates$.asObservable());
114
+ l(this, "_state$", new Ee(Q()));
115
+ l(this, "state$", this._state$.asObservable());
116
+ // TODO@wzhudev: put all state properties here
117
+ l(this, "_findString", "");
118
+ l(this, "_revealed", !1);
119
+ l(this, "_replaceRevealed", !1);
120
+ l(this, "_matchesPosition", 0);
121
+ l(this, "_matchesCount", 0);
122
+ }
123
+ get state() {
124
+ return this._state$.getValue();
125
+ }
126
+ get findString() {
127
+ return this._findString;
128
+ }
129
+ changeState(e) {
130
+ let n = !1;
131
+ const i = {};
132
+ typeof e.findString < "u" && e.findString !== this._findString && (this._findString = e.findString, i.findString = this._findString, n = !0), typeof e.revealed < "u" && e.revealed !== this._revealed && (this._revealed = e.revealed, i.revealed = e.revealed, n = !0), typeof e.replaceRevealed < "u" && e.replaceRevealed !== this._replaceRevealed && (this._replaceRevealed = e.replaceRevealed, i.replaceRevealed = e.replaceRevealed, n = !0), typeof e.matchesCount < "u" && e.matchesCount !== this._matchesCount && (this._matchesCount = e.matchesCount, i.matchesCount = e.matchesCount, n = !0), typeof e.matchesPosition < "u" && e.matchesPosition !== this._matchesPosition && (this._matchesPosition = e.matchesPosition, i.matchesPosition = e.matchesPosition, n = !0), n && (this._stateUpdates$.next(i), this._state$.next({
133
+ findString: this._findString,
134
+ revealed: this._revealed,
135
+ replaceRevealed: this._replaceRevealed,
136
+ matchesCount: this._matchesCount,
137
+ matchesPosition: this._matchesPosition
138
+ }));
139
+ }
140
+ }
110
141
  let T = class extends E {
111
142
  constructor(e, n, i, r) {
112
143
  super();
@@ -202,37 +233,6 @@ function Q() {
202
233
  matchesCount: 0
203
234
  };
204
235
  }
205
- class ke {
206
- constructor() {
207
- l(this, "_stateUpdates$", new be());
208
- l(this, "stateUpdates$", this._stateUpdates$.asObservable());
209
- l(this, "_state$", new Ee(Q()));
210
- l(this, "state$", this._state$.asObservable());
211
- // TODO@wzhudev: put all state properties here
212
- l(this, "_findString", "");
213
- l(this, "_revealed", !1);
214
- l(this, "_replaceRevealed", !1);
215
- l(this, "_matchesPosition", 0);
216
- l(this, "_matchesCount", 0);
217
- }
218
- get state() {
219
- return this._state$.getValue();
220
- }
221
- get findString() {
222
- return this._findString;
223
- }
224
- changeState(e) {
225
- let n = !1;
226
- const i = {};
227
- typeof e.findString < "u" && e.findString !== this._findString && (this._findString = e.findString, i.findString = this._findString, n = !0), typeof e.revealed < "u" && e.revealed !== this._revealed && (this._revealed = e.revealed, i.revealed = e.revealed, n = !0), typeof e.replaceRevealed < "u" && e.replaceRevealed !== this._replaceRevealed && (this._replaceRevealed = e.replaceRevealed, i.replaceRevealed = e.replaceRevealed, n = !0), typeof e.matchesCount < "u" && e.matchesCount !== this._matchesCount && (this._matchesCount = e.matchesCount, i.matchesCount = e.matchesCount, n = !0), typeof e.matchesPosition < "u" && e.matchesPosition !== this._matchesPosition && (this._matchesPosition = e.matchesPosition, i.matchesPosition = e.matchesPosition, n = !0), n && (this._stateUpdates$.next(i), this._state$.next({
228
- findString: this._findString,
229
- revealed: this._revealed,
230
- replaceRevealed: this._replaceRevealed,
231
- matchesCount: this._matchesCount,
232
- matchesPosition: this._matchesPosition
233
- }));
234
- }
235
- }
236
236
  let b = class extends E {
237
237
  constructor(e, n, i) {
238
238
  super();
@@ -77,6 +77,25 @@ export interface IFindQuery {
77
77
  /** Other possible options set by business. */
78
78
  [key: string]: boolean | string | number | undefined;
79
79
  }
80
+ /**
81
+ * This class stores find replace options state. These state are stored
82
+ * here instead of the React component so we can change state from
83
+ * operations.
84
+ */
85
+ export declare class FindReplaceState {
86
+ private readonly _stateUpdates$;
87
+ readonly stateUpdates$: Observable<Partial<IFindReplaceState>>;
88
+ private readonly _state$;
89
+ readonly state$: Observable<IFindReplaceState>;
90
+ get state(): IFindReplaceState;
91
+ private _findString;
92
+ private _revealed;
93
+ private _replaceRevealed;
94
+ private _matchesPosition;
95
+ private _matchesCount;
96
+ get findString(): string;
97
+ changeState(changes: Partial<IFindReplaceState>): void;
98
+ }
80
99
  /**
81
100
  * This class stores find replace results and provides methods to perform replace or something.
82
101
  */
@@ -107,25 +126,6 @@ export interface IFindReplaceState {
107
126
  matchesPosition: number;
108
127
  matchesCount: number;
109
128
  }
110
- /**
111
- * This class stores find replace options state. These state are stored
112
- * here instead of the React component so we can change state from
113
- * operations.
114
- */
115
- export declare class FindReplaceState {
116
- private readonly _stateUpdates$;
117
- readonly stateUpdates$: Observable<Partial<IFindReplaceState>>;
118
- private readonly _state$;
119
- readonly state$: Observable<IFindReplaceState>;
120
- get state(): IFindReplaceState;
121
- private _findString;
122
- private _revealed;
123
- private _replaceRevealed;
124
- private _matchesPosition;
125
- private _matchesCount;
126
- get findString(): string;
127
- changeState(changes: Partial<IFindReplaceState>): void;
128
- }
129
129
  export declare class FindReplaceService extends Disposable implements IFindReplaceService {
130
130
  private readonly _injector;
131
131
  private readonly _univerInstanceService;
package/lib/umd/index.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(c,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("@univerjs/ui"),require("rxjs"),require("react"),require("@univerjs/design"),require("@wendellhu/redi/react-bindings")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","@univerjs/ui","rxjs","react","@univerjs/design","@wendellhu/redi/react-bindings"],o):(c=typeof globalThis<"u"?globalThis:c||self,o(c.UniverFindReplace={},c.UniverCore,c["@wendellhu/redi"],c.UniverUi,c.rxjs,c.React,c.UniverDesign,c["@wendellhu/redi/react-bindings"]))})(this,function(c,o,v,h,O,p,_,T){"use strict";var je=Object.defineProperty;var be=(c,o,v)=>o in c?je(c,o,{enumerable:!0,configurable:!0,writable:!0,value:v}):c[o]=v;var u=(c,o,v)=>(be(c,typeof o!="symbol"?o+"":o,v),v);var g=function(){return g=Object.assign||function(t){for(var e,r=1,i=arguments.length;r<i;r++){e=arguments[r];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])}return t},g.apply(this,arguments)},z=function(t,e){var r={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(r[i]=t[i]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var n=0,i=Object.getOwnPropertySymbols(t);n<i.length;n++)e.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(t,i[n])&&(r[i[n]]=t[i[n]]);return r},E=p.forwardRef(function(t,e){var r=t.icon,i=t.id,n=t.className,a=t.extend,s=z(t,["icon","id","className","extend"]),l="univerjs-icon univerjs-icon-".concat(i," ").concat(n||"").trim(),m=p.useRef("_".concat(Y()));return D(r,"".concat(i),{defIds:r.defIds,idSuffix:m.current},g({ref:e,className:l},s),a)});function D(t,e,r,i,n){return p.createElement(t.tag,g(g({key:e},Z(t,r,n)),i),(J(t,r).children||[]).map(function(a,s){return D(a,"".concat(e,"-").concat(t.tag,"-").concat(s),r,void 0,n)}))}function Z(t,e,r){var i=g({},t.attrs);r!=null&&r.colorChannel1&&i.fill==="colorChannel1"&&(i.fill=r.colorChannel1);var n=e.defIds;return!n||n.length===0||(t.tag==="use"&&i["xlink:href"]&&(i["xlink:href"]=i["xlink:href"]+e.idSuffix),Object.entries(i).forEach(function(a){var s=a[0],l=a[1];typeof l=="string"&&(i[s]=l.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),i}function J(t,e){var r,i=e.defIds;return!i||i.length===0?t:t.tag==="defs"&&(!((r=t.children)===null||r===void 0)&&r.length)?g(g({},t),{children:t.children.map(function(n){return typeof n.attrs.id=="string"&&i&&i.indexOf(n.attrs.id)>-1?g(g({},n),{attrs:g(g({},n.attrs),{id:n.attrs.id+e.idSuffix})}):n})}):t}function Y(){return Math.random().toString(36).substring(2,8)}E.displayName="UniverIcon";var Q={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_217_40",style:{maskType:"alpha"},width:17,height:17,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#D9D9D9",d:"M0.9 0.09H16.9V16.09H0.9z"}}]},{tag:"g",attrs:{mask:"url(#mask0_217_40)"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.39551 7.37266C2.39551 4.18105 4.98281 1.59375 8.17441 1.59375C11.366 1.59375 13.9533 4.18105 13.9533 7.37266C13.9533 8.72342 13.4898 9.96603 12.7133 10.95L15.1964 13.4331C15.4619 13.6986 15.4619 14.1291 15.1964 14.3946C14.9309 14.6601 14.5004 14.6601 14.2349 14.3946L11.7518 11.9115C10.7678 12.6881 9.52525 13.1516 8.17441 13.1516C4.98281 13.1516 2.39551 10.5642 2.39551 7.37266ZM8.17441 2.95349C5.73378 2.95349 3.75525 4.93202 3.75525 7.37266C3.75525 9.81333 5.73378 11.7918 8.17441 11.7918C10.6151 11.7918 12.5936 9.81333 12.5936 7.37266C12.5936 4.93202 10.6151 2.95349 8.17441 2.95349Z",fillRule:"evenodd",clipRule:"evenodd"}}]}]},N=p.forwardRef(function(t,e){return p.createElement(E,Object.assign({},t,{id:"search-single-16",ref:e,icon:Q}))});N.displayName="SearchSingle16";var X=Object.defineProperty,$=Object.getOwnPropertyDescriptor,U=(t,e,r,i)=>{for(var n=i>1?void 0:i?$(e,r):e,a=t.length-1,s;a>=0;a--)(s=t[a])&&(n=(i?s(e,r,n):s(n))||n);return i&&n&&X(e,r,n),n},M=(t,e)=>(r,i)=>e(r,i,t);class q extends o.Disposable{}const x=v.createIdentifier("univer.find-replace.service");let j=class extends o.Disposable{constructor(e,r,i,n){super();u(this,"_matchPositionFindModel",null);u(this,"_findModels",[]);u(this,"_matches",[]);u(this,"_positionModel",null);this._state=e,this._providers=r,this._logService=i,this._univerInstanceService=n,this._state.stateUpdates$.subscribe(a=>{typeof a.findString<"u"&&(a.findString?this.find():this._cancelFinding())})}async find(){this._cancelFinding();const e=Array.from(this._providers),r=this._findModels=(await Promise.all(e.map(a=>a.find({text:this._state.findString})))).flat(),i=r.map(a=>a.getMatches()).flat();if(this._matches=i,!i.length)return{results:[]};const n=this._moveToInitialMatch(r,i);return this._state.changeState({matchesCount:i.length,matchesPosition:n+1}),{results:i}}moveToNextMatch(){if(!this._positionModel)return;const e=this._findModels.length===1,r=this._positionModel.moveToNextMatch(e);if(r){const i=this._matches.findIndex(n=>n===r);this._state.changeState({matchesPosition:i+1})}else{const i=this._findModels.findIndex(l=>l===this._positionModel),n=this._findModels[(i+1)%this._findModels.length],a=n.moveToNextMatch(),s=this._matches.findIndex(l=>l===a);this._positionModel=n,this._state.changeState({matchesPosition:s+1})}}moveToPreviousMatch(){if(!this._positionModel)return;const e=this._findModels.length===1,r=this._positionModel.moveToPreviousMatch(e);if(r){const i=this._matches.findIndex(n=>n===r);this._state.changeState({matchesPosition:i+1})}else{const i=this._findModels.findIndex(l=>l===this._positionModel),n=this._findModels[(i-1+this._findModels.length)%this._findModels.length],a=n.moveToPreviousMatch(),s=this._matches.findIndex(l=>l===a);this._positionModel=n,this._state.changeState({matchesPosition:s+1})}}_moveToInitialMatch(e,r){var l;const i=(l=this._univerInstanceService.getFocusedUniverInstance())==null?void 0:l.getUnitId();if(!i)return-1;const n=e.find(m=>m.unitId===i);if(n){this._positionModel=n;const m=n.moveToNextMatch();return r.findIndex(I=>I===m)}this._positionModel=e[0];const a=this._positionModel.moveToNextMatch();return this._matches.findIndex(m=>m===a)}_cancelFinding(){this._providers.forEach(e=>e.cancel()),this._state.changeState({matchesCount:0,matchesPosition:0})}};j=U([M(2,o.ILogService),M(3,o.IUniverInstanceService)],j);function L(){return{revealed:!0,findString:"",replaceRevealed:!1,matchesPosition:0,matchesCount:0}}class ee{constructor(){u(this,"_stateUpdates$",new O.Subject);u(this,"stateUpdates$",this._stateUpdates$.asObservable());u(this,"_state$",new O.BehaviorSubject(L()));u(this,"state$",this._state$.asObservable());u(this,"_findString","");u(this,"_revealed",!1);u(this,"_replaceRevealed",!1);u(this,"_matchesPosition",0);u(this,"_matchesCount",0)}get state(){return this._state$.getValue()}get findString(){return this._findString}changeState(e){let r=!1;const i={};typeof e.findString<"u"&&e.findString!==this._findString&&(this._findString=e.findString,i.findString=this._findString,r=!0),typeof e.revealed<"u"&&e.revealed!==this._revealed&&(this._revealed=e.revealed,i.revealed=e.revealed,r=!0),typeof e.replaceRevealed<"u"&&e.replaceRevealed!==this._replaceRevealed&&(this._replaceRevealed=e.replaceRevealed,i.replaceRevealed=e.replaceRevealed,r=!0),typeof e.matchesCount<"u"&&e.matchesCount!==this._matchesCount&&(this._matchesCount=e.matchesCount,i.matchesCount=e.matchesCount,r=!0),typeof e.matchesPosition<"u"&&e.matchesPosition!==this._matchesPosition&&(this._matchesPosition=e.matchesPosition,i.matchesPosition=e.matchesPosition,r=!0),r&&(this._stateUpdates$.next(i),this._state$.next({findString:this._findString,revealed:this._revealed,replaceRevealed:this._replaceRevealed,matchesCount:this._matchesCount,matchesPosition:this._matchesPosition}))}}let b=class extends o.Disposable{constructor(e,r,i){super();u(this,"_providers",new Set);u(this,"_state",new ee);u(this,"_model");this._injector=e,this._univerInstanceService=r,this._logService=i}get stateUpdates$(){return this._state.stateUpdates$}get state$(){return this._state.state$}changeFindString(e){this._state.changeState({findString:e})}moveToNextMatch(){var e;this._model&&((e=this._model)==null||e.moveToNextMatch())}moveToPreviousMatch(){var e;this._model&&((e=this._model)==null||e.moveToPreviousMatch())}replace(){return!0}replaceAll(){return!0}revealReplace(){this._state.changeState({replaceRevealed:!0})}disposeModel(){var e;(e=this._model)==null||e.dispose(),this._model=null}start(){if(this._providers.size===0)return!1;this._model=this._injector.createInstance(j,this._state,this._providers);const e=L();return e.revealed=!0,this._state.changeState(e),!0}end(){return this._state.changeState({revealed:!1,replaceRevealed:!1}),!0}registerFindReplaceProvider(e){return this._providers.add(e),o.toDisposable(()=>this._providers.delete(e))}};b=U([M(0,v.Inject(v.Injector)),M(1,o.IUniverInstanceService),M(2,o.ILogService)],b);const F={id:"ui.operation.open-find-dialog",type:o.CommandType.OPERATION,handler:t=>(t.get(x).start(),!0)},w={id:"ui.operation.open-replace-dialog",type:o.CommandType.OPERATION,handler:t=>(t.get(x).start(),!0)},te={id:"ui.operation.toggle-replace-dialog",type:o.CommandType.OPERATION,handler:t=>(t.get(x),!0)},A={id:"ui.operation.close-find-replace-dialog",type:o.CommandType.OPERATION,handler:t=>!0},V={type:o.CommandType.OPERATION,id:"ui.operation.go-to-next-match",handler:t=>(t.get(x).moveToNextMatch(),!0)},B={type:o.CommandType.OPERATION,id:"ui.operation.go-to-previous-match",handler:t=>(t.get(x).moveToPreviousMatch(),!0)},R="FIND_REPLACE_ACTIVATED";var K={exports:{}},y={};/**
1
+ (function(c,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("@univerjs/ui"),require("rxjs"),require("react"),require("@univerjs/design"),require("@wendellhu/redi/react-bindings")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","@univerjs/ui","rxjs","react","@univerjs/design","@wendellhu/redi/react-bindings"],o):(c=typeof globalThis<"u"?globalThis:c||self,o(c.UniverFindReplace={},c.UniverCore,c["@wendellhu/redi"],c.UniverUi,c.rxjs,c.React,c.UniverDesign,c["@wendellhu/redi/react-bindings"]))})(this,function(c,o,v,h,O,p,_,T){"use strict";var je=Object.defineProperty;var be=(c,o,v)=>o in c?je(c,o,{enumerable:!0,configurable:!0,writable:!0,value:v}):c[o]=v;var u=(c,o,v)=>(be(c,typeof o!="symbol"?o+"":o,v),v);var g=function(){return g=Object.assign||function(t){for(var e,r=1,i=arguments.length;r<i;r++){e=arguments[r];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])}return t},g.apply(this,arguments)},z=function(t,e){var r={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(r[i]=t[i]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var n=0,i=Object.getOwnPropertySymbols(t);n<i.length;n++)e.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(t,i[n])&&(r[i[n]]=t[i[n]]);return r},E=p.forwardRef(function(t,e){var r=t.icon,i=t.id,n=t.className,a=t.extend,s=z(t,["icon","id","className","extend"]),l="univerjs-icon univerjs-icon-".concat(i," ").concat(n||"").trim(),m=p.useRef("_".concat(Y()));return D(r,"".concat(i),{defIds:r.defIds,idSuffix:m.current},g({ref:e,className:l},s),a)});function D(t,e,r,i,n){return p.createElement(t.tag,g(g({key:e},Z(t,r,n)),i),(J(t,r).children||[]).map(function(a,s){return D(a,"".concat(e,"-").concat(t.tag,"-").concat(s),r,void 0,n)}))}function Z(t,e,r){var i=g({},t.attrs);r!=null&&r.colorChannel1&&i.fill==="colorChannel1"&&(i.fill=r.colorChannel1);var n=e.defIds;return!n||n.length===0||(t.tag==="use"&&i["xlink:href"]&&(i["xlink:href"]=i["xlink:href"]+e.idSuffix),Object.entries(i).forEach(function(a){var s=a[0],l=a[1];typeof l=="string"&&(i[s]=l.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),i}function J(t,e){var r,i=e.defIds;return!i||i.length===0?t:t.tag==="defs"&&(!((r=t.children)===null||r===void 0)&&r.length)?g(g({},t),{children:t.children.map(function(n){return typeof n.attrs.id=="string"&&i&&i.indexOf(n.attrs.id)>-1?g(g({},n),{attrs:g(g({},n.attrs),{id:n.attrs.id+e.idSuffix})}):n})}):t}function Y(){return Math.random().toString(36).substring(2,8)}E.displayName="UniverIcon";var Q={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_217_40",style:{maskType:"alpha"},width:17,height:17,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#D9D9D9",d:"M0.9 0.09H16.9V16.09H0.9z"}}]},{tag:"g",attrs:{mask:"url(#mask0_217_40)"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.39551 7.37266C2.39551 4.18105 4.98281 1.59375 8.17441 1.59375C11.366 1.59375 13.9533 4.18105 13.9533 7.37266C13.9533 8.72342 13.4898 9.96603 12.7133 10.95L15.1964 13.4331C15.4619 13.6986 15.4619 14.1291 15.1964 14.3946C14.9309 14.6601 14.5004 14.6601 14.2349 14.3946L11.7518 11.9115C10.7678 12.6881 9.52525 13.1516 8.17441 13.1516C4.98281 13.1516 2.39551 10.5642 2.39551 7.37266ZM8.17441 2.95349C5.73378 2.95349 3.75525 4.93202 3.75525 7.37266C3.75525 9.81333 5.73378 11.7918 8.17441 11.7918C10.6151 11.7918 12.5936 9.81333 12.5936 7.37266C12.5936 4.93202 10.6151 2.95349 8.17441 2.95349Z",fillRule:"evenodd",clipRule:"evenodd"}}]}]},N=p.forwardRef(function(t,e){return p.createElement(E,Object.assign({},t,{id:"search-single-16",ref:e,icon:Q}))});N.displayName="SearchSingle16";var X=Object.defineProperty,$=Object.getOwnPropertyDescriptor,U=(t,e,r,i)=>{for(var n=i>1?void 0:i?$(e,r):e,a=t.length-1,s;a>=0;a--)(s=t[a])&&(n=(i?s(e,r,n):s(n))||n);return i&&n&&X(e,r,n),n},M=(t,e)=>(r,i)=>e(r,i,t);class q extends o.Disposable{}const x=v.createIdentifier("univer.find-replace.service");class ee{constructor(){u(this,"_stateUpdates$",new O.Subject);u(this,"stateUpdates$",this._stateUpdates$.asObservable());u(this,"_state$",new O.BehaviorSubject(L()));u(this,"state$",this._state$.asObservable());u(this,"_findString","");u(this,"_revealed",!1);u(this,"_replaceRevealed",!1);u(this,"_matchesPosition",0);u(this,"_matchesCount",0)}get state(){return this._state$.getValue()}get findString(){return this._findString}changeState(e){let r=!1;const i={};typeof e.findString<"u"&&e.findString!==this._findString&&(this._findString=e.findString,i.findString=this._findString,r=!0),typeof e.revealed<"u"&&e.revealed!==this._revealed&&(this._revealed=e.revealed,i.revealed=e.revealed,r=!0),typeof e.replaceRevealed<"u"&&e.replaceRevealed!==this._replaceRevealed&&(this._replaceRevealed=e.replaceRevealed,i.replaceRevealed=e.replaceRevealed,r=!0),typeof e.matchesCount<"u"&&e.matchesCount!==this._matchesCount&&(this._matchesCount=e.matchesCount,i.matchesCount=e.matchesCount,r=!0),typeof e.matchesPosition<"u"&&e.matchesPosition!==this._matchesPosition&&(this._matchesPosition=e.matchesPosition,i.matchesPosition=e.matchesPosition,r=!0),r&&(this._stateUpdates$.next(i),this._state$.next({findString:this._findString,revealed:this._revealed,replaceRevealed:this._replaceRevealed,matchesCount:this._matchesCount,matchesPosition:this._matchesPosition}))}}let j=class extends o.Disposable{constructor(e,r,i,n){super();u(this,"_matchPositionFindModel",null);u(this,"_findModels",[]);u(this,"_matches",[]);u(this,"_positionModel",null);this._state=e,this._providers=r,this._logService=i,this._univerInstanceService=n,this._state.stateUpdates$.subscribe(a=>{typeof a.findString<"u"&&(a.findString?this.find():this._cancelFinding())})}async find(){this._cancelFinding();const e=Array.from(this._providers),r=this._findModels=(await Promise.all(e.map(a=>a.find({text:this._state.findString})))).flat(),i=r.map(a=>a.getMatches()).flat();if(this._matches=i,!i.length)return{results:[]};const n=this._moveToInitialMatch(r,i);return this._state.changeState({matchesCount:i.length,matchesPosition:n+1}),{results:i}}moveToNextMatch(){if(!this._positionModel)return;const e=this._findModels.length===1,r=this._positionModel.moveToNextMatch(e);if(r){const i=this._matches.findIndex(n=>n===r);this._state.changeState({matchesPosition:i+1})}else{const i=this._findModels.findIndex(l=>l===this._positionModel),n=this._findModels[(i+1)%this._findModels.length],a=n.moveToNextMatch(),s=this._matches.findIndex(l=>l===a);this._positionModel=n,this._state.changeState({matchesPosition:s+1})}}moveToPreviousMatch(){if(!this._positionModel)return;const e=this._findModels.length===1,r=this._positionModel.moveToPreviousMatch(e);if(r){const i=this._matches.findIndex(n=>n===r);this._state.changeState({matchesPosition:i+1})}else{const i=this._findModels.findIndex(l=>l===this._positionModel),n=this._findModels[(i-1+this._findModels.length)%this._findModels.length],a=n.moveToPreviousMatch(),s=this._matches.findIndex(l=>l===a);this._positionModel=n,this._state.changeState({matchesPosition:s+1})}}_moveToInitialMatch(e,r){var l;const i=(l=this._univerInstanceService.getFocusedUniverInstance())==null?void 0:l.getUnitId();if(!i)return-1;const n=e.find(m=>m.unitId===i);if(n){this._positionModel=n;const m=n.moveToNextMatch();return r.findIndex(I=>I===m)}this._positionModel=e[0];const a=this._positionModel.moveToNextMatch();return this._matches.findIndex(m=>m===a)}_cancelFinding(){this._providers.forEach(e=>e.cancel()),this._state.changeState({matchesCount:0,matchesPosition:0})}};j=U([M(2,o.ILogService),M(3,o.IUniverInstanceService)],j);function L(){return{revealed:!0,findString:"",replaceRevealed:!1,matchesPosition:0,matchesCount:0}}let b=class extends o.Disposable{constructor(e,r,i){super();u(this,"_providers",new Set);u(this,"_state",new ee);u(this,"_model");this._injector=e,this._univerInstanceService=r,this._logService=i}get stateUpdates$(){return this._state.stateUpdates$}get state$(){return this._state.state$}changeFindString(e){this._state.changeState({findString:e})}moveToNextMatch(){var e;this._model&&((e=this._model)==null||e.moveToNextMatch())}moveToPreviousMatch(){var e;this._model&&((e=this._model)==null||e.moveToPreviousMatch())}replace(){return!0}replaceAll(){return!0}revealReplace(){this._state.changeState({replaceRevealed:!0})}disposeModel(){var e;(e=this._model)==null||e.dispose(),this._model=null}start(){if(this._providers.size===0)return!1;this._model=this._injector.createInstance(j,this._state,this._providers);const e=L();return e.revealed=!0,this._state.changeState(e),!0}end(){return this._state.changeState({revealed:!1,replaceRevealed:!1}),!0}registerFindReplaceProvider(e){return this._providers.add(e),o.toDisposable(()=>this._providers.delete(e))}};b=U([M(0,v.Inject(v.Injector)),M(1,o.IUniverInstanceService),M(2,o.ILogService)],b);const F={id:"ui.operation.open-find-dialog",type:o.CommandType.OPERATION,handler:t=>(t.get(x).start(),!0)},w={id:"ui.operation.open-replace-dialog",type:o.CommandType.OPERATION,handler:t=>(t.get(x).start(),!0)},te={id:"ui.operation.toggle-replace-dialog",type:o.CommandType.OPERATION,handler:t=>(t.get(x),!0)},A={id:"ui.operation.close-find-replace-dialog",type:o.CommandType.OPERATION,handler:t=>!0},V={type:o.CommandType.OPERATION,id:"ui.operation.go-to-next-match",handler:t=>(t.get(x).moveToNextMatch(),!0)},B={type:o.CommandType.OPERATION,id:"ui.operation.go-to-previous-match",handler:t=>(t.get(x).moveToPreviousMatch(),!0)},R="FIND_REPLACE_ACTIVATED";var K={exports:{}},y={};/**
2
2
  * @license React
3
3
  * react-jsx-runtime.production.min.js
4
4
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/find-replace",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -48,16 +48,16 @@
48
48
  "npm": ">=8.0.0"
49
49
  },
50
50
  "peerDependencies": {
51
- "@univerjs/icons": "^0.1.28",
51
+ "@univerjs/icons": "^0.1.30",
52
52
  "@wendellhu/redi": "^0.13.0",
53
53
  "react": "^18.2.0",
54
54
  "rxjs": ">=7.0.0",
55
- "@univerjs/core": "0.1.1",
56
- "@univerjs/design": "0.1.1",
57
- "@univerjs/ui": "0.1.1"
55
+ "@univerjs/core": "0.1.2",
56
+ "@univerjs/design": "0.1.2",
57
+ "@univerjs/ui": "0.1.2"
58
58
  },
59
59
  "dependencies": {
60
- "@univerjs/icons": "^0.1.28"
60
+ "@univerjs/icons": "^0.1.30"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@types/react": "^18.2.57",
@@ -67,10 +67,10 @@
67
67
  "typescript": "^5.3.3",
68
68
  "vite": "^5.1.4",
69
69
  "vitest": "^1.3.1",
70
- "@univerjs/core": "0.1.1",
71
- "@univerjs/shared": "0.1.1",
72
- "@univerjs/design": "0.1.1",
73
- "@univerjs/ui": "0.1.1"
70
+ "@univerjs/design": "0.1.2",
71
+ "@univerjs/ui": "0.1.2",
72
+ "@univerjs/core": "0.1.2",
73
+ "@univerjs/shared": "0.1.2"
74
74
  },
75
75
  "scripts": {
76
76
  "test": "vitest run",