@univerjs/find-replace 0.13.0 → 0.14.0-insiders.20251227-b250a8d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +22 -22
- package/lib/index.js +22 -22
- package/lib/umd/index.js +1 -1
- package/package.json +9 -9
- package/LICENSE +0 -176
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var Fe=Object.defineProperty;var Ie=(t,e,n)=>e in t?Fe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var u=(t,e,n)=>Ie(t,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),c=require("@univerjs/ui"),f=require("@univerjs/design"),De=require("@univerjs/engine-render"),_=require("rxjs"),h=require("react"),d=require("react/jsx-runtime"),H="FIND_REPLACE_INPUT_FOCUS",q="FIND_REPLACE_DIALOG_FOCUS",Z="FIND_REPLACE_REPLACE_REVEALED";var xe=Object.getOwnPropertyDescriptor,z=(t,e,n,i)=>{for(var s=i>1?void 0:i?xe(e,n):e,r=t.length-1,a;r>=0;r--)(a=t[r])&&(s=a(s)||s);return s},x=(t,e)=>(n,i)=>e(n,i,t);class Te extends o.Disposable{}const v=o.createIdentifier("find-replace.service");function Pe(t){return typeof t.findString<"u"||typeof t.inputtingFindString<"u"||typeof t.findDirection<"u"||typeof t.matchesTheWholeCell<"u"||typeof t.caseSensitive<"u"||typeof t.findScope<"u"||typeof t.findBy<"u"}exports.FindReplaceModel=class extends o.Disposable{constructor(n,i,s,r){super();u(this,"currentMatch$",new _.BehaviorSubject(null));u(this,"replaceables$",new _.BehaviorSubject([]));u(this,"_findModels",[]);u(this,"_matchingModel",null);u(this,"_matches",[]);u(this,"_currentSearchingDisposables",null);this._state=n,this._providers=i,this._univerInstanceService=s,this._commandService=r,this.disposeWithMe(this._state.stateUpdates$.pipe(_.throttleTime(200,void 0,{leading:!0,trailing:!0})).subscribe(async a=>{const l=this._state.state;Pe(a)&&(l.findString!==""&&!l.replaceRevealed?(await this._startSearching(),this._state.changeState({findCompleted:!0})):a.replaceRevealed!==!0&&this._stopSearching())}))}get searched(){return this._findModels.length>0}dispose(){super.dispose(),this._stopSearching(),this.currentMatch$.complete(),this.replaceables$.complete(),this._state.changeState({...O(),revealed:!1})}async start(){if(!this._state.findString)return{results:[]};const n=await this._startSearching();return this._state.changeState({findCompleted:!0}),n}focusSelection(){var n;(n=this._matchingModel)==null||n.focusSelection()}async _startSearching(){if(!this._state.findString)return{results:[]};const n=Array.from(this._providers),i=this._findModels=(await Promise.all(n.map(r=>r.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(i);const s=this._matches=i.map(r=>r.getMatches()).flat();return this.replaceables$.next(s.filter(r=>r.replaceable)),s.length?(this._moveToInitialMatch(i),this._state.changeState({matchesCount:s.length}),{results:s}):(this._state.changeState({matchesCount:0,matchesPosition:0}),{results:[]})}_stopSearching(){var n;this._providers.forEach(i=>i.terminate()),this._findModels=[],this._matches=[],this._matchingModel=null,(n=this._currentSearchingDisposables)==null||n.dispose(),this._currentSearchingDisposables=null,this.currentMatch$.next(null),this.replaceables$.next([]),this._state.changeState({findCompleted:!1,matchesCount:0,matchesPosition:0})}_subscribeToModelsChanges(n){const i=this._currentSearchingDisposables=new o.DisposableCollection,s=_.combineLatest(n.map(r=>r.matchesUpdate$)).pipe(_.debounceTime(220)).subscribe(([...r])=>{const a=this._matches=r.flat();a.length?(this._moveToInitialMatch(this._findModels,!0),this._state.changeState({matchesCount:a.length}),this.replaceables$.next(a.filter(l=>l.replaceable))):(this._state.changeState({matchesCount:0,matchesPosition:0}),this.replaceables$.next([]))});n.forEach(r=>i.add(o.toDisposable(r.activelyChangingMatch$.subscribe(a=>{const l=this._matches.findIndex(p=>p===a);this._state.changeState({matchesPosition:l+1})})))),i.add(o.toDisposable(s))}async replace(){return this._matchingModel?this._matchingModel.replace(this._state.replaceString):!1}async replaceAll(){const n=await Promise.all(this._findModels.map(i=>i.replaceAll(this._state.replaceString))).then(i=>i.reduce((s,r)=>(s.success+=r.success,s.failure+=r.failure,s),{success:0,failure:0}));return n.failure===0&&this._stopSearching(),n}getCurrentMatch(){return this._state.matchesPosition>0?this._matches[this._state.matchesPosition-1]:null}_markMatch(n){const i=this._matches.findIndex(s=>s===n);this.currentMatch$.next(n),this._state.changeState({matchesPosition:i+1})}moveToNextMatch(){if(!this._matchingModel)return;const n=this._findModels.length===1,i=this._matchingModel.moveToNextMatch({loop:n});if(i)return this._markMatch(i),i;{const s=this._findModels.findIndex(r=>r===this._matchingModel);return this._moveToNextUnitMatch(s)}}_moveToNextUnitMatch(n){const i=this._findModels.length;for(let s=(n+1)%i;s!==n;){const r=this._findModels[s],a=r.moveToNextMatch({ignoreSelection:!0});if(a)return this._matchingModel=r,this._markMatch(a),a;s=(s+1)%i}if(this._matchingModel){const s=this._matchingModel.moveToNextMatch({ignoreSelection:!0});return s&&this._markMatch(s),s}}moveToPreviousMatch(){if(!this._matchingModel)return;const n=this._findModels.length===1,i=this._matchingModel.moveToPreviousMatch({loop:n});if(i){const s=this._matches.findIndex(r=>r===i);return this.currentMatch$.next(i),this._state.changeState({matchesPosition:s+1}),i}else{const s=this._findModels.length,r=this._findModels.findIndex(l=>l===this._matchingModel);for(let l=(r-1+s)%s;l!==r;){const p=this._findModels[l],m=p.moveToPreviousMatch({ignoreSelection:!0});if(m)return this._matchingModel=p,this._markMatch(m),m;l=(l-1)%s}const a=this._matchingModel.moveToPreviousMatch({ignoreSelection:!0});return a&&this._markMatch(a),a}}_moveToInitialMatch(n,i=!1){var a;const s=(a=this._univerInstanceService.getFocusedUnit())==null?void 0:a.getUnitId();if(!s)return-1;const r=n.findIndex(l=>l.unitId===s);if(r!==-1){this._matchingModel=n[r];const l=this._matchingModel.moveToNextMatch({stayIfOnMatch:!0,noFocus:i});if(l)return this._markMatch(l),r}return this._moveToNextUnitMatch(r),0}};exports.FindReplaceModel=z([x(2,o.IUniverInstanceService),x(3,o.ICommandService)],exports.FindReplaceModel);var T=(t=>(t.ROW="row",t.COLUMN="column",t))(T||{}),P=(t=>(t.VALUE="value",t.FORMULA="formula",t))(P||{}),E=(t=>(t.SUBUNIT="subunit",t.UNIT="unit",t))(E||{});function O(){return{caseSensitive:!1,findBy:"value",findCompleted:!1,findDirection:"row",findScope:"subunit",findString:"",inputtingFindString:"",matchesCount:0,matchesPosition:0,matchesTheWholeCell:!1,replaceRevealed:!1,replaceString:"",revealed:!0}}class Y{constructor(){u(this,"_stateUpdates$",new _.Subject);u(this,"stateUpdates$",this._stateUpdates$.asObservable());u(this,"_state$",new _.BehaviorSubject(O()));u(this,"state$",this._state$.asObservable());u(this,"_findString","");u(this,"_inputtingFindString","");u(this,"_replaceString","");u(this,"_revealed",!1);u(this,"_replaceRevealed",!1);u(this,"_matchesPosition",0);u(this,"_matchesCount",0);u(this,"_caseSensitive",!0);u(this,"_matchesTheWholeCell",!1);u(this,"_findDirection","row");u(this,"_findScope","subunit");u(this,"_findBy","value");u(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 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.replaceString<"u"&&e.replaceString!==this._replaceString&&(this._replaceString=e.replaceString,i.replaceString=e.replaceString,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),typeof e.findBy<"u"&&e.findBy!==this._findBy&&(this._findBy=e.findBy,i.findBy=e.findBy,n=!0),typeof e.findScope<"u"&&e.findScope!==this._findScope&&(this._findScope=e.findScope,i.findScope=e.findScope,n=!0),typeof e.findDirection<"u"&&e.findDirection!==this._findDirection&&(this._findDirection=e.findDirection,i.findDirection=e.findDirection,n=!0),typeof e.caseSensitive<"u"&&e.caseSensitive!==this._caseSensitive&&(this._caseSensitive=e.caseSensitive,i.caseSensitive=e.caseSensitive,n=!0),typeof e.matchesTheWholeCell<"u"&&e.matchesTheWholeCell!==this._matchesTheWholeCell&&(this._matchesTheWholeCell=e.matchesTheWholeCell,i.matchesTheWholeCell=e.matchesTheWholeCell,n=!0),typeof e.inputtingFindString<"u"&&e.inputtingFindString!==this._inputtingFindString&&(this._inputtingFindString=e.inputtingFindString,i.inputtingFindString=e.inputtingFindString,n=!0),typeof e.findCompleted<"u"&&e.findCompleted!==this._findCompleted&&(this._findCompleted=e.findCompleted,i.findCompleted=e.findCompleted,n=!0),n&&(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(i))}}let A=class extends o.Disposable{constructor(e,n){super();u(this,"_providers",new Set);u(this,"_state",new Y);u(this,"_model");u(this,"_currentMatch$",new _.BehaviorSubject(null));u(this,"currentMatch$",this._currentMatch$.asObservable());u(this,"_replaceables$",new _.BehaviorSubject([]));u(this,"replaceables$",this._replaceables$.asObservable());u(this,"_focusSignal$",new _.Subject);u(this,"focusSignal$",this._focusSignal$.asObservable());this._injector=e,this._contextService=n}get stateUpdates$(){return this._state.stateUpdates$}get state$(){return this._state.state$}get revealed(){return this._state.revealed}get replaceRevealed(){return this._state.replaceRevealed}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==="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 new 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(exports.FindReplaceModel,this._state,this._providers),this._model.currentMatch$.subscribe(i=>this._currentMatch$.next(i)),this._model.replaceables$.subscribe(i=>this._replaceables$.next(i));const n=O();return e&&(n.replaceRevealed=!0),this._state.changeState(n),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),o.toDisposable(()=>this._providers.delete(e))}_toggleRevealReplace(e){this._contextService.setContextValue(Z,e)}_toggleDisplayRawFormula(e){this._contextService.setContextValue(De.RENDER_RAW_FORMULA_KEY,e)}};A=z([x(0,o.Inject(o.Injector)),x(1,o.IContextService)],A);const j={id:"ui.command.replace-current-match",type:o.CommandType.COMMAND,handler:t=>t.get(v).replace()},Ee="CONFIRM_REPLACE_ALL",w={id:"ui.command.replace-all-matches",type:o.CommandType.COMMAND,handler:async t=>{const e=t.get(c.IConfirmService),n=t.get(o.LocaleService),i=t.get(c.IMessageService);if(!await e.confirm({id:Ee,title:{title:n.t("find-replace.replace.confirm.title")},cancelText:n.t("button.cancel"),confirmText:n.t("button.confirm")}))return!1;const r=await t.get(v).replaceAll(),{success:a,failure:l}=r;return l>0?(a===0?i.show({type:f.MessageType.Error,content:n.t("find-replace.replace.all-failure")}):i.show({type:f.MessageType.Warning,content:n.t("find-replace.replace.partial-success",`${a}`,`${l}`)}),!1):(i.show({type:f.MessageType.Success,content:n.t("find-replace.replace.all-success",`${a}`)}),!0)}},F={id:"ui.operation.open-find-dialog",type:o.CommandType.OPERATION,handler:t=>{const e=t.get(v);return e.revealed?e.focusFindInput():e.start(),!0}},N={id:"ui.operation.open-replace-dialog",type:o.CommandType.OPERATION,handler:t=>{const e=t.get(v);return e.revealed?e.replaceRevealed?e.focusFindInput():e.revealReplace():e.start(!0),!0}},U={type:o.CommandType.OPERATION,id:"ui.operation.go-to-next-match",handler:t=>(t.get(v).moveToNextMatch(),!0)},k={type:o.CommandType.OPERATION,id:"ui.operation.go-to-previous-match",handler:t=>(t.get(v).moveToPreviousMatch(),!0)},J={type:o.CommandType.OPERATION,id:"ui.operation.focus-selection",handler:t=>(t.get(v).focusSelection(),!0)};function Q({ref:t,...e}){const{icon:n,id:i,className:s,extend:r,...a}=e,l=`univerjs-icon univerjs-icon-${i} ${s||""}`.trim(),p=h.useRef(`_${$e()}`);return X(n,`${i}`,{defIds:n.defIds,idSuffix:p.current},{ref:t,className:l,...a},r)}function X(t,e,n,i,s){return h.createElement(t.tag,{key:e,...Oe(t,n,s),...i},(Ne(t,n).children||[]).map((r,a)=>X(r,`${e}-${t.tag}-${a}`,n,void 0,s)))}function Oe(t,e,n){const i={...t.attrs};n!=null&&n.colorChannel1&&i.fill==="colorChannel1"&&(i.fill=n.colorChannel1),t.tag==="mask"&&i.id&&(i.id=i.id+e.idSuffix),Object.entries(i).forEach(([r,a])=>{r==="mask"&&typeof a=="string"&&(i[r]=a.replace(/url\(#(.*)\)/,`url(#$1${e.idSuffix})`))});const{defIds:s}=e;return!s||s.length===0||(t.tag==="use"&&i["xlink:href"]&&(i["xlink:href"]=i["xlink:href"]+e.idSuffix),Object.entries(i).forEach(([r,a])=>{typeof a=="string"&&(i[r]=a.replace(/url\(#(.*)\)/,`url(#$1${e.idSuffix})`))})),i}function Ne(t,e){var i;const{defIds:n}=e;return!n||n.length===0?t:t.tag==="defs"&&((i=t.children)!=null&&i.length)?{...t,children:t.children.map(s=>typeof s.attrs.id=="string"&&n&&n.includes(s.attrs.id)?{...s,attrs:{...s.attrs,id:s.attrs.id+e.idSuffix}}:s)}:t}function $e(){return Math.random().toString(36).substring(2,8)}Q.displayName="UniverIcon";const Le={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"}}]},ee=h.forwardRef(function(e,n){return h.createElement(Q,Object.assign({},e,{id:"search-icon",ref:n,icon:Le}))});ee.displayName="SearchIcon";function te(t){const{findCompleted:e,localeService:n,matchesCount:i,matchesPosition:s,initialFindString:r,findReplaceService:a,onChange:l,...p}=t,[m,S]=h.useState(r),y=e&&i===0?n.t("find-replace.dialog.no-result"):i===0?" ":void 0;function M(C){s===i&&C===1?a.moveToNextMatch():s===1&&C===i||C<s?a.moveToPreviousMatch():a.moveToNextMatch()}return d.jsx("div",{className:"univer-relative univer-flex univer-items-center univer-gap-2",onDrag:C=>C.stopPropagation(),children:d.jsx(f.Input,{"data-u-comp":"search-input",autoFocus:!0,placeholder:n.t("find-replace.dialog.find-placeholder"),value:m,onChange:C=>{S(C),l==null||l(C)},slot:d.jsx(f.Pager,{loop:!0,text:y,value:s,total:i,onChange:M}),...p})})}function ie(t,e){const n=h.useCallback(()=>{var s;(s=document.querySelector(".univer-find-input input"))==null||s.focus()},[]),i=h.useCallback(()=>{const s=document.querySelectorAll("[data-u-comp=find-replace-dialog] [data-u-comp=search-input]");return Array.from(s).some(r=>r===document.activeElement)},[]);return h.useImperativeHandle(e,()=>({focus:n,selectHasFocus:i})),h.useEffect(()=>{const s=t.focusSignal$.subscribe(()=>n());return()=>s.unsubscribe()},[t,n]),{focus:n,selectHasFocus:i}}const Ae=h.forwardRef(function(e,n){const i=c.useDependency(o.LocaleService),s=c.useDependency(v),r=c.useDependency(o.ICommandService),a=c.useObservable(s.state$,void 0,!0),{findCompleted:l,findString:p,matchesCount:m,matchesPosition:S}=a,b=h.useCallback(()=>{r.executeCommand(N.id)},[r]),y=c.useDebounceFn(M=>s.changeFindString(M),500);return ie(s,n),d.jsxs(d.Fragment,{children:[d.jsx(te,{findCompleted:l,matchesCount:m,matchesPosition:S,findReplaceService:s,localeService:i,initialFindString:p,onChange:y}),d.jsx("div",{className:"univer-mt-4 univer-text-center",children:d.jsx("a",{className:"hover:univer-text-primary-500/80 univer-cursor-pointer univer-text-sm univer-text-primary-500 univer-transition-colors",onClick:b,children:i.t("find-replace.dialog.advanced-finding")})})]})}),je=h.forwardRef(function(e,n){const i=c.useDependency(v),s=c.useDependency(o.LocaleService),r=c.useDependency(o.ICommandService),a=c.useDependency(c.IMessageService),l=c.useObservable(i.currentMatch$,void 0,!0),p=c.useObservable(i.replaceables$,void 0,!0),m=c.useObservable(i.state$,void 0,!0),{matchesCount:S,matchesPosition:b,findString:y,inputtingFindString:M,replaceString:C,caseSensitive:re,matchesTheWholeCell:ae,findDirection:oe,findScope:ce,findBy:le,findCompleted:$}=m,de=M.length===0,ue=S===0||!(l!=null&&l.replaceable),he=p.length===0,pe=h.useCallback(g=>i.changeInputtingFindString(g),[i]),fe=h.useCallback(g=>i.changeReplaceString(g),[i]),{focus:ge}=ie(i,n),_e=h.useCallback(()=>{y===M?i.moveToNextMatch():(i.changeFindString(M),i.find())},[y,M,i]),me=h.useCallback(()=>r.executeCommand(j.id),[r]),Se=h.useCallback(async()=>{await r.executeCommand(w.id),ge()},[r]),ve=h.useCallback(g=>{i.changeFindDirection(g)},[i]),Ce=h.useCallback(g=>{i.changeFindScope(g)},[i]),Me=h.useCallback(g=>{i.changeFindBy(g)},[i]),Re=Ue(s),be=ke(s),ye=Be(s);return h.useEffect(()=>{$&&S===0&&a.show({content:s.t("find-replace.dialog.no-match"),type:f.MessageType.Warning,duration:5e3})},[$,S,a,s]),d.jsxs("div",{children:[d.jsx(f.FormLayout,{label:s.t("find-replace.dialog.find"),children:d.jsx(te,{findCompleted:$,className:"univer-find-input",matchesCount:S,matchesPosition:b,findReplaceService:i,localeService:s,initialFindString:M,onChange:pe})}),d.jsx(f.FormLayout,{label:s.t("find-replace.dialog.replace"),children:d.jsx(f.Input,{placeholder:s.t("find-replace.dialog.replace-placeholder"),value:C,onChange:g=>fe(g)})}),d.jsx(f.FormLayout,{label:s.t("find-replace.dialog.find-direction.title"),children:d.jsx(f.Select,{value:oe,options:be,onChange:ve})}),d.jsx(f.FormDualColumnLayout,{children:d.jsxs(d.Fragment,{children:[d.jsx(f.FormLayout,{label:s.t("find-replace.dialog.find-scope.title"),children:d.jsx(f.Select,{value:ce,options:Re,onChange:Ce})}),d.jsx(f.FormLayout,{label:s.t("find-replace.dialog.find-by.title"),children:d.jsx(f.Select,{value:le,options:ye,onChange:Me})})]})}),d.jsx(f.FormDualColumnLayout,{children:d.jsxs(d.Fragment,{children:[d.jsx(f.FormLayout,{children:d.jsx(f.Checkbox,{checked:re,onChange:g=>{i.changeCaseSensitive(g)},children:s.t("find-replace.dialog.case-sensitive")})}),d.jsx(f.FormLayout,{children:d.jsx(f.Checkbox,{checked:ae,onChange:g=>{i.changeMatchesTheWholeCell(g)},children:s.t("find-replace.dialog.match-the-whole-cell")})})]})}),d.jsxs("div",{className:"univer-mt-6 univer-flex univer-justify-between",children:[d.jsx(f.Button,{variant:"primary",onClick:_e,disabled:de,children:s.t("find-replace.dialog.find")}),d.jsxs("span",{className:"univer-inline-flex univer-gap-2",children:[d.jsx(f.Button,{disabled:ue,onClick:me,children:s.t("find-replace.dialog.replace")}),d.jsx(f.Button,{disabled:he,onClick:Se,children:s.t("find-replace.dialog.replace-all")})]})]})]})});function we(){const t=c.useDependency(v),e=c.useDependency(c.ILayoutService),n=c.useDependency(o.IContextService),i=c.useObservable(t.state$,void 0,!0),s=h.useRef(null);h.useEffect(()=>{let p;return s.current&&(p=e.registerContainerElement(s.current)),()=>p==null?void 0:p.dispose()},[e]);const r=h.useRef(null),a=h.useCallback(p=>n.setContextValue(q,p),[n]),l=h.useCallback(p=>n.setContextValue(H,p),[n]);return h.useEffect(()=>{var m;const p=_.fromEvent(document,"focusin").subscribe(S=>{var b;S.target&&((b=s.current)!=null&&b.contains(S.target))?a(!0):a(!1),!r.current||!r.current.selectHasFocus()?l(!1):l(!0)});return(m=r.current)==null||m.focus(),a(!0),l(!0),()=>{p.unsubscribe(),a(!1)}},[a,l]),d.jsx("div",{ref:s,"data-u-comp":"find-replace-dialog",children:i.replaceRevealed?d.jsx(je,{ref:r}):d.jsx(Ae,{ref:r})})}function Ue(t){const e=t.getCurrentLocale();return h.useMemo(()=>[{label:t.t("find-replace.dialog.find-scope.current-sheet"),value:E.SUBUNIT},{label:t.t("find-replace.dialog.find-scope.workbook"),value:E.UNIT}],[e])}function ke(t){const e=t.getCurrentLocale();return h.useMemo(()=>[{label:t.t("find-replace.dialog.find-direction.row"),value:T.ROW},{label:t.t("find-replace.dialog.find-direction.column"),value:T.COLUMN}],[e])}function Be(t){const e=t.getCurrentLocale();return h.useMemo(()=>[{label:t.t("find-replace.dialog.find-by.value"),value:P.VALUE},{label:t.t("find-replace.dialog.find-by.formula"),value:P.FORMULA}],[e])}function I(t){return t.getContextValue(q)}function We(t){return t.getContextValue(Z)}function ne(t){return t.getContextValue(H)}const D="7_find-replace-shortcuts";function B(t){return t.getContextValue(o.FOCUSING_SHEET)}function W(t){return!t.getContextValue(o.EDITOR_ACTIVATED)}const Ge={id:F.id,description:"find-replace.shortcut.open-find-dialog",binding:c.KeyCode.F|c.MetaKeys.CTRL_COMMAND,group:D,preconditions(t){return!I(t)&&B(t)&&W(t)}},Ve={id:F.id,description:"find-replace.shortcut.open-find-dialog",binding:c.KeyCode.F|c.MetaKeys.CTRL_COMMAND,mac:c.KeyCode.F|c.MetaKeys.MAC_CTRL,preconditions(t){return!I(t)&&B(t)&&W(t)}},Ke={id:N.id,description:"find-replace.shortcut.open-replace-dialog",binding:c.KeyCode.H|c.MetaKeys.CTRL_COMMAND,mac:c.KeyCode.H|c.MetaKeys.MAC_CTRL,group:D,preconditions(t){return B(t)&&W(t)&&(!I(t)||!We(t))}},He={id:U.id,description:"find-replace.shortcut.go-to-next-match",binding:c.KeyCode.ENTER,group:D,priority:1e3,preconditions(t){return ne(t)&&I(t)}},qe={id:k.id,description:"find-replace.shortcut.go-to-previous-match",binding:c.KeyCode.ENTER|c.MetaKeys.SHIFT,group:D,priority:1e3,preconditions(t){return ne(t)&&I(t)}},Ze={id:J.id,description:"find-replace.shortcut.focus-selection",binding:c.KeyCode.ESC,group:D,priority:1e3,preconditions(t){return I(t)}};function ze(t){const e=t.get(o.IContextService);return{id:F.id,icon:"SearchIcon",tooltip:"find-replace.toolbar",type:c.MenuItemType.BUTTON,hidden$:c.getMenuHiddenObservable(t,o.UniverInstanceType.UNIVER_SHEET),disabled$:_.combineLatest([e.subscribeContextValue$(o.EDITOR_ACTIVATED),e.subscribeContextValue$(o.FOCUSING_SHEET)]).pipe(_.map(([n,i])=>n||!i))}}const Ye={[c.RibbonDataGroup.ORGANIZATION]:{[F.id]:{order:2,menuItemFactory:ze}}};var Je=Object.getOwnPropertyDescriptor,Qe=(t,e,n,i)=>{for(var s=i>1?void 0:i?Je(e,n):e,r=t.length-1,a;r>=0;r--)(a=t[r])&&(s=a(s)||s);return s},R=(t,e)=>(n,i)=>e(n,i,t);const G="DESKTOP_FIND_REPLACE_DIALOG",se=350,Xe=20,et=64;exports.FindReplaceController=class extends o.RxDisposable{constructor(n,i,s,r,a,l,p,m,S){super();u(this,"_closingListenerDisposable");this._univerInstanceService=n,this._menuManagerService=i,this._shortcutService=s,this._commandService=r,this._findReplaceService=a,this._dialogService=l,this._layoutService=p,this._localeService=m,this._componentManager=S,this._initCommands(),this._initUI(),this._initShortcuts()}dispose(){var n;super.dispose(),(n=this._closingListenerDisposable)==null||n.dispose(),this._closingListenerDisposable=null}_initCommands(){[F,N,U,k,w,j,J].forEach(n=>{this.disposeWithMe(this._commandService.registerCommand(n))})}_initShortcuts(){[Ke,Ge,Ve,qe,He,Ze].forEach(n=>this.disposeWithMe(this._shortcutService.registerShortcut(n)))}_initUI(){[["FindReplaceDialog",we],["SearchIcon",ee]].forEach(([n,i])=>{this.disposeWithMe(this._componentManager.register(n,i))}),this._menuManagerService.mergeMenu(Ye),this._findReplaceService.stateUpdates$.pipe(_.takeUntil(this.dispose$)).subscribe(n=>{n.revealed===!0&&this._openPanel()})}_openPanel(){this._dialogService.open({id:G,draggable:!0,width:se,title:{title:this._localeService.t("find-replace.dialog.title")},children:{label:"FindReplaceDialog"},destroyOnClose:!0,mask:!1,maskClosable:!1,defaultPosition:tt(),preservePositionOnDestroy:!0,onClose:()=>this.closePanel()}),this._closingListenerDisposable=o.toDisposable(this._univerInstanceService.focused$.pipe(_.takeUntil(this.dispose$)).subscribe(n=>{(!n||!this._univerInstanceService.getUniverSheetInstance(n))&&this.closePanel()}))}closePanel(){this._closingListenerDisposable&&(this._closingListenerDisposable.dispose(),this._closingListenerDisposable=null,this._dialogService.close(G),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus()))}};exports.FindReplaceController=Qe([R(0,o.IUniverInstanceService),R(1,c.IMenuManagerService),R(2,c.IShortcutService),R(3,o.ICommandService),R(4,v),R(5,c.IDialogService),R(6,c.ILayoutService),R(7,o.Inject(o.LocaleService)),R(8,o.Inject(c.ComponentManager))],exports.FindReplaceController);function tt(){const{innerWidth:t}=window;return{x:t-se-Xe,y:et}}const it="find-replace.config",V={};var nt=Object.getOwnPropertyDescriptor,st=(t,e,n,i)=>{for(var s=i>1?void 0:i?nt(e,n):e,r=t.length-1,a;r>=0;r--)(a=t[r])&&(s=a(s)||s);return s},K=(t,e)=>(n,i)=>e(n,i,t);const rt="UNIVER_FIND_REPLACE_PLUGIN";var L;exports.UniverFindReplacePlugin=(L=class extends o.Plugin{constructor(e=V,n,i){super(),this._config=e,this._injector=n,this._configService=i;const{...s}=o.merge({},V,this._config);this._configService.setConfig(it,s)}onStarting(){[[exports.FindReplaceController],[v,{useClass:A}]].forEach(e=>this._injector.add(e))}onRendered(){this._injector.get(exports.FindReplaceController)}},u(L,"pluginName",rt),L);exports.UniverFindReplacePlugin=st([K(1,o.Inject(o.Injector)),K(2,o.IConfigService)],exports.UniverFindReplacePlugin);exports.FindBy=P;exports.FindDirection=T;exports.FindModel=Te;exports.FindReplaceState=Y;exports.FindScope=E;exports.GoToNextMatchOperation=U;exports.GoToPreviousMatchOperation=k;exports.IFindReplaceService=v;exports.OpenFindDialogOperation=F;exports.OpenReplaceDialogOperation=N;exports.ReplaceAllMatchesCommand=w;exports.ReplaceCurrentMatchCommand=j;exports.createInitFindReplaceState=O;
|
|
1
|
+
"use strict";var Fe=Object.defineProperty;var Ie=(t,e,n)=>e in t?Fe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var u=(t,e,n)=>Ie(t,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),f=require("@univerjs/design"),c=require("@univerjs/ui"),De=require("@univerjs/engine-render"),_=require("rxjs"),h=require("react"),d=require("react/jsx-runtime"),H="FIND_REPLACE_INPUT_FOCUS",q="FIND_REPLACE_DIALOG_FOCUS",Z="FIND_REPLACE_REPLACE_REVEALED";var xe=Object.getOwnPropertyDescriptor,z=(t,e,n,i)=>{for(var s=i>1?void 0:i?xe(e,n):e,r=t.length-1,a;r>=0;r--)(a=t[r])&&(s=a(s)||s);return s},x=(t,e)=>(n,i)=>e(n,i,t);class Te extends o.Disposable{}const v=o.createIdentifier("find-replace.service");function Pe(t){return typeof t.findString<"u"||typeof t.inputtingFindString<"u"||typeof t.findDirection<"u"||typeof t.matchesTheWholeCell<"u"||typeof t.caseSensitive<"u"||typeof t.findScope<"u"||typeof t.findBy<"u"}exports.FindReplaceModel=class extends o.Disposable{constructor(n,i,s,r){super();u(this,"currentMatch$",new _.BehaviorSubject(null));u(this,"replaceables$",new _.BehaviorSubject([]));u(this,"_findModels",[]);u(this,"_matchingModel",null);u(this,"_matches",[]);u(this,"_currentSearchingDisposables",null);this._state=n,this._providers=i,this._univerInstanceService=s,this._commandService=r,this.disposeWithMe(this._state.stateUpdates$.pipe(_.throttleTime(200,void 0,{leading:!0,trailing:!0})).subscribe(async a=>{const l=this._state.state;Pe(a)&&(l.findString!==""&&!l.replaceRevealed?(await this._startSearching(),this._state.changeState({findCompleted:!0})):a.replaceRevealed!==!0&&this._stopSearching())}))}get searched(){return this._findModels.length>0}dispose(){super.dispose(),this._stopSearching(),this.currentMatch$.complete(),this.replaceables$.complete(),this._state.changeState({...O(),revealed:!1})}async start(){if(!this._state.findString)return{results:[]};const n=await this._startSearching();return this._state.changeState({findCompleted:!0}),n}focusSelection(){var n;(n=this._matchingModel)==null||n.focusSelection()}async _startSearching(){if(!this._state.findString)return{results:[]};const n=Array.from(this._providers),i=this._findModels=(await Promise.all(n.map(r=>r.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(i);const s=this._matches=i.map(r=>r.getMatches()).flat();return this.replaceables$.next(s.filter(r=>r.replaceable)),s.length?(this._moveToInitialMatch(i),this._state.changeState({matchesCount:s.length}),{results:s}):(this._state.changeState({matchesCount:0,matchesPosition:0}),{results:[]})}_stopSearching(){var n;this._providers.forEach(i=>i.terminate()),this._findModels=[],this._matches=[],this._matchingModel=null,(n=this._currentSearchingDisposables)==null||n.dispose(),this._currentSearchingDisposables=null,this.currentMatch$.next(null),this.replaceables$.next([]),this._state.changeState({findCompleted:!1,matchesCount:0,matchesPosition:0})}_subscribeToModelsChanges(n){const i=this._currentSearchingDisposables=new o.DisposableCollection,s=_.combineLatest(n.map(r=>r.matchesUpdate$)).pipe(_.debounceTime(220)).subscribe(([...r])=>{const a=this._matches=r.flat();a.length?(this._moveToInitialMatch(this._findModels,!0),this._state.changeState({matchesCount:a.length}),this.replaceables$.next(a.filter(l=>l.replaceable))):(this._state.changeState({matchesCount:0,matchesPosition:0}),this.replaceables$.next([]))});n.forEach(r=>i.add(o.toDisposable(r.activelyChangingMatch$.subscribe(a=>{const l=this._matches.findIndex(p=>p===a);this._state.changeState({matchesPosition:l+1})})))),i.add(o.toDisposable(s))}async replace(){return this._matchingModel?this._matchingModel.replace(this._state.replaceString):!1}async replaceAll(){const n=await Promise.all(this._findModels.map(i=>i.replaceAll(this._state.replaceString))).then(i=>i.reduce((s,r)=>(s.success+=r.success,s.failure+=r.failure,s),{success:0,failure:0}));return n.failure===0&&this._stopSearching(),n}getCurrentMatch(){return this._state.matchesPosition>0?this._matches[this._state.matchesPosition-1]:null}_markMatch(n){const i=this._matches.findIndex(s=>s===n);this.currentMatch$.next(n),this._state.changeState({matchesPosition:i+1})}moveToNextMatch(){if(!this._matchingModel)return;const n=this._findModels.length===1,i=this._matchingModel.moveToNextMatch({loop:n});if(i)return this._markMatch(i),i;{const s=this._findModels.findIndex(r=>r===this._matchingModel);return this._moveToNextUnitMatch(s)}}_moveToNextUnitMatch(n){const i=this._findModels.length;for(let s=(n+1)%i;s!==n;){const r=this._findModels[s],a=r.moveToNextMatch({ignoreSelection:!0});if(a)return this._matchingModel=r,this._markMatch(a),a;s=(s+1)%i}if(this._matchingModel){const s=this._matchingModel.moveToNextMatch({ignoreSelection:!0});return s&&this._markMatch(s),s}}moveToPreviousMatch(){if(!this._matchingModel)return;const n=this._findModels.length===1,i=this._matchingModel.moveToPreviousMatch({loop:n});if(i){const s=this._matches.findIndex(r=>r===i);return this.currentMatch$.next(i),this._state.changeState({matchesPosition:s+1}),i}else{const s=this._findModels.length,r=this._findModels.findIndex(l=>l===this._matchingModel);for(let l=(r-1+s)%s;l!==r;){const p=this._findModels[l],m=p.moveToPreviousMatch({ignoreSelection:!0});if(m)return this._matchingModel=p,this._markMatch(m),m;l=(l-1)%s}const a=this._matchingModel.moveToPreviousMatch({ignoreSelection:!0});return a&&this._markMatch(a),a}}_moveToInitialMatch(n,i=!1){var a;const s=(a=this._univerInstanceService.getFocusedUnit())==null?void 0:a.getUnitId();if(!s)return-1;const r=n.findIndex(l=>l.unitId===s);if(r!==-1){this._matchingModel=n[r];const l=this._matchingModel.moveToNextMatch({stayIfOnMatch:!0,noFocus:i});if(l)return this._markMatch(l),r}return this._moveToNextUnitMatch(r),0}};exports.FindReplaceModel=z([x(2,o.IUniverInstanceService),x(3,o.ICommandService)],exports.FindReplaceModel);var T=(t=>(t.ROW="row",t.COLUMN="column",t))(T||{}),P=(t=>(t.VALUE="value",t.FORMULA="formula",t))(P||{}),E=(t=>(t.SUBUNIT="subunit",t.UNIT="unit",t))(E||{});function O(){return{caseSensitive:!1,findBy:"value",findCompleted:!1,findDirection:"row",findScope:"subunit",findString:"",inputtingFindString:"",matchesCount:0,matchesPosition:0,matchesTheWholeCell:!1,replaceRevealed:!1,replaceString:"",revealed:!0}}class Y{constructor(){u(this,"_stateUpdates$",new _.Subject);u(this,"stateUpdates$",this._stateUpdates$.asObservable());u(this,"_state$",new _.BehaviorSubject(O()));u(this,"state$",this._state$.asObservable());u(this,"_findString","");u(this,"_inputtingFindString","");u(this,"_replaceString","");u(this,"_revealed",!1);u(this,"_replaceRevealed",!1);u(this,"_matchesPosition",0);u(this,"_matchesCount",0);u(this,"_caseSensitive",!0);u(this,"_matchesTheWholeCell",!1);u(this,"_findDirection","row");u(this,"_findScope","subunit");u(this,"_findBy","value");u(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 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.replaceString<"u"&&e.replaceString!==this._replaceString&&(this._replaceString=e.replaceString,i.replaceString=e.replaceString,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),typeof e.findBy<"u"&&e.findBy!==this._findBy&&(this._findBy=e.findBy,i.findBy=e.findBy,n=!0),typeof e.findScope<"u"&&e.findScope!==this._findScope&&(this._findScope=e.findScope,i.findScope=e.findScope,n=!0),typeof e.findDirection<"u"&&e.findDirection!==this._findDirection&&(this._findDirection=e.findDirection,i.findDirection=e.findDirection,n=!0),typeof e.caseSensitive<"u"&&e.caseSensitive!==this._caseSensitive&&(this._caseSensitive=e.caseSensitive,i.caseSensitive=e.caseSensitive,n=!0),typeof e.matchesTheWholeCell<"u"&&e.matchesTheWholeCell!==this._matchesTheWholeCell&&(this._matchesTheWholeCell=e.matchesTheWholeCell,i.matchesTheWholeCell=e.matchesTheWholeCell,n=!0),typeof e.inputtingFindString<"u"&&e.inputtingFindString!==this._inputtingFindString&&(this._inputtingFindString=e.inputtingFindString,i.inputtingFindString=e.inputtingFindString,n=!0),typeof e.findCompleted<"u"&&e.findCompleted!==this._findCompleted&&(this._findCompleted=e.findCompleted,i.findCompleted=e.findCompleted,n=!0),n&&(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(i))}}let A=class extends o.Disposable{constructor(e,n){super();u(this,"_providers",new Set);u(this,"_state",new Y);u(this,"_model");u(this,"_currentMatch$",new _.BehaviorSubject(null));u(this,"currentMatch$",this._currentMatch$.asObservable());u(this,"_replaceables$",new _.BehaviorSubject([]));u(this,"replaceables$",this._replaceables$.asObservable());u(this,"_focusSignal$",new _.Subject);u(this,"focusSignal$",this._focusSignal$.asObservable());this._injector=e,this._contextService=n}get stateUpdates$(){return this._state.stateUpdates$}get state$(){return this._state.state$}get revealed(){return this._state.revealed}get replaceRevealed(){return this._state.replaceRevealed}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==="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 new 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(exports.FindReplaceModel,this._state,this._providers),this._model.currentMatch$.subscribe(i=>this._currentMatch$.next(i)),this._model.replaceables$.subscribe(i=>this._replaceables$.next(i));const n=O();return e&&(n.replaceRevealed=!0),this._state.changeState(n),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),o.toDisposable(()=>this._providers.delete(e))}_toggleRevealReplace(e){this._contextService.setContextValue(Z,e)}_toggleDisplayRawFormula(e){this._contextService.setContextValue(De.RENDER_RAW_FORMULA_KEY,e)}};A=z([x(0,o.Inject(o.Injector)),x(1,o.IContextService)],A);const j={id:"ui.command.replace-current-match",type:o.CommandType.COMMAND,handler:t=>t.get(v).replace()},Ee="CONFIRM_REPLACE_ALL",w={id:"ui.command.replace-all-matches",type:o.CommandType.COMMAND,handler:async t=>{const e=t.get(o.IConfirmService),n=t.get(o.LocaleService),i=t.get(c.IMessageService);if(!await e.confirm({id:Ee,title:{title:n.t("find-replace.replace.confirm.title")},cancelText:n.t("button.cancel"),confirmText:n.t("button.confirm")}))return!1;const r=await t.get(v).replaceAll(),{success:a,failure:l}=r;return l>0?(a===0?i.show({type:f.MessageType.Error,content:n.t("find-replace.replace.all-failure")}):i.show({type:f.MessageType.Warning,content:n.t("find-replace.replace.partial-success",`${a}`,`${l}`)}),!1):(i.show({type:f.MessageType.Success,content:n.t("find-replace.replace.all-success",`${a}`)}),!0)}},F={id:"ui.operation.open-find-dialog",type:o.CommandType.OPERATION,handler:t=>{const e=t.get(v);return e.revealed?e.focusFindInput():e.start(),!0}},N={id:"ui.operation.open-replace-dialog",type:o.CommandType.OPERATION,handler:t=>{const e=t.get(v);return e.revealed?e.replaceRevealed?e.focusFindInput():e.revealReplace():e.start(!0),!0}},U={type:o.CommandType.OPERATION,id:"ui.operation.go-to-next-match",handler:t=>(t.get(v).moveToNextMatch(),!0)},k={type:o.CommandType.OPERATION,id:"ui.operation.go-to-previous-match",handler:t=>(t.get(v).moveToPreviousMatch(),!0)},J={type:o.CommandType.OPERATION,id:"ui.operation.focus-selection",handler:t=>(t.get(v).focusSelection(),!0)};function Q({ref:t,...e}){const{icon:n,id:i,className:s,extend:r,...a}=e,l=`univerjs-icon univerjs-icon-${i} ${s||""}`.trim(),p=h.useRef(`_${$e()}`);return X(n,`${i}`,{defIds:n.defIds,idSuffix:p.current},{ref:t,className:l,...a},r)}function X(t,e,n,i,s){return h.createElement(t.tag,{key:e,...Oe(t,n,s),...i},(Ne(t,n).children||[]).map((r,a)=>X(r,`${e}-${t.tag}-${a}`,n,void 0,s)))}function Oe(t,e,n){const i={...t.attrs};n!=null&&n.colorChannel1&&i.fill==="colorChannel1"&&(i.fill=n.colorChannel1),t.tag==="mask"&&i.id&&(i.id=i.id+e.idSuffix),Object.entries(i).forEach(([r,a])=>{r==="mask"&&typeof a=="string"&&(i[r]=a.replace(/url\(#(.*)\)/,`url(#$1${e.idSuffix})`))});const{defIds:s}=e;return!s||s.length===0||(t.tag==="use"&&i["xlink:href"]&&(i["xlink:href"]=i["xlink:href"]+e.idSuffix),Object.entries(i).forEach(([r,a])=>{typeof a=="string"&&(i[r]=a.replace(/url\(#(.*)\)/,`url(#$1${e.idSuffix})`))})),i}function Ne(t,e){var i;const{defIds:n}=e;return!n||n.length===0?t:t.tag==="defs"&&((i=t.children)!=null&&i.length)?{...t,children:t.children.map(s=>typeof s.attrs.id=="string"&&n&&n.includes(s.attrs.id)?{...s,attrs:{...s.attrs,id:s.attrs.id+e.idSuffix}}:s)}:t}function $e(){return Math.random().toString(36).substring(2,8)}Q.displayName="UniverIcon";const Le={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"}}]},ee=h.forwardRef(function(e,n){return h.createElement(Q,Object.assign({},e,{id:"search-icon",ref:n,icon:Le}))});ee.displayName="SearchIcon";function te(t){const{findCompleted:e,localeService:n,matchesCount:i,matchesPosition:s,initialFindString:r,findReplaceService:a,onChange:l,...p}=t,[m,S]=h.useState(r),y=e&&i===0?n.t("find-replace.dialog.no-result"):i===0?" ":void 0;function M(C){s===i&&C===1?a.moveToNextMatch():s===1&&C===i||C<s?a.moveToPreviousMatch():a.moveToNextMatch()}return d.jsx("div",{className:"univer-relative univer-flex univer-items-center univer-gap-2",onDrag:C=>C.stopPropagation(),children:d.jsx(f.Input,{"data-u-comp":"search-input",autoFocus:!0,placeholder:n.t("find-replace.dialog.find-placeholder"),value:m,onChange:C=>{S(C),l==null||l(C)},slot:d.jsx(f.Pager,{loop:!0,text:y,value:s,total:i,onChange:M}),...p})})}function ie(t,e){const n=h.useCallback(()=>{var s;(s=document.querySelector(".univer-find-input input"))==null||s.focus()},[]),i=h.useCallback(()=>{const s=document.querySelectorAll("[data-u-comp=find-replace-dialog] [data-u-comp=search-input]");return Array.from(s).some(r=>r===document.activeElement)},[]);return h.useImperativeHandle(e,()=>({focus:n,selectHasFocus:i})),h.useEffect(()=>{const s=t.focusSignal$.subscribe(()=>n());return()=>s.unsubscribe()},[t,n]),{focus:n,selectHasFocus:i}}const Ae=h.forwardRef(function(e,n){const i=c.useDependency(o.LocaleService),s=c.useDependency(v),r=c.useDependency(o.ICommandService),a=c.useObservable(s.state$,void 0,!0),{findCompleted:l,findString:p,matchesCount:m,matchesPosition:S}=a,b=h.useCallback(()=>{r.executeCommand(N.id)},[r]),y=c.useDebounceFn(M=>s.changeFindString(M),500);return ie(s,n),d.jsxs(d.Fragment,{children:[d.jsx(te,{findCompleted:l,matchesCount:m,matchesPosition:S,findReplaceService:s,localeService:i,initialFindString:p,onChange:y}),d.jsx("div",{className:"univer-mt-4 univer-text-center",children:d.jsx("a",{className:"hover:univer-text-primary-500/80 univer-cursor-pointer univer-text-sm univer-text-primary-500 univer-transition-colors",onClick:b,children:i.t("find-replace.dialog.advanced-finding")})})]})}),je=h.forwardRef(function(e,n){const i=c.useDependency(v),s=c.useDependency(o.LocaleService),r=c.useDependency(o.ICommandService),a=c.useDependency(c.IMessageService),l=c.useObservable(i.currentMatch$,void 0,!0),p=c.useObservable(i.replaceables$,void 0,!0),m=c.useObservable(i.state$,void 0,!0),{matchesCount:S,matchesPosition:b,findString:y,inputtingFindString:M,replaceString:C,caseSensitive:re,matchesTheWholeCell:ae,findDirection:oe,findScope:ce,findBy:le,findCompleted:$}=m,de=M.length===0,ue=S===0||!(l!=null&&l.replaceable),he=p.length===0,pe=h.useCallback(g=>i.changeInputtingFindString(g),[i]),fe=h.useCallback(g=>i.changeReplaceString(g),[i]),{focus:ge}=ie(i,n),_e=h.useCallback(()=>{y===M?i.moveToNextMatch():(i.changeFindString(M),i.find())},[y,M,i]),me=h.useCallback(()=>r.executeCommand(j.id),[r]),Se=h.useCallback(async()=>{await r.executeCommand(w.id),ge()},[r]),ve=h.useCallback(g=>{i.changeFindDirection(g)},[i]),Ce=h.useCallback(g=>{i.changeFindScope(g)},[i]),Me=h.useCallback(g=>{i.changeFindBy(g)},[i]),Re=Ue(s),be=ke(s),ye=Be(s);return h.useEffect(()=>{$&&S===0&&a.show({content:s.t("find-replace.dialog.no-match"),type:f.MessageType.Warning,duration:5e3})},[$,S,a,s]),d.jsxs("div",{children:[d.jsx(f.FormLayout,{label:s.t("find-replace.dialog.find"),children:d.jsx(te,{findCompleted:$,className:"univer-find-input",matchesCount:S,matchesPosition:b,findReplaceService:i,localeService:s,initialFindString:M,onChange:pe})}),d.jsx(f.FormLayout,{label:s.t("find-replace.dialog.replace"),children:d.jsx(f.Input,{placeholder:s.t("find-replace.dialog.replace-placeholder"),value:C,onChange:g=>fe(g)})}),d.jsx(f.FormLayout,{label:s.t("find-replace.dialog.find-direction.title"),children:d.jsx(f.Select,{value:oe,options:be,onChange:ve})}),d.jsx(f.FormDualColumnLayout,{children:d.jsxs(d.Fragment,{children:[d.jsx(f.FormLayout,{label:s.t("find-replace.dialog.find-scope.title"),children:d.jsx(f.Select,{value:ce,options:Re,onChange:Ce})}),d.jsx(f.FormLayout,{label:s.t("find-replace.dialog.find-by.title"),children:d.jsx(f.Select,{value:le,options:ye,onChange:Me})})]})}),d.jsx(f.FormDualColumnLayout,{children:d.jsxs(d.Fragment,{children:[d.jsx(f.FormLayout,{children:d.jsx(f.Checkbox,{checked:re,onChange:g=>{i.changeCaseSensitive(g)},children:s.t("find-replace.dialog.case-sensitive")})}),d.jsx(f.FormLayout,{children:d.jsx(f.Checkbox,{checked:ae,onChange:g=>{i.changeMatchesTheWholeCell(g)},children:s.t("find-replace.dialog.match-the-whole-cell")})})]})}),d.jsxs("div",{className:"univer-mt-6 univer-flex univer-justify-between",children:[d.jsx(f.Button,{variant:"primary",onClick:_e,disabled:de,children:s.t("find-replace.dialog.find")}),d.jsxs("span",{className:"univer-inline-flex univer-gap-2",children:[d.jsx(f.Button,{disabled:ue,onClick:me,children:s.t("find-replace.dialog.replace")}),d.jsx(f.Button,{disabled:he,onClick:Se,children:s.t("find-replace.dialog.replace-all")})]})]})]})});function we(){const t=c.useDependency(v),e=c.useDependency(c.ILayoutService),n=c.useDependency(o.IContextService),i=c.useObservable(t.state$,void 0,!0),s=h.useRef(null);h.useEffect(()=>{let p;return s.current&&(p=e.registerContainerElement(s.current)),()=>p==null?void 0:p.dispose()},[e]);const r=h.useRef(null),a=h.useCallback(p=>n.setContextValue(q,p),[n]),l=h.useCallback(p=>n.setContextValue(H,p),[n]);return h.useEffect(()=>{var m;const p=_.fromEvent(document,"focusin").subscribe(S=>{var b;S.target&&((b=s.current)!=null&&b.contains(S.target))?a(!0):a(!1),!r.current||!r.current.selectHasFocus()?l(!1):l(!0)});return(m=r.current)==null||m.focus(),a(!0),l(!0),()=>{p.unsubscribe(),a(!1)}},[a,l]),d.jsx("div",{ref:s,"data-u-comp":"find-replace-dialog",children:i.replaceRevealed?d.jsx(je,{ref:r}):d.jsx(Ae,{ref:r})})}function Ue(t){const e=t.getCurrentLocale();return h.useMemo(()=>[{label:t.t("find-replace.dialog.find-scope.current-sheet"),value:E.SUBUNIT},{label:t.t("find-replace.dialog.find-scope.workbook"),value:E.UNIT}],[e])}function ke(t){const e=t.getCurrentLocale();return h.useMemo(()=>[{label:t.t("find-replace.dialog.find-direction.row"),value:T.ROW},{label:t.t("find-replace.dialog.find-direction.column"),value:T.COLUMN}],[e])}function Be(t){const e=t.getCurrentLocale();return h.useMemo(()=>[{label:t.t("find-replace.dialog.find-by.value"),value:P.VALUE},{label:t.t("find-replace.dialog.find-by.formula"),value:P.FORMULA}],[e])}function I(t){return t.getContextValue(q)}function We(t){return t.getContextValue(Z)}function ne(t){return t.getContextValue(H)}const D="7_find-replace-shortcuts";function B(t){return t.getContextValue(o.FOCUSING_SHEET)}function W(t){return!t.getContextValue(o.EDITOR_ACTIVATED)}const Ge={id:F.id,description:"find-replace.shortcut.open-find-dialog",binding:c.KeyCode.F|c.MetaKeys.CTRL_COMMAND,group:D,preconditions(t){return!I(t)&&B(t)&&W(t)}},Ve={id:F.id,description:"find-replace.shortcut.open-find-dialog",binding:c.KeyCode.F|c.MetaKeys.CTRL_COMMAND,mac:c.KeyCode.F|c.MetaKeys.MAC_CTRL,preconditions(t){return!I(t)&&B(t)&&W(t)}},Ke={id:N.id,description:"find-replace.shortcut.open-replace-dialog",binding:c.KeyCode.H|c.MetaKeys.CTRL_COMMAND,mac:c.KeyCode.H|c.MetaKeys.MAC_CTRL,group:D,preconditions(t){return B(t)&&W(t)&&(!I(t)||!We(t))}},He={id:U.id,description:"find-replace.shortcut.go-to-next-match",binding:c.KeyCode.ENTER,group:D,priority:1e3,preconditions(t){return ne(t)&&I(t)}},qe={id:k.id,description:"find-replace.shortcut.go-to-previous-match",binding:c.KeyCode.ENTER|c.MetaKeys.SHIFT,group:D,priority:1e3,preconditions(t){return ne(t)&&I(t)}},Ze={id:J.id,description:"find-replace.shortcut.focus-selection",binding:c.KeyCode.ESC,group:D,priority:1e3,preconditions(t){return I(t)}};function ze(t){const e=t.get(o.IContextService);return{id:F.id,icon:"SearchIcon",tooltip:"find-replace.toolbar",type:c.MenuItemType.BUTTON,hidden$:c.getMenuHiddenObservable(t,o.UniverInstanceType.UNIVER_SHEET),disabled$:_.combineLatest([e.subscribeContextValue$(o.EDITOR_ACTIVATED),e.subscribeContextValue$(o.FOCUSING_SHEET)]).pipe(_.map(([n,i])=>n||!i))}}const Ye={[c.RibbonDataGroup.ORGANIZATION]:{[F.id]:{order:2,menuItemFactory:ze}}};var Je=Object.getOwnPropertyDescriptor,Qe=(t,e,n,i)=>{for(var s=i>1?void 0:i?Je(e,n):e,r=t.length-1,a;r>=0;r--)(a=t[r])&&(s=a(s)||s);return s},R=(t,e)=>(n,i)=>e(n,i,t);const G="DESKTOP_FIND_REPLACE_DIALOG",se=350,Xe=20,et=64;exports.FindReplaceController=class extends o.RxDisposable{constructor(n,i,s,r,a,l,p,m,S){super();u(this,"_closingListenerDisposable");this._univerInstanceService=n,this._menuManagerService=i,this._shortcutService=s,this._commandService=r,this._findReplaceService=a,this._dialogService=l,this._layoutService=p,this._localeService=m,this._componentManager=S,this._initCommands(),this._initUI(),this._initShortcuts()}dispose(){var n;super.dispose(),(n=this._closingListenerDisposable)==null||n.dispose(),this._closingListenerDisposable=null}_initCommands(){[F,N,U,k,w,j,J].forEach(n=>{this.disposeWithMe(this._commandService.registerCommand(n))})}_initShortcuts(){[Ke,Ge,Ve,qe,He,Ze].forEach(n=>this.disposeWithMe(this._shortcutService.registerShortcut(n)))}_initUI(){[["FindReplaceDialog",we],["SearchIcon",ee]].forEach(([n,i])=>{this.disposeWithMe(this._componentManager.register(n,i))}),this._menuManagerService.mergeMenu(Ye),this._findReplaceService.stateUpdates$.pipe(_.takeUntil(this.dispose$)).subscribe(n=>{n.revealed===!0&&this._openPanel()})}_openPanel(){this._dialogService.open({id:G,draggable:!0,width:se,title:{title:this._localeService.t("find-replace.dialog.title")},children:{label:"FindReplaceDialog"},destroyOnClose:!0,mask:!1,maskClosable:!1,defaultPosition:tt(),preservePositionOnDestroy:!0,onClose:()=>this.closePanel()}),this._closingListenerDisposable=o.toDisposable(this._univerInstanceService.focused$.pipe(_.takeUntil(this.dispose$)).subscribe(n=>{(!n||!this._univerInstanceService.getUniverSheetInstance(n))&&this.closePanel()}))}closePanel(){this._closingListenerDisposable&&(this._closingListenerDisposable.dispose(),this._closingListenerDisposable=null,this._dialogService.close(G),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus()))}};exports.FindReplaceController=Qe([R(0,o.IUniverInstanceService),R(1,c.IMenuManagerService),R(2,c.IShortcutService),R(3,o.ICommandService),R(4,v),R(5,c.IDialogService),R(6,c.ILayoutService),R(7,o.Inject(o.LocaleService)),R(8,o.Inject(c.ComponentManager))],exports.FindReplaceController);function tt(){const{innerWidth:t}=window;return{x:t-se-Xe,y:et}}const it="find-replace.config",V={};var nt=Object.getOwnPropertyDescriptor,st=(t,e,n,i)=>{for(var s=i>1?void 0:i?nt(e,n):e,r=t.length-1,a;r>=0;r--)(a=t[r])&&(s=a(s)||s);return s},K=(t,e)=>(n,i)=>e(n,i,t);const rt="UNIVER_FIND_REPLACE_PLUGIN";var L;exports.UniverFindReplacePlugin=(L=class extends o.Plugin{constructor(e=V,n,i){super(),this._config=e,this._injector=n,this._configService=i;const{...s}=o.merge({},V,this._config);this._configService.setConfig(it,s)}onStarting(){[[exports.FindReplaceController],[v,{useClass:A}]].forEach(e=>this._injector.add(e))}onRendered(){this._injector.get(exports.FindReplaceController)}},u(L,"pluginName",rt),L);exports.UniverFindReplacePlugin=st([K(1,o.Inject(o.Injector)),K(2,o.IConfigService)],exports.UniverFindReplacePlugin);exports.FindBy=P;exports.FindDirection=T;exports.FindModel=Te;exports.FindReplaceState=Y;exports.FindScope=E;exports.GoToNextMatchOperation=U;exports.GoToPreviousMatchOperation=k;exports.IFindReplaceService=v;exports.OpenFindDialogOperation=F;exports.OpenReplaceDialogOperation=N;exports.ReplaceAllMatchesCommand=w;exports.ReplaceCurrentMatchCommand=j;exports.createInitFindReplaceState=O;
|
package/lib/es/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
var st = Object.defineProperty;
|
|
2
2
|
var rt = (t, e, n) => e in t ? st(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
|
|
3
3
|
var o = (t, e, n) => rt(t, typeof e != "symbol" ? e + "" : e, n);
|
|
4
|
-
import { createIdentifier as at, Inject as $, Injector as ue, IContextService as J, Disposable as Q, DisposableCollection as ot, toDisposable as O, IUniverInstanceService as fe, ICommandService as U, CommandType as b, LocaleService as B, FOCUSING_SHEET as pe, EDITOR_ACTIVATED as _e, UniverInstanceType as
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { createIdentifier as at, Inject as $, Injector as ue, IContextService as J, Disposable as Q, DisposableCollection as ot, toDisposable as O, IUniverInstanceService as fe, ICommandService as U, CommandType as b, IConfirmService as ct, LocaleService as B, FOCUSING_SHEET as pe, EDITOR_ACTIVATED as _e, UniverInstanceType as lt, RxDisposable as dt, IConfigService as ht, Plugin as ut, merge as ft } from "@univerjs/core";
|
|
5
|
+
import { MessageType as N, Input as ge, Pager as pt, FormLayout as R, Select as k, FormDualColumnLayout as re, Checkbox as ae, Button as j } from "@univerjs/design";
|
|
6
|
+
import { IMessageService as me, useDependency as m, useObservable as P, useDebounceFn as _t, ILayoutService as Se, KeyCode as C, MetaKeys as D, getMenuHiddenObservable as gt, MenuItemType as mt, RibbonDataGroup as St, IMenuManagerService as vt, IShortcutService as Ct, IDialogService as Mt, ComponentManager as Rt } from "@univerjs/ui";
|
|
7
7
|
import { RENDER_RAW_FORMULA_KEY as bt } from "@univerjs/engine-render";
|
|
8
8
|
import { throttleTime as It, BehaviorSubject as T, combineLatest as ve, debounceTime as Ft, Subject as Ce, fromEvent as Dt, map as yt, takeUntil as oe } from "rxjs";
|
|
9
9
|
import { useRef as G, createElement as Me, forwardRef as X, useState as Pt, useCallback as u, useEffect as A, useMemo as ee, useImperativeHandle as Tt } from "react";
|
|
@@ -394,7 +394,7 @@ const De = {
|
|
|
394
394
|
id: "ui.command.replace-all-matches",
|
|
395
395
|
type: b.COMMAND,
|
|
396
396
|
handler: async (t) => {
|
|
397
|
-
const e = t.get(
|
|
397
|
+
const e = t.get(ct), n = t.get(B), i = t.get(me);
|
|
398
398
|
if (!await e.confirm({
|
|
399
399
|
id: $t,
|
|
400
400
|
title: { title: n.t("find-replace.replace.confirm.title") },
|
|
@@ -528,7 +528,7 @@ function Oe(t) {
|
|
|
528
528
|
s === i && g === 1 ? a.moveToNextMatch() : s === 1 && g === i || g < s ? a.moveToPreviousMatch() : a.moveToNextMatch();
|
|
529
529
|
}
|
|
530
530
|
return /* @__PURE__ */ c("div", { className: "univer-relative univer-flex univer-items-center univer-gap-2", onDrag: (g) => g.stopPropagation(), children: /* @__PURE__ */ c(
|
|
531
|
-
|
|
531
|
+
ge,
|
|
532
532
|
{
|
|
533
533
|
"data-u-comp": "search-input",
|
|
534
534
|
autoFocus: !0,
|
|
@@ -538,7 +538,7 @@ function Oe(t) {
|
|
|
538
538
|
p(g), l == null || l(g);
|
|
539
539
|
},
|
|
540
540
|
slot: /* @__PURE__ */ c(
|
|
541
|
-
|
|
541
|
+
pt,
|
|
542
542
|
{
|
|
543
543
|
loop: !0,
|
|
544
544
|
text: I,
|
|
@@ -567,7 +567,7 @@ function Ae(t, e) {
|
|
|
567
567
|
const Ut = X(function(e, n) {
|
|
568
568
|
const i = m(B), s = m(f), r = m(U), a = P(s.state$, void 0, !0), { findCompleted: l, findString: d, matchesCount: _, matchesPosition: p } = a, M = u(() => {
|
|
569
569
|
r.executeCommand(ie.id);
|
|
570
|
-
}, [r]), I =
|
|
570
|
+
}, [r]), I = _t((S) => s.changeFindString(S), 500);
|
|
571
571
|
return Ae(s, n), /* @__PURE__ */ F(H, { children: [
|
|
572
572
|
/* @__PURE__ */ c(
|
|
573
573
|
Oe,
|
|
@@ -591,7 +591,7 @@ const Ut = X(function(e, n) {
|
|
|
591
591
|
) })
|
|
592
592
|
] });
|
|
593
593
|
}), Bt = X(function(e, n) {
|
|
594
|
-
const i = m(f), s = m(B), r = m(U), a = m(
|
|
594
|
+
const i = m(f), s = m(B), r = m(U), a = m(me), l = P(i.currentMatch$, void 0, !0), d = P(i.replaceables$, void 0, !0), _ = P(i.state$, void 0, !0), {
|
|
595
595
|
matchesCount: p,
|
|
596
596
|
matchesPosition: M,
|
|
597
597
|
findString: I,
|
|
@@ -641,7 +641,7 @@ const Ut = X(function(e, n) {
|
|
|
641
641
|
}
|
|
642
642
|
) }),
|
|
643
643
|
/* @__PURE__ */ c(R, { label: s.t("find-replace.dialog.replace"), children: /* @__PURE__ */ c(
|
|
644
|
-
|
|
644
|
+
ge,
|
|
645
645
|
{
|
|
646
646
|
placeholder: s.t("find-replace.dialog.replace-placeholder"),
|
|
647
647
|
value: g,
|
|
@@ -685,7 +685,7 @@ const Ut = X(function(e, n) {
|
|
|
685
685
|
] });
|
|
686
686
|
});
|
|
687
687
|
function Wt() {
|
|
688
|
-
const t = m(f), e = m(
|
|
688
|
+
const t = m(f), e = m(Se), n = m(J), i = P(t.state$, void 0, !0), s = G(null);
|
|
689
689
|
A(() => {
|
|
690
690
|
let d;
|
|
691
691
|
return s.current && (d = e.registerContainerElement(s.current)), () => d == null ? void 0 : d.dispose();
|
|
@@ -804,8 +804,8 @@ function Jt(t) {
|
|
|
804
804
|
id: x.id,
|
|
805
805
|
icon: "SearchIcon",
|
|
806
806
|
tooltip: "find-replace.toolbar",
|
|
807
|
-
type:
|
|
808
|
-
hidden$:
|
|
807
|
+
type: mt.BUTTON,
|
|
808
|
+
hidden$: gt(t, lt.UNIVER_SHEET),
|
|
809
809
|
disabled$: ve([
|
|
810
810
|
e.subscribeContextValue$(_e),
|
|
811
811
|
e.subscribeContextValue$(pe)
|
|
@@ -813,7 +813,7 @@ function Jt(t) {
|
|
|
813
813
|
};
|
|
814
814
|
}
|
|
815
815
|
const Qt = {
|
|
816
|
-
[
|
|
816
|
+
[St.ORGANIZATION]: {
|
|
817
817
|
[x.id]: {
|
|
818
818
|
order: 2,
|
|
819
819
|
menuItemFactory: Jt
|
|
@@ -826,7 +826,7 @@ var Xt = Object.getOwnPropertyDescriptor, ei = (t, e, n, i) => {
|
|
|
826
826
|
return s;
|
|
827
827
|
}, v = (t, e) => (n, i) => e(n, i, t);
|
|
828
828
|
const ce = "DESKTOP_FIND_REPLACE_DIALOG", we = 350, ti = 20, ii = 64;
|
|
829
|
-
let w = class extends
|
|
829
|
+
let w = class extends dt {
|
|
830
830
|
constructor(e, n, i, s, r, a, l, d, _) {
|
|
831
831
|
super();
|
|
832
832
|
o(this, "_closingListenerDisposable");
|
|
@@ -894,14 +894,14 @@ let w = class extends lt {
|
|
|
894
894
|
};
|
|
895
895
|
w = ei([
|
|
896
896
|
v(0, fe),
|
|
897
|
-
v(1,
|
|
898
|
-
v(2,
|
|
897
|
+
v(1, vt),
|
|
898
|
+
v(2, Ct),
|
|
899
899
|
v(3, U),
|
|
900
900
|
v(4, f),
|
|
901
|
-
v(5,
|
|
902
|
-
v(6,
|
|
901
|
+
v(5, Mt),
|
|
902
|
+
v(6, Se),
|
|
903
903
|
v(7, $(B)),
|
|
904
|
-
v(8, $(
|
|
904
|
+
v(8, $(Rt))
|
|
905
905
|
], w);
|
|
906
906
|
function ni() {
|
|
907
907
|
const { innerWidth: t } = window;
|
|
@@ -915,10 +915,10 @@ var ri = Object.getOwnPropertyDescriptor, ai = (t, e, n, i) => {
|
|
|
915
915
|
}, de = (t, e) => (n, i) => e(n, i, t);
|
|
916
916
|
const oi = "UNIVER_FIND_REPLACE_PLUGIN";
|
|
917
917
|
var V;
|
|
918
|
-
let he = (V = class extends
|
|
918
|
+
let he = (V = class extends ut {
|
|
919
919
|
constructor(t = le, e, n) {
|
|
920
920
|
super(), this._config = t, this._injector = e, this._configService = n;
|
|
921
|
-
const { ...i } =
|
|
921
|
+
const { ...i } = ft(
|
|
922
922
|
{},
|
|
923
923
|
le,
|
|
924
924
|
this._config
|
|
@@ -937,7 +937,7 @@ let he = (V = class extends ht {
|
|
|
937
937
|
}, o(V, "pluginName", oi), V);
|
|
938
938
|
he = ai([
|
|
939
939
|
de(1, $(ue)),
|
|
940
|
-
de(2,
|
|
940
|
+
de(2, ht)
|
|
941
941
|
], he);
|
|
942
942
|
export {
|
|
943
943
|
Z as FindBy,
|
package/lib/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
var st = Object.defineProperty;
|
|
2
2
|
var rt = (t, e, n) => e in t ? st(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
|
|
3
3
|
var o = (t, e, n) => rt(t, typeof e != "symbol" ? e + "" : e, n);
|
|
4
|
-
import { createIdentifier as at, Inject as $, Injector as ue, IContextService as J, Disposable as Q, DisposableCollection as ot, toDisposable as O, IUniverInstanceService as fe, ICommandService as U, CommandType as b, LocaleService as B, FOCUSING_SHEET as pe, EDITOR_ACTIVATED as _e, UniverInstanceType as
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { createIdentifier as at, Inject as $, Injector as ue, IContextService as J, Disposable as Q, DisposableCollection as ot, toDisposable as O, IUniverInstanceService as fe, ICommandService as U, CommandType as b, IConfirmService as ct, LocaleService as B, FOCUSING_SHEET as pe, EDITOR_ACTIVATED as _e, UniverInstanceType as lt, RxDisposable as dt, IConfigService as ht, Plugin as ut, merge as ft } from "@univerjs/core";
|
|
5
|
+
import { MessageType as N, Input as ge, Pager as pt, FormLayout as R, Select as k, FormDualColumnLayout as re, Checkbox as ae, Button as j } from "@univerjs/design";
|
|
6
|
+
import { IMessageService as me, useDependency as m, useObservable as P, useDebounceFn as _t, ILayoutService as Se, KeyCode as C, MetaKeys as D, getMenuHiddenObservable as gt, MenuItemType as mt, RibbonDataGroup as St, IMenuManagerService as vt, IShortcutService as Ct, IDialogService as Mt, ComponentManager as Rt } from "@univerjs/ui";
|
|
7
7
|
import { RENDER_RAW_FORMULA_KEY as bt } from "@univerjs/engine-render";
|
|
8
8
|
import { throttleTime as It, BehaviorSubject as T, combineLatest as ve, debounceTime as Ft, Subject as Ce, fromEvent as Dt, map as yt, takeUntil as oe } from "rxjs";
|
|
9
9
|
import { useRef as G, createElement as Me, forwardRef as X, useState as Pt, useCallback as u, useEffect as A, useMemo as ee, useImperativeHandle as Tt } from "react";
|
|
@@ -394,7 +394,7 @@ const De = {
|
|
|
394
394
|
id: "ui.command.replace-all-matches",
|
|
395
395
|
type: b.COMMAND,
|
|
396
396
|
handler: async (t) => {
|
|
397
|
-
const e = t.get(
|
|
397
|
+
const e = t.get(ct), n = t.get(B), i = t.get(me);
|
|
398
398
|
if (!await e.confirm({
|
|
399
399
|
id: $t,
|
|
400
400
|
title: { title: n.t("find-replace.replace.confirm.title") },
|
|
@@ -528,7 +528,7 @@ function Oe(t) {
|
|
|
528
528
|
s === i && g === 1 ? a.moveToNextMatch() : s === 1 && g === i || g < s ? a.moveToPreviousMatch() : a.moveToNextMatch();
|
|
529
529
|
}
|
|
530
530
|
return /* @__PURE__ */ c("div", { className: "univer-relative univer-flex univer-items-center univer-gap-2", onDrag: (g) => g.stopPropagation(), children: /* @__PURE__ */ c(
|
|
531
|
-
|
|
531
|
+
ge,
|
|
532
532
|
{
|
|
533
533
|
"data-u-comp": "search-input",
|
|
534
534
|
autoFocus: !0,
|
|
@@ -538,7 +538,7 @@ function Oe(t) {
|
|
|
538
538
|
p(g), l == null || l(g);
|
|
539
539
|
},
|
|
540
540
|
slot: /* @__PURE__ */ c(
|
|
541
|
-
|
|
541
|
+
pt,
|
|
542
542
|
{
|
|
543
543
|
loop: !0,
|
|
544
544
|
text: I,
|
|
@@ -567,7 +567,7 @@ function Ae(t, e) {
|
|
|
567
567
|
const Ut = X(function(e, n) {
|
|
568
568
|
const i = m(B), s = m(f), r = m(U), a = P(s.state$, void 0, !0), { findCompleted: l, findString: d, matchesCount: _, matchesPosition: p } = a, M = u(() => {
|
|
569
569
|
r.executeCommand(ie.id);
|
|
570
|
-
}, [r]), I =
|
|
570
|
+
}, [r]), I = _t((S) => s.changeFindString(S), 500);
|
|
571
571
|
return Ae(s, n), /* @__PURE__ */ F(H, { children: [
|
|
572
572
|
/* @__PURE__ */ c(
|
|
573
573
|
Oe,
|
|
@@ -591,7 +591,7 @@ const Ut = X(function(e, n) {
|
|
|
591
591
|
) })
|
|
592
592
|
] });
|
|
593
593
|
}), Bt = X(function(e, n) {
|
|
594
|
-
const i = m(f), s = m(B), r = m(U), a = m(
|
|
594
|
+
const i = m(f), s = m(B), r = m(U), a = m(me), l = P(i.currentMatch$, void 0, !0), d = P(i.replaceables$, void 0, !0), _ = P(i.state$, void 0, !0), {
|
|
595
595
|
matchesCount: p,
|
|
596
596
|
matchesPosition: M,
|
|
597
597
|
findString: I,
|
|
@@ -641,7 +641,7 @@ const Ut = X(function(e, n) {
|
|
|
641
641
|
}
|
|
642
642
|
) }),
|
|
643
643
|
/* @__PURE__ */ c(R, { label: s.t("find-replace.dialog.replace"), children: /* @__PURE__ */ c(
|
|
644
|
-
|
|
644
|
+
ge,
|
|
645
645
|
{
|
|
646
646
|
placeholder: s.t("find-replace.dialog.replace-placeholder"),
|
|
647
647
|
value: g,
|
|
@@ -685,7 +685,7 @@ const Ut = X(function(e, n) {
|
|
|
685
685
|
] });
|
|
686
686
|
});
|
|
687
687
|
function Wt() {
|
|
688
|
-
const t = m(f), e = m(
|
|
688
|
+
const t = m(f), e = m(Se), n = m(J), i = P(t.state$, void 0, !0), s = G(null);
|
|
689
689
|
A(() => {
|
|
690
690
|
let d;
|
|
691
691
|
return s.current && (d = e.registerContainerElement(s.current)), () => d == null ? void 0 : d.dispose();
|
|
@@ -804,8 +804,8 @@ function Jt(t) {
|
|
|
804
804
|
id: x.id,
|
|
805
805
|
icon: "SearchIcon",
|
|
806
806
|
tooltip: "find-replace.toolbar",
|
|
807
|
-
type:
|
|
808
|
-
hidden$:
|
|
807
|
+
type: mt.BUTTON,
|
|
808
|
+
hidden$: gt(t, lt.UNIVER_SHEET),
|
|
809
809
|
disabled$: ve([
|
|
810
810
|
e.subscribeContextValue$(_e),
|
|
811
811
|
e.subscribeContextValue$(pe)
|
|
@@ -813,7 +813,7 @@ function Jt(t) {
|
|
|
813
813
|
};
|
|
814
814
|
}
|
|
815
815
|
const Qt = {
|
|
816
|
-
[
|
|
816
|
+
[St.ORGANIZATION]: {
|
|
817
817
|
[x.id]: {
|
|
818
818
|
order: 2,
|
|
819
819
|
menuItemFactory: Jt
|
|
@@ -826,7 +826,7 @@ var Xt = Object.getOwnPropertyDescriptor, ei = (t, e, n, i) => {
|
|
|
826
826
|
return s;
|
|
827
827
|
}, v = (t, e) => (n, i) => e(n, i, t);
|
|
828
828
|
const ce = "DESKTOP_FIND_REPLACE_DIALOG", we = 350, ti = 20, ii = 64;
|
|
829
|
-
let w = class extends
|
|
829
|
+
let w = class extends dt {
|
|
830
830
|
constructor(e, n, i, s, r, a, l, d, _) {
|
|
831
831
|
super();
|
|
832
832
|
o(this, "_closingListenerDisposable");
|
|
@@ -894,14 +894,14 @@ let w = class extends lt {
|
|
|
894
894
|
};
|
|
895
895
|
w = ei([
|
|
896
896
|
v(0, fe),
|
|
897
|
-
v(1,
|
|
898
|
-
v(2,
|
|
897
|
+
v(1, vt),
|
|
898
|
+
v(2, Ct),
|
|
899
899
|
v(3, U),
|
|
900
900
|
v(4, f),
|
|
901
|
-
v(5,
|
|
902
|
-
v(6,
|
|
901
|
+
v(5, Mt),
|
|
902
|
+
v(6, Se),
|
|
903
903
|
v(7, $(B)),
|
|
904
|
-
v(8, $(
|
|
904
|
+
v(8, $(Rt))
|
|
905
905
|
], w);
|
|
906
906
|
function ni() {
|
|
907
907
|
const { innerWidth: t } = window;
|
|
@@ -915,10 +915,10 @@ var ri = Object.getOwnPropertyDescriptor, ai = (t, e, n, i) => {
|
|
|
915
915
|
}, de = (t, e) => (n, i) => e(n, i, t);
|
|
916
916
|
const oi = "UNIVER_FIND_REPLACE_PLUGIN";
|
|
917
917
|
var V;
|
|
918
|
-
let he = (V = class extends
|
|
918
|
+
let he = (V = class extends ut {
|
|
919
919
|
constructor(t = le, e, n) {
|
|
920
920
|
super(), this._config = t, this._injector = e, this._configService = n;
|
|
921
|
-
const { ...i } =
|
|
921
|
+
const { ...i } = ft(
|
|
922
922
|
{},
|
|
923
923
|
le,
|
|
924
924
|
this._config
|
|
@@ -937,7 +937,7 @@ let he = (V = class extends ht {
|
|
|
937
937
|
}, o(V, "pluginName", oi), V);
|
|
938
938
|
he = ai([
|
|
939
939
|
de(1, $(ue)),
|
|
940
|
-
de(2,
|
|
940
|
+
de(2, ht)
|
|
941
941
|
], he);
|
|
942
942
|
export {
|
|
943
943
|
Z as FindBy,
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(l,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("@univerjs/ui"),require("@univerjs/design"),require("@univerjs/engine-render"),require("rxjs"),require("react"),require("react/jsx-runtime")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/ui","@univerjs/design","@univerjs/engine-render","rxjs","react","react/jsx-runtime"],o):(l=typeof globalThis<"u"?globalThis:l||self,o(l.UniverFindReplace={},l.UniverCore,l.UniverUi,l.UniverDesign,l.UniverEngineRender,l.rxjs,l.React,l.React))})(this,(function(l,o,c,_,re,m,p,h){"use strict";var at=Object.defineProperty;var rt=(l,o,c)=>o in l?at(l,o,{enumerable:!0,configurable:!0,writable:!0,value:c}):l[o]=c;var u=(l,o,c)=>rt(l,typeof o!="symbol"?o+"":o,c);var j;const V="FIND_REPLACE_INPUT_FOCUS",K="FIND_REPLACE_DIALOG_FOCUS",H="FIND_REPLACE_REPLACE_REVEALED";var oe=Object.getOwnPropertyDescriptor,q=(i,e,n,t)=>{for(var s=t>1?void 0:t?oe(e,n):e,a=i.length-1,r;a>=0;a--)(r=i[a])&&(s=r(s)||s);return s},P=(i,e)=>(n,t)=>e(n,t,i);class ce extends o.Disposable{}const S=o.createIdentifier("find-replace.service");function le(i){return typeof i.findString<"u"||typeof i.inputtingFindString<"u"||typeof i.findDirection<"u"||typeof i.matchesTheWholeCell<"u"||typeof i.caseSensitive<"u"||typeof i.findScope<"u"||typeof i.findBy<"u"}l.FindReplaceModel=class extends o.Disposable{constructor(n,t,s,a){super();u(this,"currentMatch$",new m.BehaviorSubject(null));u(this,"replaceables$",new m.BehaviorSubject([]));u(this,"_findModels",[]);u(this,"_matchingModel",null);u(this,"_matches",[]);u(this,"_currentSearchingDisposables",null);this._state=n,this._providers=t,this._univerInstanceService=s,this._commandService=a,this.disposeWithMe(this._state.stateUpdates$.pipe(m.throttleTime(200,void 0,{leading:!0,trailing:!0})).subscribe(async r=>{const d=this._state.state;le(r)&&(d.findString!==""&&!d.replaceRevealed?(await this._startSearching(),this._state.changeState({findCompleted:!0})):r.replaceRevealed!==!0&&this._stopSearching())}))}get searched(){return this._findModels.length>0}dispose(){super.dispose(),this._stopSearching(),this.currentMatch$.complete(),this.replaceables$.complete(),this._state.changeState({...$(),revealed:!1})}async start(){if(!this._state.findString)return{results:[]};const n=await this._startSearching();return this._state.changeState({findCompleted:!0}),n}focusSelection(){var n;(n=this._matchingModel)==null||n.focusSelection()}async _startSearching(){if(!this._state.findString)return{results:[]};const n=Array.from(this._providers),t=this._findModels=(await Promise.all(n.map(a=>a.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);const s=this._matches=t.map(a=>a.getMatches()).flat();return this.replaceables$.next(s.filter(a=>a.replaceable)),s.length?(this._moveToInitialMatch(t),this._state.changeState({matchesCount:s.length}),{results:s}):(this._state.changeState({matchesCount:0,matchesPosition:0}),{results:[]})}_stopSearching(){var n;this._providers.forEach(t=>t.terminate()),this._findModels=[],this._matches=[],this._matchingModel=null,(n=this._currentSearchingDisposables)==null||n.dispose(),this._currentSearchingDisposables=null,this.currentMatch$.next(null),this.replaceables$.next([]),this._state.changeState({findCompleted:!1,matchesCount:0,matchesPosition:0})}_subscribeToModelsChanges(n){const t=this._currentSearchingDisposables=new o.DisposableCollection,s=m.combineLatest(n.map(a=>a.matchesUpdate$)).pipe(m.debounceTime(220)).subscribe(([...a])=>{const r=this._matches=a.flat();r.length?(this._moveToInitialMatch(this._findModels,!0),this._state.changeState({matchesCount:r.length}),this.replaceables$.next(r.filter(d=>d.replaceable))):(this._state.changeState({matchesCount:0,matchesPosition:0}),this.replaceables$.next([]))});n.forEach(a=>t.add(o.toDisposable(a.activelyChangingMatch$.subscribe(r=>{const d=this._matches.findIndex(f=>f===r);this._state.changeState({matchesPosition:d+1})})))),t.add(o.toDisposable(s))}async replace(){return this._matchingModel?this._matchingModel.replace(this._state.replaceString):!1}async replaceAll(){const n=await Promise.all(this._findModels.map(t=>t.replaceAll(this._state.replaceString))).then(t=>t.reduce((s,a)=>(s.success+=a.success,s.failure+=a.failure,s),{success:0,failure:0}));return n.failure===0&&this._stopSearching(),n}getCurrentMatch(){return this._state.matchesPosition>0?this._matches[this._state.matchesPosition-1]:null}_markMatch(n){const t=this._matches.findIndex(s=>s===n);this.currentMatch$.next(n),this._state.changeState({matchesPosition:t+1})}moveToNextMatch(){if(!this._matchingModel)return;const n=this._findModels.length===1,t=this._matchingModel.moveToNextMatch({loop:n});if(t)return this._markMatch(t),t;{const s=this._findModels.findIndex(a=>a===this._matchingModel);return this._moveToNextUnitMatch(s)}}_moveToNextUnitMatch(n){const t=this._findModels.length;for(let s=(n+1)%t;s!==n;){const a=this._findModels[s],r=a.moveToNextMatch({ignoreSelection:!0});if(r)return this._matchingModel=a,this._markMatch(r),r;s=(s+1)%t}if(this._matchingModel){const s=this._matchingModel.moveToNextMatch({ignoreSelection:!0});return s&&this._markMatch(s),s}}moveToPreviousMatch(){if(!this._matchingModel)return;const n=this._findModels.length===1,t=this._matchingModel.moveToPreviousMatch({loop:n});if(t){const s=this._matches.findIndex(a=>a===t);return this.currentMatch$.next(t),this._state.changeState({matchesPosition:s+1}),t}else{const s=this._findModels.length,a=this._findModels.findIndex(d=>d===this._matchingModel);for(let d=(a-1+s)%s;d!==a;){const f=this._findModels[d],v=f.moveToPreviousMatch({ignoreSelection:!0});if(v)return this._matchingModel=f,this._markMatch(v),v;d=(d-1)%s}const r=this._matchingModel.moveToPreviousMatch({ignoreSelection:!0});return r&&this._markMatch(r),r}}_moveToInitialMatch(n,t=!1){var r;const s=(r=this._univerInstanceService.getFocusedUnit())==null?void 0:r.getUnitId();if(!s)return-1;const a=n.findIndex(d=>d.unitId===s);if(a!==-1){this._matchingModel=n[a];const d=this._matchingModel.moveToNextMatch({stayIfOnMatch:!0,noFocus:t});if(d)return this._markMatch(d),a}return this._moveToNextUnitMatch(a),0}},l.FindReplaceModel=q([P(2,o.IUniverInstanceService),P(3,o.ICommandService)],l.FindReplaceModel);var E=(i=>(i.ROW="row",i.COLUMN="column",i))(E||{}),O=(i=>(i.VALUE="value",i.FORMULA="formula",i))(O||{}),N=(i=>(i.SUBUNIT="subunit",i.UNIT="unit",i))(N||{});function $(){return{caseSensitive:!1,findBy:"value",findCompleted:!1,findDirection:"row",findScope:"subunit",findString:"",inputtingFindString:"",matchesCount:0,matchesPosition:0,matchesTheWholeCell:!1,replaceRevealed:!1,replaceString:"",revealed:!0}}class Z{constructor(){u(this,"_stateUpdates$",new m.Subject);u(this,"stateUpdates$",this._stateUpdates$.asObservable());u(this,"_state$",new m.BehaviorSubject($()));u(this,"state$",this._state$.asObservable());u(this,"_findString","");u(this,"_inputtingFindString","");u(this,"_replaceString","");u(this,"_revealed",!1);u(this,"_replaceRevealed",!1);u(this,"_matchesPosition",0);u(this,"_matchesCount",0);u(this,"_caseSensitive",!0);u(this,"_matchesTheWholeCell",!1);u(this,"_findDirection","row");u(this,"_findScope","subunit");u(this,"_findBy","value");u(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 n=!1;const t={};typeof e.findString<"u"&&e.findString!==this._findString&&(this._findString=e.findString,t.findString=this._findString,n=!0),typeof e.revealed<"u"&&e.revealed!==this._revealed&&(this._revealed=e.revealed,t.revealed=e.revealed,n=!0),typeof e.replaceRevealed<"u"&&e.replaceRevealed!==this._replaceRevealed&&(this._replaceRevealed=e.replaceRevealed,t.replaceRevealed=e.replaceRevealed,n=!0),typeof e.replaceString<"u"&&e.replaceString!==this._replaceString&&(this._replaceString=e.replaceString,t.replaceString=e.replaceString,n=!0),typeof e.matchesCount<"u"&&e.matchesCount!==this._matchesCount&&(this._matchesCount=e.matchesCount,t.matchesCount=e.matchesCount,n=!0),typeof e.matchesPosition<"u"&&e.matchesPosition!==this._matchesPosition&&(this._matchesPosition=e.matchesPosition,t.matchesPosition=e.matchesPosition,n=!0),typeof e.findBy<"u"&&e.findBy!==this._findBy&&(this._findBy=e.findBy,t.findBy=e.findBy,n=!0),typeof e.findScope<"u"&&e.findScope!==this._findScope&&(this._findScope=e.findScope,t.findScope=e.findScope,n=!0),typeof e.findDirection<"u"&&e.findDirection!==this._findDirection&&(this._findDirection=e.findDirection,t.findDirection=e.findDirection,n=!0),typeof e.caseSensitive<"u"&&e.caseSensitive!==this._caseSensitive&&(this._caseSensitive=e.caseSensitive,t.caseSensitive=e.caseSensitive,n=!0),typeof e.matchesTheWholeCell<"u"&&e.matchesTheWholeCell!==this._matchesTheWholeCell&&(this._matchesTheWholeCell=e.matchesTheWholeCell,t.matchesTheWholeCell=e.matchesTheWholeCell,n=!0),typeof e.inputtingFindString<"u"&&e.inputtingFindString!==this._inputtingFindString&&(this._inputtingFindString=e.inputtingFindString,t.inputtingFindString=e.inputtingFindString,n=!0),typeof e.findCompleted<"u"&&e.findCompleted!==this._findCompleted&&(this._findCompleted=e.findCompleted,t.findCompleted=e.findCompleted,n=!0),n&&(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(t))}}let A=class extends o.Disposable{constructor(e,n){super();u(this,"_providers",new Set);u(this,"_state",new Z);u(this,"_model");u(this,"_currentMatch$",new m.BehaviorSubject(null));u(this,"currentMatch$",this._currentMatch$.asObservable());u(this,"_replaceables$",new m.BehaviorSubject([]));u(this,"replaceables$",this._replaceables$.asObservable());u(this,"_focusSignal$",new m.Subject);u(this,"focusSignal$",this._focusSignal$.asObservable());this._injector=e,this._contextService=n}get stateUpdates$(){return this._state.stateUpdates$}get state$(){return this._state.state$}get revealed(){return this._state.revealed}get replaceRevealed(){return this._state.replaceRevealed}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==="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 new 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(l.FindReplaceModel,this._state,this._providers),this._model.currentMatch$.subscribe(t=>this._currentMatch$.next(t)),this._model.replaceables$.subscribe(t=>this._replaceables$.next(t));const n=$();return e&&(n.replaceRevealed=!0),this._state.changeState(n),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),o.toDisposable(()=>this._providers.delete(e))}_toggleRevealReplace(e){this._contextService.setContextValue(H,e)}_toggleDisplayRawFormula(e){this._contextService.setContextValue(re.RENDER_RAW_FORMULA_KEY,e)}};A=q([P(0,o.Inject(o.Injector)),P(1,o.IContextService)],A);const U={id:"ui.command.replace-current-match",type:o.CommandType.COMMAND,handler:i=>i.get(S).replace()},de="CONFIRM_REPLACE_ALL",x={id:"ui.command.replace-all-matches",type:o.CommandType.COMMAND,handler:async i=>{const e=i.get(c.IConfirmService),n=i.get(o.LocaleService),t=i.get(c.IMessageService);if(!await e.confirm({id:de,title:{title:n.t("find-replace.replace.confirm.title")},cancelText:n.t("button.cancel"),confirmText:n.t("button.confirm")}))return!1;const a=await i.get(S).replaceAll(),{success:r,failure:d}=a;return d>0?(r===0?t.show({type:_.MessageType.Error,content:n.t("find-replace.replace.all-failure")}):t.show({type:_.MessageType.Warning,content:n.t("find-replace.replace.partial-success",`${r}`,`${d}`)}),!1):(t.show({type:_.MessageType.Success,content:n.t("find-replace.replace.all-success",`${r}`)}),!0)}},I={id:"ui.operation.open-find-dialog",type:o.CommandType.OPERATION,handler:i=>{const e=i.get(S);return e.revealed?e.focusFindInput():e.start(),!0}},L={id:"ui.operation.open-replace-dialog",type:o.CommandType.OPERATION,handler:i=>{const e=i.get(S);return e.revealed?e.replaceRevealed?e.focusFindInput():e.revealReplace():e.start(!0),!0}},w={type:o.CommandType.OPERATION,id:"ui.operation.go-to-next-match",handler:i=>(i.get(S).moveToNextMatch(),!0)},k={type:o.CommandType.OPERATION,id:"ui.operation.go-to-previous-match",handler:i=>(i.get(S).moveToPreviousMatch(),!0)},z={type:o.CommandType.OPERATION,id:"ui.operation.focus-selection",handler:i=>(i.get(S).focusSelection(),!0)};function Y({ref:i,...e}){const{icon:n,id:t,className:s,extend:a,...r}=e,d=`univerjs-icon univerjs-icon-${t} ${s||""}`.trim(),f=p.useRef(`_${pe()}`);return J(n,`${t}`,{defIds:n.defIds,idSuffix:f.current},{ref:i,className:d,...r},a)}function J(i,e,n,t,s){return p.createElement(i.tag,{key:e,...he(i,n,s),...t},(ue(i,n).children||[]).map((a,r)=>J(a,`${e}-${i.tag}-${r}`,n,void 0,s)))}function he(i,e,n){const t={...i.attrs};n!=null&&n.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=n.colorChannel1),i.tag==="mask"&&t.id&&(t.id=t.id+e.idSuffix),Object.entries(t).forEach(([a,r])=>{a==="mask"&&typeof r=="string"&&(t[a]=r.replace(/url\(#(.*)\)/,`url(#$1${e.idSuffix})`))});const{defIds:s}=e;return!s||s.length===0||(i.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+e.idSuffix),Object.entries(t).forEach(([a,r])=>{typeof r=="string"&&(t[a]=r.replace(/url\(#(.*)\)/,`url(#$1${e.idSuffix})`))})),t}function ue(i,e){var t;const{defIds:n}=e;return!n||n.length===0?i:i.tag==="defs"&&((t=i.children)!=null&&t.length)?{...i,children:i.children.map(s=>typeof s.attrs.id=="string"&&n&&n.includes(s.attrs.id)?{...s,attrs:{...s.attrs,id:s.attrs.id+e.idSuffix}}:s)}:i}function pe(){return Math.random().toString(36).substring(2,8)}Y.displayName="UniverIcon";const fe={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"}}]},Q=p.forwardRef(function(e,n){return p.createElement(Y,Object.assign({},e,{id:"search-icon",ref:n,icon:fe}))});Q.displayName="SearchIcon";function X(i){const{findCompleted:e,localeService:n,matchesCount:t,matchesPosition:s,initialFindString:a,findReplaceService:r,onChange:d,...f}=i,[v,C]=p.useState(a),D=e&&t===0?n.t("find-replace.dialog.no-result"):t===0?" ":void 0;function y(M){s===t&&M===1?r.moveToNextMatch():s===1&&M===t||M<s?r.moveToPreviousMatch():r.moveToNextMatch()}return h.jsx("div",{className:"univer-relative univer-flex univer-items-center univer-gap-2",onDrag:M=>M.stopPropagation(),children:h.jsx(_.Input,{"data-u-comp":"search-input",autoFocus:!0,placeholder:n.t("find-replace.dialog.find-placeholder"),value:v,onChange:M=>{C(M),d==null||d(M)},slot:h.jsx(_.Pager,{loop:!0,text:D,value:s,total:t,onChange:y}),...f})})}function ee(i,e){const n=p.useCallback(()=>{var s;(s=document.querySelector(".univer-find-input input"))==null||s.focus()},[]),t=p.useCallback(()=>{const s=document.querySelectorAll("[data-u-comp=find-replace-dialog] [data-u-comp=search-input]");return Array.from(s).some(a=>a===document.activeElement)},[]);return p.useImperativeHandle(e,()=>({focus:n,selectHasFocus:t})),p.useEffect(()=>{const s=i.focusSignal$.subscribe(()=>n());return()=>s.unsubscribe()},[i,n]),{focus:n,selectHasFocus:t}}const _e=p.forwardRef(function(e,n){const t=c.useDependency(o.LocaleService),s=c.useDependency(S),a=c.useDependency(o.ICommandService),r=c.useObservable(s.state$,void 0,!0),{findCompleted:d,findString:f,matchesCount:v,matchesPosition:C}=r,F=p.useCallback(()=>{a.executeCommand(L.id)},[a]),D=c.useDebounceFn(y=>s.changeFindString(y),500);return ee(s,n),h.jsxs(h.Fragment,{children:[h.jsx(X,{findCompleted:d,matchesCount:v,matchesPosition:C,findReplaceService:s,localeService:t,initialFindString:f,onChange:D}),h.jsx("div",{className:"univer-mt-4 univer-text-center",children:h.jsx("a",{className:"hover:univer-text-primary-500/80 univer-cursor-pointer univer-text-sm univer-text-primary-500 univer-transition-colors",onClick:F,children:t.t("find-replace.dialog.advanced-finding")})})]})}),ge=p.forwardRef(function(e,n){const t=c.useDependency(S),s=c.useDependency(o.LocaleService),a=c.useDependency(o.ICommandService),r=c.useDependency(c.IMessageService),d=c.useObservable(t.currentMatch$,void 0,!0),f=c.useObservable(t.replaceables$,void 0,!0),v=c.useObservable(t.state$,void 0,!0),{matchesCount:C,matchesPosition:F,findString:D,inputtingFindString:y,replaceString:M,caseSensitive:ke,matchesTheWholeCell:Be,findDirection:We,findScope:je,findBy:Ge,findCompleted:G}=v,Ve=y.length===0,Ke=C===0||!(d!=null&&d.replaceable),He=f.length===0,qe=p.useCallback(g=>t.changeInputtingFindString(g),[t]),Ze=p.useCallback(g=>t.changeReplaceString(g),[t]),{focus:ze}=ee(t,n),Ye=p.useCallback(()=>{D===y?t.moveToNextMatch():(t.changeFindString(y),t.find())},[D,y,t]),Je=p.useCallback(()=>a.executeCommand(U.id),[a]),Qe=p.useCallback(async()=>{await a.executeCommand(x.id),ze()},[a]),Xe=p.useCallback(g=>{t.changeFindDirection(g)},[t]),et=p.useCallback(g=>{t.changeFindScope(g)},[t]),tt=p.useCallback(g=>{t.changeFindBy(g)},[t]),it=ve(s),nt=Se(s),st=Ce(s);return p.useEffect(()=>{G&&C===0&&r.show({content:s.t("find-replace.dialog.no-match"),type:_.MessageType.Warning,duration:5e3})},[G,C,r,s]),h.jsxs("div",{children:[h.jsx(_.FormLayout,{label:s.t("find-replace.dialog.find"),children:h.jsx(X,{findCompleted:G,className:"univer-find-input",matchesCount:C,matchesPosition:F,findReplaceService:t,localeService:s,initialFindString:y,onChange:qe})}),h.jsx(_.FormLayout,{label:s.t("find-replace.dialog.replace"),children:h.jsx(_.Input,{placeholder:s.t("find-replace.dialog.replace-placeholder"),value:M,onChange:g=>Ze(g)})}),h.jsx(_.FormLayout,{label:s.t("find-replace.dialog.find-direction.title"),children:h.jsx(_.Select,{value:We,options:nt,onChange:Xe})}),h.jsx(_.FormDualColumnLayout,{children:h.jsxs(h.Fragment,{children:[h.jsx(_.FormLayout,{label:s.t("find-replace.dialog.find-scope.title"),children:h.jsx(_.Select,{value:je,options:it,onChange:et})}),h.jsx(_.FormLayout,{label:s.t("find-replace.dialog.find-by.title"),children:h.jsx(_.Select,{value:Ge,options:st,onChange:tt})})]})}),h.jsx(_.FormDualColumnLayout,{children:h.jsxs(h.Fragment,{children:[h.jsx(_.FormLayout,{children:h.jsx(_.Checkbox,{checked:ke,onChange:g=>{t.changeCaseSensitive(g)},children:s.t("find-replace.dialog.case-sensitive")})}),h.jsx(_.FormLayout,{children:h.jsx(_.Checkbox,{checked:Be,onChange:g=>{t.changeMatchesTheWholeCell(g)},children:s.t("find-replace.dialog.match-the-whole-cell")})})]})}),h.jsxs("div",{className:"univer-mt-6 univer-flex univer-justify-between",children:[h.jsx(_.Button,{variant:"primary",onClick:Ye,disabled:Ve,children:s.t("find-replace.dialog.find")}),h.jsxs("span",{className:"univer-inline-flex univer-gap-2",children:[h.jsx(_.Button,{disabled:Ke,onClick:Je,children:s.t("find-replace.dialog.replace")}),h.jsx(_.Button,{disabled:He,onClick:Qe,children:s.t("find-replace.dialog.replace-all")})]})]})]})});function me(){const i=c.useDependency(S),e=c.useDependency(c.ILayoutService),n=c.useDependency(o.IContextService),t=c.useObservable(i.state$,void 0,!0),s=p.useRef(null);p.useEffect(()=>{let f;return s.current&&(f=e.registerContainerElement(s.current)),()=>f==null?void 0:f.dispose()},[e]);const a=p.useRef(null),r=p.useCallback(f=>n.setContextValue(K,f),[n]),d=p.useCallback(f=>n.setContextValue(V,f),[n]);return p.useEffect(()=>{var v;const f=m.fromEvent(document,"focusin").subscribe(C=>{var F;C.target&&((F=s.current)!=null&&F.contains(C.target))?r(!0):r(!1),!a.current||!a.current.selectHasFocus()?d(!1):d(!0)});return(v=a.current)==null||v.focus(),r(!0),d(!0),()=>{f.unsubscribe(),r(!1)}},[r,d]),h.jsx("div",{ref:s,"data-u-comp":"find-replace-dialog",children:t.replaceRevealed?h.jsx(ge,{ref:a}):h.jsx(_e,{ref:a})})}function ve(i){const e=i.getCurrentLocale();return p.useMemo(()=>[{label:i.t("find-replace.dialog.find-scope.current-sheet"),value:N.SUBUNIT},{label:i.t("find-replace.dialog.find-scope.workbook"),value:N.UNIT}],[e])}function Se(i){const e=i.getCurrentLocale();return p.useMemo(()=>[{label:i.t("find-replace.dialog.find-direction.row"),value:E.ROW},{label:i.t("find-replace.dialog.find-direction.column"),value:E.COLUMN}],[e])}function Ce(i){const e=i.getCurrentLocale();return p.useMemo(()=>[{label:i.t("find-replace.dialog.find-by.value"),value:O.VALUE},{label:i.t("find-replace.dialog.find-by.formula"),value:O.FORMULA}],[e])}function R(i){return i.getContextValue(K)}function Me(i){return i.getContextValue(H)}function te(i){return i.getContextValue(V)}const T="7_find-replace-shortcuts";function B(i){return i.getContextValue(o.FOCUSING_SHEET)}function W(i){return!i.getContextValue(o.EDITOR_ACTIVATED)}const be={id:I.id,description:"find-replace.shortcut.open-find-dialog",binding:c.KeyCode.F|c.MetaKeys.CTRL_COMMAND,group:T,preconditions(i){return!R(i)&&B(i)&&W(i)}},ye={id:I.id,description:"find-replace.shortcut.open-find-dialog",binding:c.KeyCode.F|c.MetaKeys.CTRL_COMMAND,mac:c.KeyCode.F|c.MetaKeys.MAC_CTRL,preconditions(i){return!R(i)&&B(i)&&W(i)}},Fe={id:L.id,description:"find-replace.shortcut.open-replace-dialog",binding:c.KeyCode.H|c.MetaKeys.CTRL_COMMAND,mac:c.KeyCode.H|c.MetaKeys.MAC_CTRL,group:T,preconditions(i){return B(i)&&W(i)&&(!R(i)||!Me(i))}},Ie={id:w.id,description:"find-replace.shortcut.go-to-next-match",binding:c.KeyCode.ENTER,group:T,priority:1e3,preconditions(i){return te(i)&&R(i)}},Re={id:k.id,description:"find-replace.shortcut.go-to-previous-match",binding:c.KeyCode.ENTER|c.MetaKeys.SHIFT,group:T,priority:1e3,preconditions(i){return te(i)&&R(i)}},De={id:z.id,description:"find-replace.shortcut.focus-selection",binding:c.KeyCode.ESC,group:T,priority:1e3,preconditions(i){return R(i)}};function Te(i){const e=i.get(o.IContextService);return{id:I.id,icon:"SearchIcon",tooltip:"find-replace.toolbar",type:c.MenuItemType.BUTTON,hidden$:c.getMenuHiddenObservable(i,o.UniverInstanceType.UNIVER_SHEET),disabled$:m.combineLatest([e.subscribeContextValue$(o.EDITOR_ACTIVATED),e.subscribeContextValue$(o.FOCUSING_SHEET)]).pipe(m.map(([n,t])=>n||!t))}}const Pe={[c.RibbonDataGroup.ORGANIZATION]:{[I.id]:{order:2,menuItemFactory:Te}}};var Ee=Object.getOwnPropertyDescriptor,Oe=(i,e,n,t)=>{for(var s=t>1?void 0:t?Ee(e,n):e,a=i.length-1,r;a>=0;a--)(r=i[a])&&(s=r(s)||s);return s},b=(i,e)=>(n,t)=>e(n,t,i);const ie="DESKTOP_FIND_REPLACE_DIALOG",ne=350,Ne=20,$e=64;l.FindReplaceController=class extends o.RxDisposable{constructor(n,t,s,a,r,d,f,v,C){super();u(this,"_closingListenerDisposable");this._univerInstanceService=n,this._menuManagerService=t,this._shortcutService=s,this._commandService=a,this._findReplaceService=r,this._dialogService=d,this._layoutService=f,this._localeService=v,this._componentManager=C,this._initCommands(),this._initUI(),this._initShortcuts()}dispose(){var n;super.dispose(),(n=this._closingListenerDisposable)==null||n.dispose(),this._closingListenerDisposable=null}_initCommands(){[I,L,w,k,x,U,z].forEach(n=>{this.disposeWithMe(this._commandService.registerCommand(n))})}_initShortcuts(){[Fe,be,ye,Re,Ie,De].forEach(n=>this.disposeWithMe(this._shortcutService.registerShortcut(n)))}_initUI(){[["FindReplaceDialog",me],["SearchIcon",Q]].forEach(([n,t])=>{this.disposeWithMe(this._componentManager.register(n,t))}),this._menuManagerService.mergeMenu(Pe),this._findReplaceService.stateUpdates$.pipe(m.takeUntil(this.dispose$)).subscribe(n=>{n.revealed===!0&&this._openPanel()})}_openPanel(){this._dialogService.open({id:ie,draggable:!0,width:ne,title:{title:this._localeService.t("find-replace.dialog.title")},children:{label:"FindReplaceDialog"},destroyOnClose:!0,mask:!1,maskClosable:!1,defaultPosition:Le(),preservePositionOnDestroy:!0,onClose:()=>this.closePanel()}),this._closingListenerDisposable=o.toDisposable(this._univerInstanceService.focused$.pipe(m.takeUntil(this.dispose$)).subscribe(n=>{(!n||!this._univerInstanceService.getUniverSheetInstance(n))&&this.closePanel()}))}closePanel(){this._closingListenerDisposable&&(this._closingListenerDisposable.dispose(),this._closingListenerDisposable=null,this._dialogService.close(ie),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus()))}},l.FindReplaceController=Oe([b(0,o.IUniverInstanceService),b(1,c.IMenuManagerService),b(2,c.IShortcutService),b(3,o.ICommandService),b(4,S),b(5,c.IDialogService),b(6,c.ILayoutService),b(7,o.Inject(o.LocaleService)),b(8,o.Inject(c.ComponentManager))],l.FindReplaceController);function Le(){const{innerWidth:i}=window;return{x:i-ne-Ne,y:$e}}const Ae="find-replace.config",se={};var Ue=Object.getOwnPropertyDescriptor,xe=(i,e,n,t)=>{for(var s=t>1?void 0:t?Ue(e,n):e,a=i.length-1,r;a>=0;a--)(r=i[a])&&(s=r(s)||s);return s},ae=(i,e)=>(n,t)=>e(n,t,i);const we="UNIVER_FIND_REPLACE_PLUGIN";l.UniverFindReplacePlugin=(j=class extends o.Plugin{constructor(e=se,n,t){super(),this._config=e,this._injector=n,this._configService=t;const{...s}=o.merge({},se,this._config);this._configService.setConfig(Ae,s)}onStarting(){[[l.FindReplaceController],[S,{useClass:A}]].forEach(e=>this._injector.add(e))}onRendered(){this._injector.get(l.FindReplaceController)}},u(j,"pluginName",we),j),l.UniverFindReplacePlugin=xe([ae(1,o.Inject(o.Injector)),ae(2,o.IConfigService)],l.UniverFindReplacePlugin),l.FindBy=O,l.FindDirection=E,l.FindModel=ce,l.FindReplaceState=Z,l.FindScope=N,l.GoToNextMatchOperation=w,l.GoToPreviousMatchOperation=k,l.IFindReplaceService=S,l.OpenFindDialogOperation=I,l.OpenReplaceDialogOperation=L,l.ReplaceAllMatchesCommand=x,l.ReplaceCurrentMatchCommand=U,l.createInitFindReplaceState=$,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(c,o){typeof exports=="object"&&typeof module<"u"?o(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"],o):(c=typeof globalThis<"u"?globalThis:c||self,o(c.UniverFindReplace={},c.UniverCore,c.UniverDesign,c.UniverUi,c.UniverEngineRender,c.rxjs,c.React,c.React))})(this,(function(c,o,f,l,re,m,p,h){"use strict";var at=Object.defineProperty;var rt=(c,o,f)=>o in c?at(c,o,{enumerable:!0,configurable:!0,writable:!0,value:f}):c[o]=f;var u=(c,o,f)=>rt(c,typeof o!="symbol"?o+"":o,f);var j;const V="FIND_REPLACE_INPUT_FOCUS",K="FIND_REPLACE_DIALOG_FOCUS",H="FIND_REPLACE_REPLACE_REVEALED";var oe=Object.getOwnPropertyDescriptor,q=(i,e,n,t)=>{for(var s=t>1?void 0:t?oe(e,n):e,a=i.length-1,r;a>=0;a--)(r=i[a])&&(s=r(s)||s);return s},P=(i,e)=>(n,t)=>e(n,t,i);class ce extends o.Disposable{}const S=o.createIdentifier("find-replace.service");function le(i){return typeof i.findString<"u"||typeof i.inputtingFindString<"u"||typeof i.findDirection<"u"||typeof i.matchesTheWholeCell<"u"||typeof i.caseSensitive<"u"||typeof i.findScope<"u"||typeof i.findBy<"u"}c.FindReplaceModel=class extends o.Disposable{constructor(n,t,s,a){super();u(this,"currentMatch$",new m.BehaviorSubject(null));u(this,"replaceables$",new m.BehaviorSubject([]));u(this,"_findModels",[]);u(this,"_matchingModel",null);u(this,"_matches",[]);u(this,"_currentSearchingDisposables",null);this._state=n,this._providers=t,this._univerInstanceService=s,this._commandService=a,this.disposeWithMe(this._state.stateUpdates$.pipe(m.throttleTime(200,void 0,{leading:!0,trailing:!0})).subscribe(async r=>{const d=this._state.state;le(r)&&(d.findString!==""&&!d.replaceRevealed?(await this._startSearching(),this._state.changeState({findCompleted:!0})):r.replaceRevealed!==!0&&this._stopSearching())}))}get searched(){return this._findModels.length>0}dispose(){super.dispose(),this._stopSearching(),this.currentMatch$.complete(),this.replaceables$.complete(),this._state.changeState({...$(),revealed:!1})}async start(){if(!this._state.findString)return{results:[]};const n=await this._startSearching();return this._state.changeState({findCompleted:!0}),n}focusSelection(){var n;(n=this._matchingModel)==null||n.focusSelection()}async _startSearching(){if(!this._state.findString)return{results:[]};const n=Array.from(this._providers),t=this._findModels=(await Promise.all(n.map(a=>a.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);const s=this._matches=t.map(a=>a.getMatches()).flat();return this.replaceables$.next(s.filter(a=>a.replaceable)),s.length?(this._moveToInitialMatch(t),this._state.changeState({matchesCount:s.length}),{results:s}):(this._state.changeState({matchesCount:0,matchesPosition:0}),{results:[]})}_stopSearching(){var n;this._providers.forEach(t=>t.terminate()),this._findModels=[],this._matches=[],this._matchingModel=null,(n=this._currentSearchingDisposables)==null||n.dispose(),this._currentSearchingDisposables=null,this.currentMatch$.next(null),this.replaceables$.next([]),this._state.changeState({findCompleted:!1,matchesCount:0,matchesPosition:0})}_subscribeToModelsChanges(n){const t=this._currentSearchingDisposables=new o.DisposableCollection,s=m.combineLatest(n.map(a=>a.matchesUpdate$)).pipe(m.debounceTime(220)).subscribe(([...a])=>{const r=this._matches=a.flat();r.length?(this._moveToInitialMatch(this._findModels,!0),this._state.changeState({matchesCount:r.length}),this.replaceables$.next(r.filter(d=>d.replaceable))):(this._state.changeState({matchesCount:0,matchesPosition:0}),this.replaceables$.next([]))});n.forEach(a=>t.add(o.toDisposable(a.activelyChangingMatch$.subscribe(r=>{const d=this._matches.findIndex(_=>_===r);this._state.changeState({matchesPosition:d+1})})))),t.add(o.toDisposable(s))}async replace(){return this._matchingModel?this._matchingModel.replace(this._state.replaceString):!1}async replaceAll(){const n=await Promise.all(this._findModels.map(t=>t.replaceAll(this._state.replaceString))).then(t=>t.reduce((s,a)=>(s.success+=a.success,s.failure+=a.failure,s),{success:0,failure:0}));return n.failure===0&&this._stopSearching(),n}getCurrentMatch(){return this._state.matchesPosition>0?this._matches[this._state.matchesPosition-1]:null}_markMatch(n){const t=this._matches.findIndex(s=>s===n);this.currentMatch$.next(n),this._state.changeState({matchesPosition:t+1})}moveToNextMatch(){if(!this._matchingModel)return;const n=this._findModels.length===1,t=this._matchingModel.moveToNextMatch({loop:n});if(t)return this._markMatch(t),t;{const s=this._findModels.findIndex(a=>a===this._matchingModel);return this._moveToNextUnitMatch(s)}}_moveToNextUnitMatch(n){const t=this._findModels.length;for(let s=(n+1)%t;s!==n;){const a=this._findModels[s],r=a.moveToNextMatch({ignoreSelection:!0});if(r)return this._matchingModel=a,this._markMatch(r),r;s=(s+1)%t}if(this._matchingModel){const s=this._matchingModel.moveToNextMatch({ignoreSelection:!0});return s&&this._markMatch(s),s}}moveToPreviousMatch(){if(!this._matchingModel)return;const n=this._findModels.length===1,t=this._matchingModel.moveToPreviousMatch({loop:n});if(t){const s=this._matches.findIndex(a=>a===t);return this.currentMatch$.next(t),this._state.changeState({matchesPosition:s+1}),t}else{const s=this._findModels.length,a=this._findModels.findIndex(d=>d===this._matchingModel);for(let d=(a-1+s)%s;d!==a;){const _=this._findModels[d],v=_.moveToPreviousMatch({ignoreSelection:!0});if(v)return this._matchingModel=_,this._markMatch(v),v;d=(d-1)%s}const r=this._matchingModel.moveToPreviousMatch({ignoreSelection:!0});return r&&this._markMatch(r),r}}_moveToInitialMatch(n,t=!1){var r;const s=(r=this._univerInstanceService.getFocusedUnit())==null?void 0:r.getUnitId();if(!s)return-1;const a=n.findIndex(d=>d.unitId===s);if(a!==-1){this._matchingModel=n[a];const d=this._matchingModel.moveToNextMatch({stayIfOnMatch:!0,noFocus:t});if(d)return this._markMatch(d),a}return this._moveToNextUnitMatch(a),0}},c.FindReplaceModel=q([P(2,o.IUniverInstanceService),P(3,o.ICommandService)],c.FindReplaceModel);var E=(i=>(i.ROW="row",i.COLUMN="column",i))(E||{}),O=(i=>(i.VALUE="value",i.FORMULA="formula",i))(O||{}),N=(i=>(i.SUBUNIT="subunit",i.UNIT="unit",i))(N||{});function $(){return{caseSensitive:!1,findBy:"value",findCompleted:!1,findDirection:"row",findScope:"subunit",findString:"",inputtingFindString:"",matchesCount:0,matchesPosition:0,matchesTheWholeCell:!1,replaceRevealed:!1,replaceString:"",revealed:!0}}class Z{constructor(){u(this,"_stateUpdates$",new m.Subject);u(this,"stateUpdates$",this._stateUpdates$.asObservable());u(this,"_state$",new m.BehaviorSubject($()));u(this,"state$",this._state$.asObservable());u(this,"_findString","");u(this,"_inputtingFindString","");u(this,"_replaceString","");u(this,"_revealed",!1);u(this,"_replaceRevealed",!1);u(this,"_matchesPosition",0);u(this,"_matchesCount",0);u(this,"_caseSensitive",!0);u(this,"_matchesTheWholeCell",!1);u(this,"_findDirection","row");u(this,"_findScope","subunit");u(this,"_findBy","value");u(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 n=!1;const t={};typeof e.findString<"u"&&e.findString!==this._findString&&(this._findString=e.findString,t.findString=this._findString,n=!0),typeof e.revealed<"u"&&e.revealed!==this._revealed&&(this._revealed=e.revealed,t.revealed=e.revealed,n=!0),typeof e.replaceRevealed<"u"&&e.replaceRevealed!==this._replaceRevealed&&(this._replaceRevealed=e.replaceRevealed,t.replaceRevealed=e.replaceRevealed,n=!0),typeof e.replaceString<"u"&&e.replaceString!==this._replaceString&&(this._replaceString=e.replaceString,t.replaceString=e.replaceString,n=!0),typeof e.matchesCount<"u"&&e.matchesCount!==this._matchesCount&&(this._matchesCount=e.matchesCount,t.matchesCount=e.matchesCount,n=!0),typeof e.matchesPosition<"u"&&e.matchesPosition!==this._matchesPosition&&(this._matchesPosition=e.matchesPosition,t.matchesPosition=e.matchesPosition,n=!0),typeof e.findBy<"u"&&e.findBy!==this._findBy&&(this._findBy=e.findBy,t.findBy=e.findBy,n=!0),typeof e.findScope<"u"&&e.findScope!==this._findScope&&(this._findScope=e.findScope,t.findScope=e.findScope,n=!0),typeof e.findDirection<"u"&&e.findDirection!==this._findDirection&&(this._findDirection=e.findDirection,t.findDirection=e.findDirection,n=!0),typeof e.caseSensitive<"u"&&e.caseSensitive!==this._caseSensitive&&(this._caseSensitive=e.caseSensitive,t.caseSensitive=e.caseSensitive,n=!0),typeof e.matchesTheWholeCell<"u"&&e.matchesTheWholeCell!==this._matchesTheWholeCell&&(this._matchesTheWholeCell=e.matchesTheWholeCell,t.matchesTheWholeCell=e.matchesTheWholeCell,n=!0),typeof e.inputtingFindString<"u"&&e.inputtingFindString!==this._inputtingFindString&&(this._inputtingFindString=e.inputtingFindString,t.inputtingFindString=e.inputtingFindString,n=!0),typeof e.findCompleted<"u"&&e.findCompleted!==this._findCompleted&&(this._findCompleted=e.findCompleted,t.findCompleted=e.findCompleted,n=!0),n&&(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(t))}}let A=class extends o.Disposable{constructor(e,n){super();u(this,"_providers",new Set);u(this,"_state",new Z);u(this,"_model");u(this,"_currentMatch$",new m.BehaviorSubject(null));u(this,"currentMatch$",this._currentMatch$.asObservable());u(this,"_replaceables$",new m.BehaviorSubject([]));u(this,"replaceables$",this._replaceables$.asObservable());u(this,"_focusSignal$",new m.Subject);u(this,"focusSignal$",this._focusSignal$.asObservable());this._injector=e,this._contextService=n}get stateUpdates$(){return this._state.stateUpdates$}get state$(){return this._state.state$}get revealed(){return this._state.revealed}get replaceRevealed(){return this._state.replaceRevealed}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==="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 new 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(c.FindReplaceModel,this._state,this._providers),this._model.currentMatch$.subscribe(t=>this._currentMatch$.next(t)),this._model.replaceables$.subscribe(t=>this._replaceables$.next(t));const n=$();return e&&(n.replaceRevealed=!0),this._state.changeState(n),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),o.toDisposable(()=>this._providers.delete(e))}_toggleRevealReplace(e){this._contextService.setContextValue(H,e)}_toggleDisplayRawFormula(e){this._contextService.setContextValue(re.RENDER_RAW_FORMULA_KEY,e)}};A=q([P(0,o.Inject(o.Injector)),P(1,o.IContextService)],A);const U={id:"ui.command.replace-current-match",type:o.CommandType.COMMAND,handler:i=>i.get(S).replace()},de="CONFIRM_REPLACE_ALL",x={id:"ui.command.replace-all-matches",type:o.CommandType.COMMAND,handler:async i=>{const e=i.get(o.IConfirmService),n=i.get(o.LocaleService),t=i.get(l.IMessageService);if(!await e.confirm({id:de,title:{title:n.t("find-replace.replace.confirm.title")},cancelText:n.t("button.cancel"),confirmText:n.t("button.confirm")}))return!1;const a=await i.get(S).replaceAll(),{success:r,failure:d}=a;return d>0?(r===0?t.show({type:f.MessageType.Error,content:n.t("find-replace.replace.all-failure")}):t.show({type:f.MessageType.Warning,content:n.t("find-replace.replace.partial-success",`${r}`,`${d}`)}),!1):(t.show({type:f.MessageType.Success,content:n.t("find-replace.replace.all-success",`${r}`)}),!0)}},I={id:"ui.operation.open-find-dialog",type:o.CommandType.OPERATION,handler:i=>{const e=i.get(S);return e.revealed?e.focusFindInput():e.start(),!0}},L={id:"ui.operation.open-replace-dialog",type:o.CommandType.OPERATION,handler:i=>{const e=i.get(S);return e.revealed?e.replaceRevealed?e.focusFindInput():e.revealReplace():e.start(!0),!0}},w={type:o.CommandType.OPERATION,id:"ui.operation.go-to-next-match",handler:i=>(i.get(S).moveToNextMatch(),!0)},k={type:o.CommandType.OPERATION,id:"ui.operation.go-to-previous-match",handler:i=>(i.get(S).moveToPreviousMatch(),!0)},z={type:o.CommandType.OPERATION,id:"ui.operation.focus-selection",handler:i=>(i.get(S).focusSelection(),!0)};function Y({ref:i,...e}){const{icon:n,id:t,className:s,extend:a,...r}=e,d=`univerjs-icon univerjs-icon-${t} ${s||""}`.trim(),_=p.useRef(`_${pe()}`);return J(n,`${t}`,{defIds:n.defIds,idSuffix:_.current},{ref:i,className:d,...r},a)}function J(i,e,n,t,s){return p.createElement(i.tag,{key:e,...he(i,n,s),...t},(ue(i,n).children||[]).map((a,r)=>J(a,`${e}-${i.tag}-${r}`,n,void 0,s)))}function he(i,e,n){const t={...i.attrs};n!=null&&n.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=n.colorChannel1),i.tag==="mask"&&t.id&&(t.id=t.id+e.idSuffix),Object.entries(t).forEach(([a,r])=>{a==="mask"&&typeof r=="string"&&(t[a]=r.replace(/url\(#(.*)\)/,`url(#$1${e.idSuffix})`))});const{defIds:s}=e;return!s||s.length===0||(i.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+e.idSuffix),Object.entries(t).forEach(([a,r])=>{typeof r=="string"&&(t[a]=r.replace(/url\(#(.*)\)/,`url(#$1${e.idSuffix})`))})),t}function ue(i,e){var t;const{defIds:n}=e;return!n||n.length===0?i:i.tag==="defs"&&((t=i.children)!=null&&t.length)?{...i,children:i.children.map(s=>typeof s.attrs.id=="string"&&n&&n.includes(s.attrs.id)?{...s,attrs:{...s.attrs,id:s.attrs.id+e.idSuffix}}:s)}:i}function pe(){return Math.random().toString(36).substring(2,8)}Y.displayName="UniverIcon";const fe={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"}}]},Q=p.forwardRef(function(e,n){return p.createElement(Y,Object.assign({},e,{id:"search-icon",ref:n,icon:fe}))});Q.displayName="SearchIcon";function X(i){const{findCompleted:e,localeService:n,matchesCount:t,matchesPosition:s,initialFindString:a,findReplaceService:r,onChange:d,..._}=i,[v,C]=p.useState(a),D=e&&t===0?n.t("find-replace.dialog.no-result"):t===0?" ":void 0;function y(M){s===t&&M===1?r.moveToNextMatch():s===1&&M===t||M<s?r.moveToPreviousMatch():r.moveToNextMatch()}return h.jsx("div",{className:"univer-relative univer-flex univer-items-center univer-gap-2",onDrag:M=>M.stopPropagation(),children:h.jsx(f.Input,{"data-u-comp":"search-input",autoFocus:!0,placeholder:n.t("find-replace.dialog.find-placeholder"),value:v,onChange:M=>{C(M),d==null||d(M)},slot:h.jsx(f.Pager,{loop:!0,text:D,value:s,total:t,onChange:y}),..._})})}function ee(i,e){const n=p.useCallback(()=>{var s;(s=document.querySelector(".univer-find-input input"))==null||s.focus()},[]),t=p.useCallback(()=>{const s=document.querySelectorAll("[data-u-comp=find-replace-dialog] [data-u-comp=search-input]");return Array.from(s).some(a=>a===document.activeElement)},[]);return p.useImperativeHandle(e,()=>({focus:n,selectHasFocus:t})),p.useEffect(()=>{const s=i.focusSignal$.subscribe(()=>n());return()=>s.unsubscribe()},[i,n]),{focus:n,selectHasFocus:t}}const _e=p.forwardRef(function(e,n){const t=l.useDependency(o.LocaleService),s=l.useDependency(S),a=l.useDependency(o.ICommandService),r=l.useObservable(s.state$,void 0,!0),{findCompleted:d,findString:_,matchesCount:v,matchesPosition:C}=r,F=p.useCallback(()=>{a.executeCommand(L.id)},[a]),D=l.useDebounceFn(y=>s.changeFindString(y),500);return ee(s,n),h.jsxs(h.Fragment,{children:[h.jsx(X,{findCompleted:d,matchesCount:v,matchesPosition:C,findReplaceService:s,localeService:t,initialFindString:_,onChange:D}),h.jsx("div",{className:"univer-mt-4 univer-text-center",children:h.jsx("a",{className:"hover:univer-text-primary-500/80 univer-cursor-pointer univer-text-sm univer-text-primary-500 univer-transition-colors",onClick:F,children:t.t("find-replace.dialog.advanced-finding")})})]})}),ge=p.forwardRef(function(e,n){const t=l.useDependency(S),s=l.useDependency(o.LocaleService),a=l.useDependency(o.ICommandService),r=l.useDependency(l.IMessageService),d=l.useObservable(t.currentMatch$,void 0,!0),_=l.useObservable(t.replaceables$,void 0,!0),v=l.useObservable(t.state$,void 0,!0),{matchesCount:C,matchesPosition:F,findString:D,inputtingFindString:y,replaceString:M,caseSensitive:ke,matchesTheWholeCell:Be,findDirection:We,findScope:je,findBy:Ge,findCompleted:G}=v,Ve=y.length===0,Ke=C===0||!(d!=null&&d.replaceable),He=_.length===0,qe=p.useCallback(g=>t.changeInputtingFindString(g),[t]),Ze=p.useCallback(g=>t.changeReplaceString(g),[t]),{focus:ze}=ee(t,n),Ye=p.useCallback(()=>{D===y?t.moveToNextMatch():(t.changeFindString(y),t.find())},[D,y,t]),Je=p.useCallback(()=>a.executeCommand(U.id),[a]),Qe=p.useCallback(async()=>{await a.executeCommand(x.id),ze()},[a]),Xe=p.useCallback(g=>{t.changeFindDirection(g)},[t]),et=p.useCallback(g=>{t.changeFindScope(g)},[t]),tt=p.useCallback(g=>{t.changeFindBy(g)},[t]),it=ve(s),nt=Se(s),st=Ce(s);return p.useEffect(()=>{G&&C===0&&r.show({content:s.t("find-replace.dialog.no-match"),type:f.MessageType.Warning,duration:5e3})},[G,C,r,s]),h.jsxs("div",{children:[h.jsx(f.FormLayout,{label:s.t("find-replace.dialog.find"),children:h.jsx(X,{findCompleted:G,className:"univer-find-input",matchesCount:C,matchesPosition:F,findReplaceService:t,localeService:s,initialFindString:y,onChange:qe})}),h.jsx(f.FormLayout,{label:s.t("find-replace.dialog.replace"),children:h.jsx(f.Input,{placeholder:s.t("find-replace.dialog.replace-placeholder"),value:M,onChange:g=>Ze(g)})}),h.jsx(f.FormLayout,{label:s.t("find-replace.dialog.find-direction.title"),children:h.jsx(f.Select,{value:We,options:nt,onChange:Xe})}),h.jsx(f.FormDualColumnLayout,{children:h.jsxs(h.Fragment,{children:[h.jsx(f.FormLayout,{label:s.t("find-replace.dialog.find-scope.title"),children:h.jsx(f.Select,{value:je,options:it,onChange:et})}),h.jsx(f.FormLayout,{label:s.t("find-replace.dialog.find-by.title"),children:h.jsx(f.Select,{value:Ge,options:st,onChange:tt})})]})}),h.jsx(f.FormDualColumnLayout,{children:h.jsxs(h.Fragment,{children:[h.jsx(f.FormLayout,{children:h.jsx(f.Checkbox,{checked:ke,onChange:g=>{t.changeCaseSensitive(g)},children:s.t("find-replace.dialog.case-sensitive")})}),h.jsx(f.FormLayout,{children:h.jsx(f.Checkbox,{checked:Be,onChange:g=>{t.changeMatchesTheWholeCell(g)},children:s.t("find-replace.dialog.match-the-whole-cell")})})]})}),h.jsxs("div",{className:"univer-mt-6 univer-flex univer-justify-between",children:[h.jsx(f.Button,{variant:"primary",onClick:Ye,disabled:Ve,children:s.t("find-replace.dialog.find")}),h.jsxs("span",{className:"univer-inline-flex univer-gap-2",children:[h.jsx(f.Button,{disabled:Ke,onClick:Je,children:s.t("find-replace.dialog.replace")}),h.jsx(f.Button,{disabled:He,onClick:Qe,children:s.t("find-replace.dialog.replace-all")})]})]})]})});function me(){const i=l.useDependency(S),e=l.useDependency(l.ILayoutService),n=l.useDependency(o.IContextService),t=l.useObservable(i.state$,void 0,!0),s=p.useRef(null);p.useEffect(()=>{let _;return s.current&&(_=e.registerContainerElement(s.current)),()=>_==null?void 0:_.dispose()},[e]);const a=p.useRef(null),r=p.useCallback(_=>n.setContextValue(K,_),[n]),d=p.useCallback(_=>n.setContextValue(V,_),[n]);return p.useEffect(()=>{var v;const _=m.fromEvent(document,"focusin").subscribe(C=>{var F;C.target&&((F=s.current)!=null&&F.contains(C.target))?r(!0):r(!1),!a.current||!a.current.selectHasFocus()?d(!1):d(!0)});return(v=a.current)==null||v.focus(),r(!0),d(!0),()=>{_.unsubscribe(),r(!1)}},[r,d]),h.jsx("div",{ref:s,"data-u-comp":"find-replace-dialog",children:t.replaceRevealed?h.jsx(ge,{ref:a}):h.jsx(_e,{ref:a})})}function ve(i){const e=i.getCurrentLocale();return p.useMemo(()=>[{label:i.t("find-replace.dialog.find-scope.current-sheet"),value:N.SUBUNIT},{label:i.t("find-replace.dialog.find-scope.workbook"),value:N.UNIT}],[e])}function Se(i){const e=i.getCurrentLocale();return p.useMemo(()=>[{label:i.t("find-replace.dialog.find-direction.row"),value:E.ROW},{label:i.t("find-replace.dialog.find-direction.column"),value:E.COLUMN}],[e])}function Ce(i){const e=i.getCurrentLocale();return p.useMemo(()=>[{label:i.t("find-replace.dialog.find-by.value"),value:O.VALUE},{label:i.t("find-replace.dialog.find-by.formula"),value:O.FORMULA}],[e])}function R(i){return i.getContextValue(K)}function Me(i){return i.getContextValue(H)}function te(i){return i.getContextValue(V)}const T="7_find-replace-shortcuts";function B(i){return i.getContextValue(o.FOCUSING_SHEET)}function W(i){return!i.getContextValue(o.EDITOR_ACTIVATED)}const be={id:I.id,description:"find-replace.shortcut.open-find-dialog",binding:l.KeyCode.F|l.MetaKeys.CTRL_COMMAND,group:T,preconditions(i){return!R(i)&&B(i)&&W(i)}},ye={id:I.id,description:"find-replace.shortcut.open-find-dialog",binding:l.KeyCode.F|l.MetaKeys.CTRL_COMMAND,mac:l.KeyCode.F|l.MetaKeys.MAC_CTRL,preconditions(i){return!R(i)&&B(i)&&W(i)}},Fe={id:L.id,description:"find-replace.shortcut.open-replace-dialog",binding:l.KeyCode.H|l.MetaKeys.CTRL_COMMAND,mac:l.KeyCode.H|l.MetaKeys.MAC_CTRL,group:T,preconditions(i){return B(i)&&W(i)&&(!R(i)||!Me(i))}},Ie={id:w.id,description:"find-replace.shortcut.go-to-next-match",binding:l.KeyCode.ENTER,group:T,priority:1e3,preconditions(i){return te(i)&&R(i)}},Re={id:k.id,description:"find-replace.shortcut.go-to-previous-match",binding:l.KeyCode.ENTER|l.MetaKeys.SHIFT,group:T,priority:1e3,preconditions(i){return te(i)&&R(i)}},De={id:z.id,description:"find-replace.shortcut.focus-selection",binding:l.KeyCode.ESC,group:T,priority:1e3,preconditions(i){return R(i)}};function Te(i){const e=i.get(o.IContextService);return{id:I.id,icon:"SearchIcon",tooltip:"find-replace.toolbar",type:l.MenuItemType.BUTTON,hidden$:l.getMenuHiddenObservable(i,o.UniverInstanceType.UNIVER_SHEET),disabled$:m.combineLatest([e.subscribeContextValue$(o.EDITOR_ACTIVATED),e.subscribeContextValue$(o.FOCUSING_SHEET)]).pipe(m.map(([n,t])=>n||!t))}}const Pe={[l.RibbonDataGroup.ORGANIZATION]:{[I.id]:{order:2,menuItemFactory:Te}}};var Ee=Object.getOwnPropertyDescriptor,Oe=(i,e,n,t)=>{for(var s=t>1?void 0:t?Ee(e,n):e,a=i.length-1,r;a>=0;a--)(r=i[a])&&(s=r(s)||s);return s},b=(i,e)=>(n,t)=>e(n,t,i);const ie="DESKTOP_FIND_REPLACE_DIALOG",ne=350,Ne=20,$e=64;c.FindReplaceController=class extends o.RxDisposable{constructor(n,t,s,a,r,d,_,v,C){super();u(this,"_closingListenerDisposable");this._univerInstanceService=n,this._menuManagerService=t,this._shortcutService=s,this._commandService=a,this._findReplaceService=r,this._dialogService=d,this._layoutService=_,this._localeService=v,this._componentManager=C,this._initCommands(),this._initUI(),this._initShortcuts()}dispose(){var n;super.dispose(),(n=this._closingListenerDisposable)==null||n.dispose(),this._closingListenerDisposable=null}_initCommands(){[I,L,w,k,x,U,z].forEach(n=>{this.disposeWithMe(this._commandService.registerCommand(n))})}_initShortcuts(){[Fe,be,ye,Re,Ie,De].forEach(n=>this.disposeWithMe(this._shortcutService.registerShortcut(n)))}_initUI(){[["FindReplaceDialog",me],["SearchIcon",Q]].forEach(([n,t])=>{this.disposeWithMe(this._componentManager.register(n,t))}),this._menuManagerService.mergeMenu(Pe),this._findReplaceService.stateUpdates$.pipe(m.takeUntil(this.dispose$)).subscribe(n=>{n.revealed===!0&&this._openPanel()})}_openPanel(){this._dialogService.open({id:ie,draggable:!0,width:ne,title:{title:this._localeService.t("find-replace.dialog.title")},children:{label:"FindReplaceDialog"},destroyOnClose:!0,mask:!1,maskClosable:!1,defaultPosition:Le(),preservePositionOnDestroy:!0,onClose:()=>this.closePanel()}),this._closingListenerDisposable=o.toDisposable(this._univerInstanceService.focused$.pipe(m.takeUntil(this.dispose$)).subscribe(n=>{(!n||!this._univerInstanceService.getUniverSheetInstance(n))&&this.closePanel()}))}closePanel(){this._closingListenerDisposable&&(this._closingListenerDisposable.dispose(),this._closingListenerDisposable=null,this._dialogService.close(ie),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus()))}},c.FindReplaceController=Oe([b(0,o.IUniverInstanceService),b(1,l.IMenuManagerService),b(2,l.IShortcutService),b(3,o.ICommandService),b(4,S),b(5,l.IDialogService),b(6,l.ILayoutService),b(7,o.Inject(o.LocaleService)),b(8,o.Inject(l.ComponentManager))],c.FindReplaceController);function Le(){const{innerWidth:i}=window;return{x:i-ne-Ne,y:$e}}const Ae="find-replace.config",se={};var Ue=Object.getOwnPropertyDescriptor,xe=(i,e,n,t)=>{for(var s=t>1?void 0:t?Ue(e,n):e,a=i.length-1,r;a>=0;a--)(r=i[a])&&(s=r(s)||s);return s},ae=(i,e)=>(n,t)=>e(n,t,i);const we="UNIVER_FIND_REPLACE_PLUGIN";c.UniverFindReplacePlugin=(j=class extends o.Plugin{constructor(e=se,n,t){super(),this._config=e,this._injector=n,this._configService=t;const{...s}=o.merge({},se,this._config);this._configService.setConfig(Ae,s)}onStarting(){[[c.FindReplaceController],[S,{useClass:A}]].forEach(e=>this._injector.add(e))}onRendered(){this._injector.get(c.FindReplaceController)}},u(j,"pluginName",we),j),c.UniverFindReplacePlugin=xe([ae(1,o.Inject(o.Injector)),ae(2,o.IConfigService)],c.UniverFindReplacePlugin),c.FindBy=O,c.FindDirection=E,c.FindModel=ce,c.FindReplaceState=Z,c.FindScope=N,c.GoToNextMatchOperation=w,c.GoToPreviousMatchOperation=k,c.IFindReplaceService=S,c.OpenFindDialogOperation=I,c.OpenReplaceDialogOperation=L,c.ReplaceAllMatchesCommand=x,c.ReplaceCurrentMatchCommand=U,c.createInitFindReplaceState=$,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/find-replace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0-insiders.20251227-b250a8d",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -54,11 +54,11 @@
|
|
|
54
54
|
"rxjs": ">=7.0.0"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@univerjs/icons": "^1.0
|
|
58
|
-
"@univerjs/core": "0.
|
|
59
|
-
"@univerjs/design": "0.
|
|
60
|
-
"@univerjs/engine-render": "0.
|
|
61
|
-
"@univerjs/ui": "0.
|
|
57
|
+
"@univerjs/icons": "^1.1.0",
|
|
58
|
+
"@univerjs/core": "0.14.0-insiders.20251227-b250a8d",
|
|
59
|
+
"@univerjs/design": "0.14.0-insiders.20251227-b250a8d",
|
|
60
|
+
"@univerjs/engine-render": "0.14.0-insiders.20251227-b250a8d",
|
|
61
|
+
"@univerjs/ui": "0.14.0-insiders.20251227-b250a8d"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"postcss": "^8.5.6",
|
|
@@ -66,9 +66,9 @@
|
|
|
66
66
|
"rxjs": "^7.8.2",
|
|
67
67
|
"tailwindcss": "3.4.18",
|
|
68
68
|
"typescript": "^5.9.3",
|
|
69
|
-
"vite": "^7.
|
|
70
|
-
"vitest": "^4.0.
|
|
71
|
-
"@univerjs-infra/shared": "0.
|
|
69
|
+
"vite": "^7.3.0",
|
|
70
|
+
"vitest": "^4.0.16",
|
|
71
|
+
"@univerjs-infra/shared": "0.14.0"
|
|
72
72
|
},
|
|
73
73
|
"scripts": {
|
|
74
74
|
"test": "vitest run",
|
package/LICENSE
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|