@univerjs/find-replace 0.1.0-beta.2 → 0.1.0-beta.4

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.
@@ -1,5 +1,3 @@
1
-
2
-
3
1
  Apache License
4
2
  Version 2.0, January 2004
5
3
  http://www.apache.org/licenses/
package/lib/cjs/index.js CHANGED
@@ -1 +1,9 @@
1
- "use strict";var C=Object.defineProperty;var E=(t,e,i)=>e in t?C(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i;var c=(t,e,i)=>(E(t,typeof e!="symbol"?e+"":e,i),i);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),d=require("@wendellhu/redi"),v=require("rxjs");var g=(t=>(t.VOID="void",t.TOOLBAR_START="uiToolbar.start",t.TOOLBAR_INSERT="uiToolbar.insert",t.TOOLBAR_FORMULAS="uiToolbar.formulas",t.TOOLBAR_DATA="uiToolbar.data",t.TOOLBAR_VIEW="uiToolbar.view",t.TOOLBAR_OTHERS="uiToolbar.others",t.CONTEXT_MENU="contextMenu",t))(g||{}),S=(t=>(t[t.TOOLBAR_HISTORY=0]="TOOLBAR_HISTORY",t[t.TOOLBAR_FORMAT=1]="TOOLBAR_FORMAT",t[t.TOOLBAR_LAYOUT=2]="TOOLBAR_LAYOUT",t[t.TOOLBAR_FORMULAS_INSERT=3]="TOOLBAR_FORMULAS_INSERT",t[t.TOOLBAR_FORMULAS_VIEW=4]="TOOLBAR_FORMULAS_VIEW",t[t.TOOLBAR_FILE=5]="TOOLBAR_FILE",t[t.TOOLBAR_OTHERS=6]="TOOLBAR_OTHERS",t[t.CONTEXT_MENU_FORMAT=7]="CONTEXT_MENU_FORMAT",t[t.CONTEXT_MENU_LAYOUT=8]="CONTEXT_MENU_LAYOUT",t[t.CONTEXT_MENU_DATA=9]="CONTEXT_MENU_DATA",t[t.CONTEXT_MENU_OTHERS=10]="CONTEXT_MENU_OTHERS",t))(S||{}),A=(t=>(t[t.BUTTON=0]="BUTTON",t[t.SELECTOR=1]="SELECTOR",t[t.BUTTON_SELECTOR=2]="BUTTON_SELECTOR",t[t.SUBITEMS=3]="SUBITEMS",t))(A||{});function R(t,e,i){return document.addEventListener(t,e,i),o.toDisposable(()=>document.removeEventListener(t,e,i))}class L{constructor(){c(this,"_containers",[])}registerContainer(e){if(this._containers.indexOf(e)===-1)return this._containers.push(e),o.toDisposable(()=>o.remove(this._containers,e));throw new Error("[LayoutService]: container already registered!")}checkElementInCurrentApplicationScope(e){return this._containers.some(i=>i.contains(e))}}const I=d.createIdentifier("univer.platform-service"),D={8:"Backspace",9:"Tab",13:"Enter",46:"Del",27:"Esc",32:"Space",37:"←",39:"",38:"↑",40:"↓",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z",189:"-",187:"="};var _=(t=>(t[t.SHIFT=1024]="SHIFT",t[t.ALT=2048]="ALT",t[t.CTRL_COMMAND=4096]="CTRL_COMMAND",t[t.MAC_CTRL=8192]="MAC_CTRL",t))(_||{}),b=Object.defineProperty,B=Object.getOwnPropertyDescriptor,y=(t,e,i,s)=>{for(var r=s>1?void 0:s?B(e,i):e,n=t.length-1,a;n>=0;n--)(a=t[n])&&(r=(s?a(e,i,r):a(r))||r);return s&&r&&b(e,i,r),r},l=(t,e)=>(i,s)=>e(i,s,t);const M=d.createIdentifier("univer.shortcut");let T=class extends o.Disposable{constructor(e,i,s,r){super();c(this,"_shortCutMapping",new Map);c(this,"_commandIDMapping",new Map);c(this,"_shortcutChanged$",new v.Subject);c(this,"shortcutChanged$",this._shortcutChanged$.asObservable());c(this,"_forceEscaped",!1);c(this,"_disable",!1);this._commandService=e,this._platformService=i,this._contextService=s,this._layoutService=r,this.disposeWithMe(R("keydown",n=>{this._resolveKeyboardEvent(n)}))}setDisable(e){this._disable=e}getAllShortcuts(){return Array.from(this._shortCutMapping.values()).map(e=>Array.from(e.values())).flat()}registerShortcut(e){const i=this._getBindingFromItem(e),s=this._shortCutMapping.get(i);s?s.add(e):this._shortCutMapping.set(i,new Set([e]));const r=e.id,n=this._commandIDMapping.get(r);return n?n.add(e):this._commandIDMapping.set(r,new Set([e])),this._emitShortcutChanged(),o.toDisposable(()=>{var a,h,O,p;(a=this._shortCutMapping.get(i))==null||a.delete(e),((h=this._shortCutMapping.get(i))==null?void 0:h.size)===0&&this._shortCutMapping.delete(i),(O=this._commandIDMapping.get(r))==null||O.delete(e),((p=this._commandIDMapping.get(r))==null?void 0:p.size)===0&&this._commandIDMapping.delete(r),this._emitShortcutChanged()})}getShortcutDisplayOfCommand(e){const i=this._commandIDMapping.get(e);return i?this.getShortcutDisplay(i.values().next().value):null}getShortcutDisplay(e){const i=this._getBindingFromItem(e),s=i&_.CTRL_COMMAND,r=i&_.SHIFT,n=i&_.ALT,a=i&_.MAC_CTRL,h=D[i&255]??"<->";return this._platformService.isMac?`${s?"⌘":""}${r?"⇧":""}${n?"⌥":""}${a?"⌃":""}${h}`:`${s?"Ctrl+":""}${r?"Shift+":""}${n?"Alt+":""}${h}`}_emitShortcutChanged(){this._shortcutChanged$.next()}forceEscape(){return this._forceEscaped=!0,o.toDisposable(()=>this._forceEscaped=!1)}_resolveKeyboardEvent(e){if(this._forceEscaped||this._disable||this._layoutService&&!this._layoutService.checkElementInCurrentApplicationScope(e.target))return;this._dispatch(e)&&e.preventDefault()}_dispatch(e){const i=this._deriveBindingFromEvent(e);if(i===null)return!1;const s=this._shortCutMapping.get(i);if(s===void 0)return!1;const r=Array.from(s).sort((n,a)=>(a.priority??0)-(n.priority??0)).find(n=>{var a;return((a=n.preconditions)==null?void 0:a.call(n,this._contextService))??!0});return r?(this._commandService.executeCommand(r.id,r.staticParameters),!0):!1}_getBindingFromItem(e){return this._platformService.isMac&&e.mac?e.mac:this._platformService.isWindows&&e.win?e.win:this._platformService.isLinux&&e.linux?e.linux:e.binding}_deriveBindingFromEvent(e){const{shiftKey:i,metaKey:s,altKey:r,keyCode:n}=e;let a=n;return i&&(a|=_.SHIFT),r&&(a|=_.ALT),(this._platformService.isMac?s:e.ctrlKey)&&(a|=_.CTRL_COMMAND),this._platformService.isMac&&e.ctrlKey&&(a|=_.MAC_CTRL),a}};T=y([l(0,o.ICommandService),l(1,I),l(2,o.IContextService),l(3,d.Optional(L))],T);var N=Object.defineProperty,P=Object.getOwnPropertyDescriptor,U=(t,e,i,s)=>{for(var r=s>1?void 0:s?P(e,i):e,n=t.length-1,a;n>=0;n--)(a=t[n])&&(r=(s?a(e,i,r):a(r))||r);return s&&r&&N(e,i,r),r},$=(t,e)=>(i,s)=>e(i,s,t);const F=d.createIdentifier("univer.menu-service");let f=class extends o.Disposable{constructor(e){super();c(this,"_menuItemMap",new Map);c(this,"_menuByPositions",new Map);c(this,"_menuChanged$",new v.BehaviorSubject(void 0));c(this,"menuChanged$",this._menuChanged$.asObservable());this._shortcutService=e}dispose(){this._menuItemMap.clear(),this._menuChanged$.complete()}addMenuItem(e){if(this._menuItemMap.has(e.id))throw new Error(`Menu item with the same id ${e.id} has already been added!`);return this._menuItemMap.set(e.id,e),Array.isArray(e.positions)?e.positions.forEach(i=>this._appendMenuToPosition(e,i)):this._appendMenuToPosition(e,e.positions),this._menuChanged$.next(),o.toDisposable(()=>{if(this._menuItemMap.delete(e.id),Array.isArray(e.positions))e.positions.forEach(i=>{const s=this._menuByPositions.get(i);if(!s)return;const r=s.findIndex(n=>n[0]===e.id);r>-1&&s.splice(r,1)});else{const i=this._menuByPositions.get(e.positions);if(!i)return;const s=i.findIndex(r=>r[0]===e.id);s>-1&&i.splice(s,1)}this._menuChanged$.next()})}getMenuItems(e){if(this._menuByPositions.has(e)){const i=this._menuByPositions.get(e);if(i)return[...i.values()].map(s=>this._getDisplayMenuItems(s[1]))}return[]}getMenuItem(e){return this._menuItemMap.has(e)?this._menuItemMap.get(e):null}_getDisplayMenuItems(e){const i=this._shortcutService.getShortcutDisplayOfCommand(e.id);return i?{...e,shortcut:i}:e}_appendMenuToPosition(e,i){this._menuByPositions.has(i)||this._menuByPositions.set(i,[]);const s=this._menuByPositions.get(i);if(s.findIndex(r=>r[0]===e.id)>-1)throw new Error(`Menu item with the same id ${e.id} has already been added!`);s.push([e.id,e])}};f=U([$(0,M)],f);const w={type:o.CommandType.OPERATION,id:"ui.operation.toggle-find-replace-dialog",handler:t=>!0};function x(t){return{id:w.id,tooltip:"toolbar.find-replace",group:S.TOOLBAR_OTHERS,type:A.BUTTON,positions:[g.TOOLBAR_START]}}var j=Object.defineProperty,H=Object.getOwnPropertyDescriptor,X=(t,e,i,s)=>{for(var r=s>1?void 0:s?H(e,i):e,n=t.length-1,a;n>=0;n--)(a=t[n])&&(r=(s?a(e,i,r):a(r))||r);return s&&r&&j(e,i,r),r},m=(t,e)=>(i,s)=>e(i,s,t);let u=class extends o.Disposable{constructor(t,e){super(),this._menuService=t,this._injector=e,[x].forEach(i=>{this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(i)))})}};u=X([o.OnLifecycle(o.LifecycleStages.Steady,u),m(0,F),m(1,d.Inject(d.Injector))],u);const K="FIND_REPLACE";class W extends o.Plugin{constructor(e){super(K),this._injector=e}onStarting(e){[[u]].forEach(i=>{e.add(i)})}}exports.UniverFindReplacePlugin=W;
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:{"mask-type":"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";const ne=$;var re=Object.defineProperty,oe=Object.getOwnPropertyDescriptor,A=(t,e,n,i)=>{for(var r=i>1?void 0:i?oe(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&&re(e,n,r),r},I=(t,e)=>(n,i)=>e(n,i,t);class ae 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=A([I(2,s.ILogService),I(3,s.IUniverInstanceService)],T);function L(){return{revealed:!0,findString:"",replaceRevealed:!1,matchesPosition:0,matchesCount:0}}class se{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 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 se);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=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),s.toDisposable(()=>this._providers.delete(e))}};b=A([I(0,S.Inject(S.Injector)),I(1,s.IUniverInstanceService),I(2,s.ILogService)],b);const F={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)},ce={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
+ * @license React
3
+ * react-jsx-runtime.production.min.js
4
+ *
5
+ * Copyright (c) Facebook, Inc. and its affiliates.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */var le=p,de=Symbol.for("react.element"),ue=Symbol.for("react.fragment"),he=Object.prototype.hasOwnProperty,pe=le.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,fe={key:!0,ref:!0,__self:!0,__source:!0};function k(t,e,n){var i,r={},o=null,a=null;n!==void 0&&(o=""+n),e.key!==void 0&&(o=""+e.key),e.ref!==void 0&&(a=e.ref);for(i in e)he.call(e,i)&&!fe.hasOwnProperty(i)&&(r[i]=e[i]);if(t&&t.defaultProps)for(i in e=t.defaultProps,e)r[i]===void 0&&(r[i]=e[i]);return{$$typeof:de,type:t,key:o,ref:a,props:r,_owner:pe.current}}y.Fragment=ue;y.jsx=k;y.jsxs=k;K.exports=y;var h=K.exports;const ve="univer-find-replace-expand-container",E={findReplaceExpandContainer:ve};function _e(){const t=P.useDependency(m),e=P.useDependency(s.LocaleService),n=P.useDependency(d.LayoutService),[i,r]=p.useState(""),[o,a]=p.useState(""),c=p.useRef(null),v=f.useObservable(t.state$,!0),{matchesCount:R,matchesPosition:C}=v,G=p.useCallback(()=>t.revealReplace(),[t]),H=p.useCallback(l=>t.changeFindString(l),[t]),W=p.useCallback(l=>{r(l),H(l)},[t]),j=p.useCallback(l=>{a(l)},[t]);p.useEffect(()=>{let l;return c.current&&(l=n.registerContainer(c.current)),()=>l==null?void 0:l.dispose()},[c.current]);function z(){return h.jsxs(p.Fragment,{children:[h.jsx(f.InputWithSlot,{autoFocus:!0,placeholder:e.t("univer.find-replace.dialog.find-placeholder"),slot:h.jsx(f.Pager,{loop:!0,value:C,total:R,onChange:l=>{C===R&&l===1?t.moveToNextMatch():C===1&&l===R||l<C?t.moveToPreviousMatch():t.moveToNextMatch()}}),value:i,onChange:l=>W(l)}),h.jsx("div",{className:E.findReplaceExpandContainer,children:h.jsx(f.Button,{type:"text",size:"small",onClick:G,children:e.t("univer.find-replace.dialog.advanced-finding")})})]})}function Z(){return h.jsxs(p.Fragment,{children:[h.jsx(f.FormLayout,{label:e.t("univer.find-replace.dialog.find"),children:h.jsx(f.Input,{placeholder:e.t("univer.find-replace.dialog.find-placeholder"),autoFocus:!0,value:i,onChange:l=>j(l)})}),h.jsx(f.FormLayout,{label:e.t("univer.find-replace.dialog.replace"),children:h.jsx(f.Input,{placeholder:e.t("univer.find-replace.dialog.replace-placeholder"),value:o,onChange:l=>j(l)})}),h.jsx(f.FormLayout,{label:e.t("univer.find-replace.dialog.find-range"),children:h.jsx(f.Select,{value:"123",onChange:()=>{}})}),h.jsx(f.Button,{type:"primary",children:e.t("univer.find-replace.dialog.find")}),h.jsx(f.Button,{children:e.t("univer.find-replace.dialog.replace")}),h.jsx(f.Button,{children:e.t("univer.find-replace.dialog.replace-all")})]})}return h.jsx("div",{className:E.findReplaceDialogContainer,ref:c,children:v.replaceRevealed?Z():z()})}function ge(t){return{id:F.id,icon:"SearchIcon",tooltip:"toolbar.find-replace",group:d.MenuGroup.TOOLBAR_OTHERS,type:d.MenuItemType.BUTTON,positions:[d.MenuPosition.TOOLBAR_START],hidden$:d.getMenuHiddenObservable(t,s.UniverInstanceType.SHEET)}}const me={id:F.id,description:"shortcut.find-replace.open-find-dialog",binding:d.KeyCode.F|d.MetaKeys.CTRL_COMMAND,group:"4_find-replace",preconditions(t){return!t.getContextValue(x)}},Se={id:w.id,description:"shortcut.find-replace.open-replace-dialog",binding:d.KeyCode.H|d.MetaKeys.CTRL_COMMAND,group:"4_find-replace",preconditions(t){return!t.getContextValue(x)}},xe={id:B.id,description:"shortcut.find-replace.close-dialog",binding:d.KeyCode.ESC,group:"4_find-replace",priority:1e3,preconditions(t){return!!t.getContextValue(x)}},Re={id:V.id,description:"shortcut.find-replace.go-to-next-find-match",binding:d.KeyCode.ENTER,group:"4_find-replace",priority:1e3,preconditions(t){return!!t.getContextValue(x)}},Ce={id:q.id,description:"shortcut.find-replace.go-to-previous-find-match",binding:d.KeyCode.ENTER|d.MetaKeys.SHIFT,group:"4_find-replace",priority:1e3,preconditions(t){return!!t.getContextValue(x)}};var Ie=Object.defineProperty,Me=Object.getOwnPropertyDescriptor,ye=(t,e,n,i)=>{for(var r=i>1?void 0:i?Me(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&&Ie(e,n,r),r},g=(t,e)=>(n,i)=>e(n,i,t);const D="DESKTOP_FIND_REPLACE_DIALOG";let M=class extends s.RxDisposable{constructor(t,e,n,i,r,o,a,c,v,R){super(),this._menuService=t,this._shortcutService=e,this._commandService=n,this._findReplaceService=i,this._dialogService=r,this._contextService=o,this._focusService=a,this._localeService=c,this._componentManager=v,this._injector=R,this._initOperations(),this._initUI(),this._initShortcuts()}_initOperations(){[B,F,w,ce,V,q].forEach(t=>{this.disposeWithMe(this._commandService.registerCommand(t))})}_initUI(){[ge].forEach(t=>{this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(t)))}),this.disposeWithMe(this._componentManager.register("FindReplaceDialog",_e)),this.disposeWithMe(this._componentManager.register("SearchIcon",ne)),this._findReplaceService.stateUpdates$.pipe(O.takeUntil(this.dispose$)).subscribe(t=>{t.revealed===!0?this._openPanel():t.revealed===!1&&this._closePanel()})}_initShortcuts(){[Se,me,xe,Ce,Re].forEach(t=>{this.disposeWithMe(this._shortcutService.registerShortcut(t))})}_openPanel(){this._dialogService.open({id:D,draggable:!0,width:350,title:{title:this._localeService.t("univer.find-replace.dialog.title")},children:{label:"FindReplaceDialog"},onClose:()=>this._closePanel()}),this._contextService.setContextValue(x,!0)}_closePanel(){this._dialogService.close(D),this._contextService.setContextValue(x,!1),this._focusService.forceFocus(),this._findReplaceService.end()}};M=ye([s.OnLifecycle(s.LifecycleStages.Rendered,M),g(0,d.IMenuService),g(1,d.IShortcutService),g(2,s.ICommandService),g(3,m),g(4,d.IDialogService),g(5,s.IContextService),g(6,d.IFocusService),g(7,S.Inject(s.LocaleService)),g(8,S.Inject(d.ComponentManager)),g(9,S.Inject(S.Injector))],M);const Pe={univer:{"find-replace":{dialog:{title:"查找",find:"查找",replace:"替换","replace-all":"替换全部","find-range":"查找范围","find-placeholder":"输入查找内容","advanced-finding":"替换 / 高级查找","replace-placeholder":"输入替换内容"}}}};var Oe=Object.defineProperty,Te=Object.getOwnPropertyDescriptor,be=(t,e,n,i)=>{for(var r=i>1?void 0:i?Te(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&&Oe(e,n,r),r},Fe=(t,e)=>(n,i)=>e(n,i,t);const je="FIND_REPLACE";exports.UniverFindReplacePlugin=class extends s.Plugin{constructor(e,n){super(je),this._injector=e,this._localeService=n,this._localeService.load({zhCN:Pe})}onStarting(e){[[M],[m,{useClass:b}]].forEach(n=>{e.add(n)})}};exports.UniverFindReplacePlugin=be([Fe(1,S.Inject(s.LocaleService))],exports.UniverFindReplacePlugin);exports.FindModel=ae;exports.IFindReplaceService=m;