@univerjs/find-replace 0.6.0-nightly.202502151605 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +176 -0
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +122 -123
- package/lib/umd/index.js +1 -1
- package/package.json +5 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
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
|
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var Fe=Object.defineProperty;var De=(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)=>De(t,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),l=require("@univerjs/ui"),_=require("rxjs"),f=require("@univerjs/design"),xe=require("@univerjs/engine-render"),d=require("react/jsx-runtime"),h=require("react"),Te="find-replace.config",V={};var C=function(){return C=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++){e=arguments[n];for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=e[s])}return t},C.apply(this,arguments)},Pe=function(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,i=Object.getOwnPropertySymbols(t);s<i.length;s++)e.indexOf(i[s])<0&&Object.prototype.propertyIsEnumerable.call(t,i[s])&&(n[i[s]]=t[i[s]]);return n},q=h.forwardRef(function(t,e){var n=t.icon,i=t.id,s=t.className,r=t.extend,a=Pe(t,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(i," ").concat(s||"").trim(),p=h.useRef("_".concat(Ne()));return z(n,"".concat(i),{defIds:n.defIds,idSuffix:p.current},C({ref:e,className:c},a),r)});function z(t,e,n,i,s){return h.createElement(t.tag,C(C({key:e},Oe(t,n,s)),i),(Ee(t,n).children||[]).map(function(r,a){return z(r,"".concat(e,"-").concat(t.tag,"-").concat(a),n,void 0,s)}))}function Oe(t,e,n){var i=C({},t.attrs);n!=null&&n.colorChannel1&&i.fill==="colorChannel1"&&(i.fill=n.colorChannel1);var s=e.defIds;return!s||s.length===0||(t.tag==="use"&&i["xlink:href"]&&(i["xlink:href"]=i["xlink:href"]+e.idSuffix),Object.entries(i).forEach(function(r){var a=r[0],c=r[1];typeof c=="string"&&(i[a]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),i}function Ee(t,e){var n,i=e.defIds;return!i||i.length===0?t:t.tag==="defs"&&(!((n=t.children)===null||n===void 0)&&n.length)?C(C({},t),{children:t.children.map(function(s){return typeof s.attrs.id=="string"&&i&&i.indexOf(s.attrs.id)>-1?C(C({},s),{attrs:C(C({},s.attrs),{id:s.attrs.id+e.idSuffix})}):s})}):t}function Ne(){return Math.random().toString(36).substring(2,8)}q.displayName="UniverIcon";var Le={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_217_40",style:{maskType:"alpha"},width:17,height:17,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#D9D9D9",d:"M0.9 0.09H16.9V16.09H0.9z"}}]},{tag:"g",attrs:{mask:"url(#mask0_217_40)"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.39551 7.37266C2.39551 4.18105 4.98281 1.59375 8.17441 1.59375C11.366 1.59375 13.9533 4.18105 13.9533 7.37266C13.9533 8.72342 13.4898 9.96603 12.7133 10.95L15.1964 13.4331C15.4619 13.6986 15.4619 14.1291 15.1964 14.3946C14.9309 14.6601 14.5004 14.6601 14.2349 14.3946L11.7518 11.9115C10.7678 12.6881 9.52525 13.1516 8.17441 13.1516C4.98281 13.1516 2.39551 10.5642 2.39551 7.37266ZM8.17441 2.95349C5.73378 2.95349 3.75525 4.93202 3.75525 7.37266C3.75525 9.81333 5.73378 11.7918 8.17441 11.7918C10.6151 11.7918 12.5936 9.81333 12.5936 7.37266C12.5936 4.93202 10.6151 2.95349 8.17441 2.95349Z",fillRule:"evenodd",clipRule:"evenodd"}}]}]},Y=h.forwardRef(function(t,e){return h.createElement(q,Object.assign({},t,{id:"search-single-16",ref:e,icon:Le}))});Y.displayName="SearchSingle16";const Z="FIND_REPLACE_INPUT_FOCUS",J="FIND_REPLACE_DIALOG_FOCUS",Q="FIND_REPLACE_REPLACE_REVEALED";var $e=Object.defineProperty,je=Object.getOwnPropertyDescriptor,X=(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=(i?a(e,n,s):a(s))||s);return i&&s&&$e(e,n,s),s},j=(t,e)=>(n,i)=>e(n,i,t);class Ae extends o.Disposable{}const R=o.createIdentifier("find-replace.service");function we(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){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.disposeWithMe(this._state.stateUpdates$.pipe(_.throttleTime(200,void 0,{leading:!0,trailing:!0})).subscribe(async r=>{const a=this._state.state;we(r)&&(a.findString!==""&&!a.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({...O(),revealed:!1})}async start(){if(!this._state.findString)return{results:[]};const n=await this._startSearching();return this._state.changeState({findCompleted:!0}),n}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(c=>c.replaceable))):(this._state.changeState({matchesCount:0,matchesPosition:0}),this.replaceables$.next([]))});n.forEach(r=>i.add(o.toDisposable(r.activelyChangingMatch$.subscribe(a=>{const c=this._matches.findIndex(p=>p===a);this._state.changeState({matchesPosition:c+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(c=>c===this._matchingModel);for(let c=(r-1+s)%s;c!==r;){const p=this._findModels[c],S=p.moveToPreviousMatch({ignoreSelection:!0});if(S)return this._matchingModel=p,this._markMatch(S),S;c=(c-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(c=>c.unitId===s);if(r!==-1){this._matchingModel=n[r];const c=this._matchingModel.moveToNextMatch({stayIfOnMatch:!0,noFocus:i});if(c)return this._markMatch(c),r}return this._moveToNextUnitMatch(r),0}};exports.FindReplaceModel=X([j(2,o.IUniverInstanceService)],exports.FindReplaceModel);var D=(t=>(t.ROW="row",t.COLUMN="column",t))(D||{}),x=(t=>(t.VALUE="value",t.FORMULA="formula",t))(x||{}),T=(t=>(t.SUBUNIT="subunit",t.UNIT="unit",t))(T||{});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 ee{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 ee);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)}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(Q,e)}_toggleDisplayRawFormula(e){this._contextService.setContextValue(xe.RENDER_RAW_FORMULA_KEY,e)}};A=X([j(0,o.Inject(o.Injector)),j(1,o.IContextService)],A);const w={id:"ui.command.replace-current-match",type:o.CommandType.COMMAND,handler:t=>t.get(R).replace()},Ue="CONFIRM_REPLACE_ALL",U={id:"ui.command.replace-all-matches",type:o.CommandType.COMMAND,handler:async t=>{const e=t.get(l.IConfirmService),n=t.get(o.LocaleService),i=t.get(l.IMessageService);if(!await e.confirm({id:Ue,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(R).replaceAll(),{success:a,failure:c}=r;return c>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}`,`${c}`)}),!1):(i.show({type:f.MessageType.Success,content:n.t("find-replace.replace.all-success",`${a}`)}),!0)}},y={id:"ui.operation.open-find-dialog",type:o.CommandType.OPERATION,handler:t=>{const e=t.get(R);return e.revealed?e.focusFindInput():e.start(),!0}},E={id:"ui.operation.open-replace-dialog",type:o.CommandType.OPERATION,handler:t=>{const e=t.get(R);return e.revealed?e.replaceRevealed?e.focusFindInput():e.revealReplace():e.start(!0),!0}},B={type:o.CommandType.OPERATION,id:"ui.operation.go-to-next-match",handler:t=>(t.get(R).moveToNextMatch(),!0)},k={type:o.CommandType.OPERATION,id:"ui.operation.go-to-previous-match",handler:t=>(t.get(R).moveToPreviousMatch(),!0)},Be="univer-find-replace-dialog-container",ke="univer-find-replace-expand-container",We="univer-button-text",Ge="univer-find-replace-buttons-group",Ve="univer-find-replace-buttons-group-right",P={findReplaceDialogContainer:Be,findReplaceExpandContainer:ke,buttonText:We,findReplaceButtonsGroup:Ge,findReplaceButtonsGroupRight:Ve};function te(t){const{findCompleted:e,localeService:n,matchesCount:i,matchesPosition:s,findString:r,findReplaceService:a,onChange:c,...p}=t,v=e&&i===0?n.t("find-replace.dialog.no-result"):i===0?" ":void 0;return d.jsx(f.InputWithSlot,{autoFocus:!0,placeholder:n.t("find-replace.dialog.find-placeholder"),slot:d.jsx(f.Pager,{loop:!0,text:v,value:s,total:i,onChange:m=>{s===i&&m===1?a.moveToNextMatch():s===1&&m===i||m<s?a.moveToPreviousMatch():a.moveToNextMatch()}}),value:r,onChange:m=>c==null?void 0:c(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(".univer-find-replace-dialog-container .univer-select-selection-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 He=h.forwardRef(function(e,n){const i=l.useDependency(o.LocaleService),s=l.useDependency(R),r=l.useDependency(o.ICommandService),a=l.useObservable(s.state$,void 0,!0),{findCompleted:c,findString:p,matchesCount:S,matchesPosition:v}=a,m=h.useCallback(()=>{r.executeCommand(E.id)},[r]),F=h.useCallback(M=>s.changeFindString(M),[s]);return ie(s,n),d.jsxs(d.Fragment,{children:[d.jsx(te,{findCompleted:c,className:"univer-find-input",matchesCount:S,matchesPosition:v,findReplaceService:s,localeService:i,findString:p,onChange:F}),d.jsx("div",{className:P.findReplaceExpandContainer,children:d.jsx(f.Button,{type:"text",size:"small",onClick:m,children:i.t("find-replace.dialog.advanced-finding")})})]})}),Ke=h.forwardRef(function(e,n){const i=l.useDependency(R),s=l.useDependency(o.LocaleService),r=l.useDependency(o.ICommandService),a=l.useDependency(l.IMessageService),c=l.useObservable(i.currentMatch$,void 0,!0),p=l.useObservable(i.replaceables$,void 0,!0),S=l.useObservable(i.state$,void 0,!0),{matchesCount:v,matchesPosition:m,findString:F,inputtingFindString:M,replaceString:re,caseSensitive:ae,matchesTheWholeCell:oe,findDirection:ce,findScope:le,findBy:de,findCompleted:L}=S,ue=M.length===0,he=v===0||!(c!=null&&c.replaceable),pe=p.length===0,fe=h.useCallback(g=>i.changeInputtingFindString(g),[i]),ge=h.useCallback(g=>i.changeReplaceString(g),[i]),{focus:_e}=ie(i,n),me=h.useCallback(()=>{F===M?i.moveToNextMatch():(i.changeFindString(M),i.find())},[F,M,i]),Se=h.useCallback(()=>r.executeCommand(w.id),[r]),ve=h.useCallback(async()=>{await r.executeCommand(U.id),_e()},[r]),Ce=h.useCallback(g=>{i.changeFindDirection(g)},[i]),Re=h.useCallback(g=>{i.changeFindScope(g)},[i]),be=h.useCallback(g=>{i.changeFindBy(g)},[i]),Me=ze(s),ye=Ye(s),Ie=Ze(s);return h.useEffect(()=>{L&&v===0&&a.show({content:s.t("find-replace.dialog.no-match"),type:f.MessageType.Warning,duration:5e3})},[L,v,a,s]),d.jsxs(d.Fragment,{children:[d.jsx(f.FormLayout,{label:s.t("find-replace.dialog.find"),children:d.jsx(te,{findCompleted:L,className:"univer-find-input",matchesCount:v,matchesPosition:m,findReplaceService:i,localeService:s,findString:M,onChange:fe})}),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:re,onChange:g=>ge(g)})}),d.jsx(f.FormLayout,{label:s.t("find-replace.dialog.find-direction.title"),children:d.jsx(f.Select,{value:ce,options:ye,onChange:Ce})}),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:le,options:Me,onChange:Re})}),d.jsx(f.FormLayout,{label:s.t("find-replace.dialog.find-by.title"),children:d.jsx(f.Select,{value:de,options:Ie,onChange:be})})]})}),d.jsx(f.FormDualColumnLayout,{children:d.jsxs(d.Fragment,{children:[d.jsx(f.FormLayout,{children:d.jsx(f.Checkbox,{checked:ae,onChange:g=>{i.changeCaseSensitive(g)},children:s.t("find-replace.dialog.case-sensitive")})}),d.jsx(f.FormLayout,{children:d.jsx(f.Checkbox,{checked:oe,onChange:g=>{i.changeMatchesTheWholeCell(g)},children:s.t("find-replace.dialog.match-the-whole-cell")})})]})}),d.jsxs("div",{className:P.findReplaceButtonsGroup,children:[d.jsx(f.Button,{type:"primary",onClick:me,disabled:ue,children:s.t("find-replace.dialog.find")}),d.jsxs("span",{className:P.findReplaceButtonsGroupRight,children:[d.jsx(f.Button,{disabled:he,onClick:Se,children:s.t("find-replace.dialog.replace")}),d.jsx(f.Button,{disabled:pe,onClick:ve,children:s.t("find-replace.dialog.replace-all")})]})]})]})});function qe(){const t=l.useDependency(R),e=l.useDependency(l.ILayoutService),n=l.useDependency(o.IContextService),i=l.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(J,p),[n]),c=h.useCallback(p=>n.setContextValue(Z,p),[n]);return h.useEffect(()=>{var S;const p=_.fromEvent(document,"focusin").subscribe(v=>{var m;v.target&&((m=s.current)!=null&&m.contains(v.target))?a(!0):a(!1),!r.current||!r.current.selectHasFocus()?c(!0):c(!1)});return(S=r.current)==null||S.focus(),a(!0),c(!0),()=>{p.unsubscribe(),a(!1)}},[a,c]),d.jsx("div",{className:P.findReplaceDialogContainer,ref:s,children:i.replaceRevealed?d.jsx(Ke,{ref:r}):d.jsx(He,{ref:r})})}function ze(t){const e=t.getCurrentLocale();return h.useMemo(()=>[{label:t.t("find-replace.dialog.find-scope.current-sheet"),value:T.SUBUNIT},{label:t.t("find-replace.dialog.find-scope.workbook"),value:T.UNIT}],[e])}function Ye(t){const e=t.getCurrentLocale();return h.useMemo(()=>[{label:t.t("find-replace.dialog.find-direction.row"),value:D.ROW},{label:t.t("find-replace.dialog.find-direction.column"),value:D.COLUMN}],[e])}function Ze(t){const e=t.getCurrentLocale();return h.useMemo(()=>[{label:t.t("find-replace.dialog.find-by.value"),value:x.VALUE},{label:t.t("find-replace.dialog.find-by.formula"),value:x.FORMULA}],[e])}function I(t){return t.getContextValue(J)}function Je(t){return t.getContextValue(Q)}function ne(t){return t.getContextValue(Z)}const N="7_find-replace-shortcuts";function W(t){return t.getContextValue(o.FOCUSING_SHEET)}function G(t){return!t.getContextValue(o.EDITOR_ACTIVATED)}const Qe={id:y.id,description:"find-replace.shortcut.open-find-dialog",binding:l.KeyCode.F|l.MetaKeys.CTRL_COMMAND,group:N,preconditions(t){return!I(t)&&W(t)&&G(t)}},Xe={id:y.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(t){return!I(t)&&W(t)&&G(t)}},et={id:E.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:N,preconditions(t){return W(t)&&G(t)&&(!I(t)||!Je(t))}},tt={id:B.id,description:"find-replace.shortcut.go-to-next-match",binding:l.KeyCode.ENTER,group:N,priority:1e3,preconditions(t){return ne(t)&&I(t)}},it={id:k.id,description:"find-replace.shortcut.go-to-previous-match",binding:l.KeyCode.ENTER|l.MetaKeys.SHIFT,group:N,priority:1e3,preconditions(t){return ne(t)&&I(t)}};function nt(t){const e=t.get(o.IContextService);return{id:y.id,icon:"SearchIcon",tooltip:"find-replace.toolbar",type:l.MenuItemType.BUTTON,hidden$:l.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 st={[l.RibbonStartGroup.OTHERS]:{[y.id]:{order:2,menuItemFactory:nt}}};var rt=Object.defineProperty,at=Object.getOwnPropertyDescriptor,ot=(t,e,n,i)=>{for(var s=i>1?void 0:i?at(e,n):e,r=t.length-1,a;r>=0;r--)(a=t[r])&&(s=(i?a(e,n,s):a(s))||s);return i&&s&&rt(e,n,s),s},b=(t,e)=>(n,i)=>e(n,i,t);const H="DESKTOP_FIND_REPLACE_DIALOG",se=350,ct=20,lt=-90;exports.FindReplaceController=class extends o.RxDisposable{constructor(n,i,s,r,a,c,p,S,v,m){super();u(this,"_closingListenerDisposable");this._univerInstanceService=n,this._menuManagerService=i,this._shortcutService=s,this._commandService=r,this._findReplaceService=a,this._dialogService=c,this._layoutService=p,this._localeService=S,this._componentManager=v,this._injector=m,this._initCommands(),this._initUI(),this._initShortcuts()}dispose(){var n;super.dispose(),(n=this._closingListenerDisposable)==null||n.dispose(),this._closingListenerDisposable=null}_initCommands(){[y,E,B,k,U,w].forEach(n=>{this.disposeWithMe(this._commandService.registerCommand(n))})}_initShortcuts(){[et,Qe,Xe,it,tt].forEach(n=>this.disposeWithMe(this._shortcutService.registerShortcut(n)))}_initUI(){this.disposeWithMe(this._componentManager.register("FindReplaceDialog",qe)),this.disposeWithMe(this._componentManager.register("SearchIcon",Y)),this._menuManagerService.mergeMenu(st),this._findReplaceService.stateUpdates$.pipe(_.takeUntil(this.dispose$)).subscribe(n=>{n.revealed===!0&&this._openPanel()})}_openPanel(){this._dialogService.open({id:H,draggable:!0,width:se,title:{title:this._localeService.t("find-replace.dialog.title")},children:{label:"FindReplaceDialog"},destroyOnClose:!0,defaultPosition:dt(),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(H),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus()))}};exports.FindReplaceController=ot([b(0,o.IUniverInstanceService),b(1,l.IMenuManagerService),b(2,l.IShortcutService),b(3,o.ICommandService),b(4,R),b(5,l.IDialogService),b(6,l.ILayoutService),b(7,o.Inject(o.LocaleService)),b(8,o.Inject(l.ComponentManager)),b(9,o.Inject(o.Injector))],exports.FindReplaceController);function dt(){const{innerWidth:t}=window;return{x:(t-se)/2-ct,y:lt}}var ut=Object.defineProperty,ht=Object.getOwnPropertyDescriptor,pt=(t,e,n,i)=>{for(var s=i>1?void 0:i?ht(e,n):e,r=t.length-1,a;r>=0;r--)(a=t[r])&&(s=(i?a(e,n,s):a(s))||s);return i&&s&&ut(e,n,s),s},K=(t,e)=>(n,i)=>e(n,i,t);const ft="UNIVER_FIND_REPLACE_PLUGIN";var $;exports.UniverFindReplacePlugin=($=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(Te,s)}onStarting(){[[exports.FindReplaceController],[R,{useClass:A}]].forEach(e=>this._injector.add(e))}onRendered(){this._injector.get(exports.FindReplaceController)}},u($,"pluginName",ft),$);exports.UniverFindReplacePlugin=pt([K(1,o.Inject(o.Injector)),K(2,o.IConfigService)],exports.UniverFindReplacePlugin);exports.FindBy=x;exports.FindDirection=D;exports.FindModel=Ae;exports.FindReplaceState=ee;exports.FindScope=T;exports.GoToNextMatchOperation=B;exports.GoToPreviousMatchOperation=k;exports.IFindReplaceService=R;exports.OpenFindDialogOperation=y;exports.OpenReplaceDialogOperation=E;exports.ReplaceAllMatchesCommand=U;exports.ReplaceCurrentMatchCommand=w;exports.createInitFindReplaceState=O;
|
|
1
|
+
"use strict";var Fe=Object.defineProperty;var De=(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)=>De(t,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),l=require("@univerjs/ui"),_=require("rxjs"),f=require("@univerjs/design"),xe=require("@univerjs/engine-render"),d=require("react/jsx-runtime"),h=require("react"),Te="find-replace.config",V={};var C=function(){return C=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++){e=arguments[n];for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=e[s])}return t},C.apply(this,arguments)},Oe=function(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,i=Object.getOwnPropertySymbols(t);s<i.length;s++)e.indexOf(i[s])<0&&Object.prototype.propertyIsEnumerable.call(t,i[s])&&(n[i[s]]=t[i[s]]);return n},q=h.forwardRef(function(t,e){var n=t.icon,i=t.id,s=t.className,r=t.extend,a=Oe(t,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(i," ").concat(s||"").trim(),p=h.useRef("_".concat(Ne()));return z(n,"".concat(i),{defIds:n.defIds,idSuffix:p.current},C({ref:e,className:c},a),r)});function z(t,e,n,i,s){return h.createElement(t.tag,C(C({key:e},Pe(t,n,s)),i),(Ee(t,n).children||[]).map(function(r,a){return z(r,"".concat(e,"-").concat(t.tag,"-").concat(a),n,void 0,s)}))}function Pe(t,e,n){var i=C({},t.attrs);n!=null&&n.colorChannel1&&i.fill==="colorChannel1"&&(i.fill=n.colorChannel1);var s=e.defIds;return!s||s.length===0||(t.tag==="use"&&i["xlink:href"]&&(i["xlink:href"]=i["xlink:href"]+e.idSuffix),Object.entries(i).forEach(function(r){var a=r[0],c=r[1];typeof c=="string"&&(i[a]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),i}function Ee(t,e){var n,i=e.defIds;return!i||i.length===0?t:t.tag==="defs"&&(!((n=t.children)===null||n===void 0)&&n.length)?C(C({},t),{children:t.children.map(function(s){return typeof s.attrs.id=="string"&&i&&i.indexOf(s.attrs.id)>-1?C(C({},s),{attrs:C(C({},s.attrs),{id:s.attrs.id+e.idSuffix})}):s})}):t}function Ne(){return Math.random().toString(36).substring(2,8)}q.displayName="UniverIcon";var Le={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_217_40",style:{maskType:"alpha"},width:17,height:17,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#D9D9D9",d:"M0.9 0.09H16.9V16.09H0.9z"}}]},{tag:"g",attrs:{mask:"url(#mask0_217_40)"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.39551 7.37266C2.39551 4.18105 4.98281 1.59375 8.17441 1.59375C11.366 1.59375 13.9533 4.18105 13.9533 7.37266C13.9533 8.72342 13.4898 9.96603 12.7133 10.95L15.1964 13.4331C15.4619 13.6986 15.4619 14.1291 15.1964 14.3946C14.9309 14.6601 14.5004 14.6601 14.2349 14.3946L11.7518 11.9115C10.7678 12.6881 9.52525 13.1516 8.17441 13.1516C4.98281 13.1516 2.39551 10.5642 2.39551 7.37266ZM8.17441 2.95349C5.73378 2.95349 3.75525 4.93202 3.75525 7.37266C3.75525 9.81333 5.73378 11.7918 8.17441 11.7918C10.6151 11.7918 12.5936 9.81333 12.5936 7.37266C12.5936 4.93202 10.6151 2.95349 8.17441 2.95349Z",fillRule:"evenodd",clipRule:"evenodd"}}]}]},Y=h.forwardRef(function(t,e){return h.createElement(q,Object.assign({},t,{id:"search-single-16",ref:e,icon:Le}))});Y.displayName="SearchSingle16";const Z="FIND_REPLACE_INPUT_FOCUS",J="FIND_REPLACE_DIALOG_FOCUS",Q="FIND_REPLACE_REPLACE_REVEALED";var $e=Object.getOwnPropertyDescriptor,X=(t,e,n,i)=>{for(var s=i>1?void 0:i?$e(e,n):e,r=t.length-1,a;r>=0;r--)(a=t[r])&&(s=a(s)||s);return s},j=(t,e)=>(n,i)=>e(n,i,t);class je extends o.Disposable{}const R=o.createIdentifier("find-replace.service");function Ae(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){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.disposeWithMe(this._state.stateUpdates$.pipe(_.throttleTime(200,void 0,{leading:!0,trailing:!0})).subscribe(async r=>{const a=this._state.state;Ae(r)&&(a.findString!==""&&!a.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({...P(),revealed:!1})}async start(){if(!this._state.findString)return{results:[]};const n=await this._startSearching();return this._state.changeState({findCompleted:!0}),n}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(c=>c.replaceable))):(this._state.changeState({matchesCount:0,matchesPosition:0}),this.replaceables$.next([]))});n.forEach(r=>i.add(o.toDisposable(r.activelyChangingMatch$.subscribe(a=>{const c=this._matches.findIndex(p=>p===a);this._state.changeState({matchesPosition:c+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(c=>c===this._matchingModel);for(let c=(r-1+s)%s;c!==r;){const p=this._findModels[c],v=p.moveToPreviousMatch({ignoreSelection:!0});if(v)return this._matchingModel=p,this._markMatch(v),v;c=(c-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(c=>c.unitId===s);if(r!==-1){this._matchingModel=n[r];const c=this._matchingModel.moveToNextMatch({stayIfOnMatch:!0,noFocus:i});if(c)return this._markMatch(c),r}return this._moveToNextUnitMatch(r),0}};exports.FindReplaceModel=X([j(2,o.IUniverInstanceService)],exports.FindReplaceModel);var D=(t=>(t.ROW="row",t.COLUMN="column",t))(D||{}),x=(t=>(t.VALUE="value",t.FORMULA="formula",t))(x||{}),T=(t=>(t.SUBUNIT="subunit",t.UNIT="unit",t))(T||{});function P(){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 ee{constructor(){u(this,"_stateUpdates$",new _.Subject);u(this,"stateUpdates$",this._stateUpdates$.asObservable());u(this,"_state$",new _.BehaviorSubject(P()));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 ee);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)}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=P();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(Q,e)}_toggleDisplayRawFormula(e){this._contextService.setContextValue(xe.RENDER_RAW_FORMULA_KEY,e)}};A=X([j(0,o.Inject(o.Injector)),j(1,o.IContextService)],A);const w={id:"ui.command.replace-current-match",type:o.CommandType.COMMAND,handler:t=>t.get(R).replace()},we="CONFIRM_REPLACE_ALL",U={id:"ui.command.replace-all-matches",type:o.CommandType.COMMAND,handler:async t=>{const e=t.get(l.IConfirmService),n=t.get(o.LocaleService),i=t.get(l.IMessageService);if(!await e.confirm({id:we,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(R).replaceAll(),{success:a,failure:c}=r;return c>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}`,`${c}`)}),!1):(i.show({type:f.MessageType.Success,content:n.t("find-replace.replace.all-success",`${a}`)}),!0)}},y={id:"ui.operation.open-find-dialog",type:o.CommandType.OPERATION,handler:t=>{const e=t.get(R);return e.revealed?e.focusFindInput():e.start(),!0}},E={id:"ui.operation.open-replace-dialog",type:o.CommandType.OPERATION,handler:t=>{const e=t.get(R);return e.revealed?e.replaceRevealed?e.focusFindInput():e.revealReplace():e.start(!0),!0}},k={type:o.CommandType.OPERATION,id:"ui.operation.go-to-next-match",handler:t=>(t.get(R).moveToNextMatch(),!0)},B={type:o.CommandType.OPERATION,id:"ui.operation.go-to-previous-match",handler:t=>(t.get(R).moveToPreviousMatch(),!0)},Ue="univer-find-replace-dialog-container",ke="univer-find-replace-expand-container",Be="univer-find-replace-buttons-group",We="univer-find-replace-buttons-group-right",O={findReplaceDialogContainer:Ue,findReplaceExpandContainer:ke,findReplaceButtonsGroup:Be,findReplaceButtonsGroupRight:We};function te(t){const{findCompleted:e,localeService:n,matchesCount:i,matchesPosition:s,findString:r,findReplaceService:a,onChange:c,...p}=t,S=e&&i===0?n.t("find-replace.dialog.no-result"):i===0?" ":void 0;return d.jsx(f.InputWithSlot,{autoFocus:!0,placeholder:n.t("find-replace.dialog.find-placeholder"),slot:d.jsx(f.Pager,{loop:!0,text:S,value:s,total:i,onChange:m=>{s===i&&m===1?a.moveToNextMatch():s===1&&m===i||m<s?a.moveToPreviousMatch():a.moveToNextMatch()}}),value:r,onChange:m=>c==null?void 0:c(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(".univer-find-replace-dialog-container .univer-select-selection-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 Ge=h.forwardRef(function(e,n){const i=l.useDependency(o.LocaleService),s=l.useDependency(R),r=l.useDependency(o.ICommandService),a=l.useObservable(s.state$,void 0,!0),{findCompleted:c,findString:p,matchesCount:v,matchesPosition:S}=a,m=h.useCallback(()=>{r.executeCommand(E.id)},[r]),F=h.useCallback(b=>s.changeFindString(b),[s]);return ie(s,n),d.jsxs(d.Fragment,{children:[d.jsx(te,{findCompleted:c,className:"univer-find-input",matchesCount:v,matchesPosition:S,findReplaceService:s,localeService:i,findString:p,onChange:F}),d.jsx("div",{className:O.findReplaceExpandContainer,children:d.jsx(f.Button,{type:"text",size:"small",onClick:m,children:i.t("find-replace.dialog.advanced-finding")})})]})}),Ve=h.forwardRef(function(e,n){const i=l.useDependency(R),s=l.useDependency(o.LocaleService),r=l.useDependency(o.ICommandService),a=l.useDependency(l.IMessageService),c=l.useObservable(i.currentMatch$,void 0,!0),p=l.useObservable(i.replaceables$,void 0,!0),v=l.useObservable(i.state$,void 0,!0),{matchesCount:S,matchesPosition:m,findString:F,inputtingFindString:b,replaceString:re,caseSensitive:ae,matchesTheWholeCell:oe,findDirection:ce,findScope:le,findBy:de,findCompleted:L}=v,ue=b.length===0,he=S===0||!(c!=null&&c.replaceable),pe=p.length===0,fe=h.useCallback(g=>i.changeInputtingFindString(g),[i]),ge=h.useCallback(g=>i.changeReplaceString(g),[i]),{focus:_e}=ie(i,n),me=h.useCallback(()=>{F===b?i.moveToNextMatch():(i.changeFindString(b),i.find())},[F,b,i]),ve=h.useCallback(()=>r.executeCommand(w.id),[r]),Se=h.useCallback(async()=>{await r.executeCommand(U.id),_e()},[r]),Ce=h.useCallback(g=>{i.changeFindDirection(g)},[i]),Re=h.useCallback(g=>{i.changeFindScope(g)},[i]),Me=h.useCallback(g=>{i.changeFindBy(g)},[i]),be=Ke(s),ye=qe(s),Ie=ze(s);return h.useEffect(()=>{L&&S===0&&a.show({content:s.t("find-replace.dialog.no-match"),type:f.MessageType.Warning,duration:5e3})},[L,S,a,s]),d.jsxs(d.Fragment,{children:[d.jsx(f.FormLayout,{label:s.t("find-replace.dialog.find"),children:d.jsx(te,{findCompleted:L,className:"univer-find-input",matchesCount:S,matchesPosition:m,findReplaceService:i,localeService:s,findString:b,onChange:fe})}),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:re,onChange:g=>ge(g)})}),d.jsx(f.FormLayout,{label:s.t("find-replace.dialog.find-direction.title"),children:d.jsx(f.Select,{value:ce,options:ye,onChange:Ce})}),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:le,options:be,onChange:Re})}),d.jsx(f.FormLayout,{label:s.t("find-replace.dialog.find-by.title"),children:d.jsx(f.Select,{value:de,options:Ie,onChange:Me})})]})}),d.jsx(f.FormDualColumnLayout,{children:d.jsxs(d.Fragment,{children:[d.jsx(f.FormLayout,{children:d.jsx(f.Checkbox,{checked:ae,onChange:g=>{i.changeCaseSensitive(g)},children:s.t("find-replace.dialog.case-sensitive")})}),d.jsx(f.FormLayout,{children:d.jsx(f.Checkbox,{checked:oe,onChange:g=>{i.changeMatchesTheWholeCell(g)},children:s.t("find-replace.dialog.match-the-whole-cell")})})]})}),d.jsxs("div",{className:O.findReplaceButtonsGroup,children:[d.jsx(f.Button,{type:"primary",onClick:me,disabled:ue,children:s.t("find-replace.dialog.find")}),d.jsxs("span",{className:O.findReplaceButtonsGroupRight,children:[d.jsx(f.Button,{disabled:he,onClick:ve,children:s.t("find-replace.dialog.replace")}),d.jsx(f.Button,{disabled:pe,onClick:Se,children:s.t("find-replace.dialog.replace-all")})]})]})]})});function He(){const t=l.useDependency(R),e=l.useDependency(l.ILayoutService),n=l.useDependency(o.IContextService),i=l.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(J,p),[n]),c=h.useCallback(p=>n.setContextValue(Z,p),[n]);return h.useEffect(()=>{var v;const p=_.fromEvent(document,"focusin").subscribe(S=>{var m;S.target&&((m=s.current)!=null&&m.contains(S.target))?a(!0):a(!1),!r.current||!r.current.selectHasFocus()?c(!0):c(!1)});return(v=r.current)==null||v.focus(),a(!0),c(!0),()=>{p.unsubscribe(),a(!1)}},[a,c]),d.jsx("div",{className:O.findReplaceDialogContainer,ref:s,children:i.replaceRevealed?d.jsx(Ve,{ref:r}):d.jsx(Ge,{ref:r})})}function Ke(t){const e=t.getCurrentLocale();return h.useMemo(()=>[{label:t.t("find-replace.dialog.find-scope.current-sheet"),value:T.SUBUNIT},{label:t.t("find-replace.dialog.find-scope.workbook"),value:T.UNIT}],[e])}function qe(t){const e=t.getCurrentLocale();return h.useMemo(()=>[{label:t.t("find-replace.dialog.find-direction.row"),value:D.ROW},{label:t.t("find-replace.dialog.find-direction.column"),value:D.COLUMN}],[e])}function ze(t){const e=t.getCurrentLocale();return h.useMemo(()=>[{label:t.t("find-replace.dialog.find-by.value"),value:x.VALUE},{label:t.t("find-replace.dialog.find-by.formula"),value:x.FORMULA}],[e])}function I(t){return t.getContextValue(J)}function Ye(t){return t.getContextValue(Q)}function ne(t){return t.getContextValue(Z)}const N="7_find-replace-shortcuts";function W(t){return t.getContextValue(o.FOCUSING_SHEET)}function G(t){return!t.getContextValue(o.EDITOR_ACTIVATED)}const Ze={id:y.id,description:"find-replace.shortcut.open-find-dialog",binding:l.KeyCode.F|l.MetaKeys.CTRL_COMMAND,group:N,preconditions(t){return!I(t)&&W(t)&&G(t)}},Je={id:y.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(t){return!I(t)&&W(t)&&G(t)}},Qe={id:E.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:N,preconditions(t){return W(t)&&G(t)&&(!I(t)||!Ye(t))}},Xe={id:k.id,description:"find-replace.shortcut.go-to-next-match",binding:l.KeyCode.ENTER,group:N,priority:1e3,preconditions(t){return ne(t)&&I(t)}},et={id:B.id,description:"find-replace.shortcut.go-to-previous-match",binding:l.KeyCode.ENTER|l.MetaKeys.SHIFT,group:N,priority:1e3,preconditions(t){return ne(t)&&I(t)}};function tt(t){const e=t.get(o.IContextService);return{id:y.id,icon:"SearchIcon",tooltip:"find-replace.toolbar",type:l.MenuItemType.BUTTON,hidden$:l.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 it={[l.RibbonStartGroup.OTHERS]:{[y.id]:{order:2,menuItemFactory:tt}}};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},M=(t,e)=>(n,i)=>e(n,i,t);const H="DESKTOP_FIND_REPLACE_DIALOG",se=350,rt=20,at=-90;exports.FindReplaceController=class extends o.RxDisposable{constructor(n,i,s,r,a,c,p,v,S,m){super();u(this,"_closingListenerDisposable");this._univerInstanceService=n,this._menuManagerService=i,this._shortcutService=s,this._commandService=r,this._findReplaceService=a,this._dialogService=c,this._layoutService=p,this._localeService=v,this._componentManager=S,this._injector=m,this._initCommands(),this._initUI(),this._initShortcuts()}dispose(){var n;super.dispose(),(n=this._closingListenerDisposable)==null||n.dispose(),this._closingListenerDisposable=null}_initCommands(){[y,E,k,B,U,w].forEach(n=>{this.disposeWithMe(this._commandService.registerCommand(n))})}_initShortcuts(){[Qe,Ze,Je,et,Xe].forEach(n=>this.disposeWithMe(this._shortcutService.registerShortcut(n)))}_initUI(){this.disposeWithMe(this._componentManager.register("FindReplaceDialog",He)),this.disposeWithMe(this._componentManager.register("SearchIcon",Y)),this._menuManagerService.mergeMenu(it),this._findReplaceService.stateUpdates$.pipe(_.takeUntil(this.dispose$)).subscribe(n=>{n.revealed===!0&&this._openPanel()})}_openPanel(){this._dialogService.open({id:H,draggable:!0,width:se,title:{title:this._localeService.t("find-replace.dialog.title")},children:{label:"FindReplaceDialog"},destroyOnClose:!0,defaultPosition:ot(),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(H),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus()))}};exports.FindReplaceController=st([M(0,o.IUniverInstanceService),M(1,l.IMenuManagerService),M(2,l.IShortcutService),M(3,o.ICommandService),M(4,R),M(5,l.IDialogService),M(6,l.ILayoutService),M(7,o.Inject(o.LocaleService)),M(8,o.Inject(l.ComponentManager)),M(9,o.Inject(o.Injector))],exports.FindReplaceController);function ot(){const{innerWidth:t}=window;return{x:(t-se)/2-rt,y:at}}var ct=Object.getOwnPropertyDescriptor,lt=(t,e,n,i)=>{for(var s=i>1?void 0:i?ct(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 dt="UNIVER_FIND_REPLACE_PLUGIN";var $;exports.UniverFindReplacePlugin=($=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(Te,s)}onStarting(){[[exports.FindReplaceController],[R,{useClass:A}]].forEach(e=>this._injector.add(e))}onRendered(){this._injector.get(exports.FindReplaceController)}},u($,"pluginName",dt),$);exports.UniverFindReplacePlugin=lt([K(1,o.Inject(o.Injector)),K(2,o.IConfigService)],exports.UniverFindReplacePlugin);exports.FindBy=x;exports.FindDirection=D;exports.FindModel=je;exports.FindReplaceState=ee;exports.FindScope=T;exports.GoToNextMatchOperation=k;exports.GoToPreviousMatchOperation=B;exports.IFindReplaceService=R;exports.OpenFindDialogOperation=y;exports.OpenReplaceDialogOperation=E;exports.ReplaceAllMatchesCommand=U;exports.ReplaceCurrentMatchCommand=w;exports.createInitFindReplaceState=P;
|
package/lib/es/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
var rt = Object.defineProperty;
|
|
2
2
|
var st = (t, e, n) => e in t ? rt(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
|
|
3
3
|
var o = (t, e, n) => st(t, typeof e != "symbol" ? e + "" : e, n);
|
|
4
|
-
import { createIdentifier as at, Inject as D, Injector as Q,
|
|
5
|
-
import { IConfirmService as ft, IMessageService as me, useDependency as
|
|
6
|
-
import { throttleTime as Rt, BehaviorSubject as P, combineLatest as
|
|
7
|
-
import { MessageType as
|
|
4
|
+
import { createIdentifier as at, Inject as D, Injector as Q, IContextService as X, Disposable as ee, DisposableCollection as ot, toDisposable as A, IUniverInstanceService as pe, CommandType as y, LocaleService as B, ICommandService as te, FOCUSING_SHEET as _e, EDITOR_ACTIVATED as ge, UniverInstanceType as ct, RxDisposable as lt, IConfigService as dt, Plugin as ht, merge as ut } from "@univerjs/core";
|
|
5
|
+
import { IConfirmService as ft, IMessageService as me, useDependency as v, useObservable as F, ILayoutService as ve, KeyCode as M, MetaKeys as I, getMenuHiddenObservable as pt, MenuItemType as _t, RibbonStartGroup as gt, IMenuManagerService as mt, IShortcutService as vt, IDialogService as St, ComponentManager as Ct } from "@univerjs/ui";
|
|
6
|
+
import { throttleTime as Rt, BehaviorSubject as P, combineLatest as Se, debounceTime as Mt, Subject as Ce, fromEvent as bt, map as It, takeUntil as oe } from "rxjs";
|
|
7
|
+
import { MessageType as O, InputWithSlot as yt, Pager as Dt, Button as N, FormLayout as R, Input as Ft, Select as G, FormDualColumnLayout as ce, Checkbox as le } from "@univerjs/design";
|
|
8
8
|
import { RENDER_RAW_FORMULA_KEY as Pt } from "@univerjs/engine-render";
|
|
9
9
|
import { jsx as l, jsxs as b, Fragment as $ } from "react/jsx-runtime";
|
|
10
10
|
import { forwardRef as W, useRef as H, createElement as Re, useCallback as u, useEffect as L, useMemo as ie, useImperativeHandle as xt } from "react";
|
|
@@ -17,7 +17,7 @@ var _ = function() {
|
|
|
17
17
|
}
|
|
18
18
|
return t;
|
|
19
19
|
}, _.apply(this, arguments);
|
|
20
|
-
},
|
|
20
|
+
}, Et = function(t, e) {
|
|
21
21
|
var n = {};
|
|
22
22
|
for (var i in t) Object.prototype.hasOwnProperty.call(t, i) && e.indexOf(i) < 0 && (n[i] = t[i]);
|
|
23
23
|
if (t != null && typeof Object.getOwnPropertySymbols == "function")
|
|
@@ -25,15 +25,15 @@ var _ = function() {
|
|
|
25
25
|
e.indexOf(i[r]) < 0 && Object.prototype.propertyIsEnumerable.call(t, i[r]) && (n[i[r]] = t[i[r]]);
|
|
26
26
|
return n;
|
|
27
27
|
}, Me = W(function(t, e) {
|
|
28
|
-
var n = t.icon, i = t.id, r = t.className, s = t.extend, a =
|
|
28
|
+
var n = t.icon, i = t.id, r = t.className, s = t.extend, a = Et(t, ["icon", "id", "className", "extend"]), c = "univerjs-icon univerjs-icon-".concat(i, " ").concat(r || "").trim(), d = H("_".concat($t()));
|
|
29
29
|
return be(n, "".concat(i), { defIds: n.defIds, idSuffix: d.current }, _({ ref: e, className: c }, a), s);
|
|
30
30
|
});
|
|
31
31
|
function be(t, e, n, i, r) {
|
|
32
|
-
return Re(t.tag, _(_({ key: e },
|
|
32
|
+
return Re(t.tag, _(_({ key: e }, Ot(t, n, r)), i), (Nt(t, n).children || []).map(function(s, a) {
|
|
33
33
|
return be(s, "".concat(e, "-").concat(t.tag, "-").concat(a), n, void 0, r);
|
|
34
34
|
}));
|
|
35
35
|
}
|
|
36
|
-
function
|
|
36
|
+
function Ot(t, e, n) {
|
|
37
37
|
var i = _({}, t.attrs);
|
|
38
38
|
n != null && n.colorChannel1 && i.fill === "colorChannel1" && (i.fill = n.colorChannel1);
|
|
39
39
|
var r = e.defIds;
|
|
@@ -61,18 +61,18 @@ var At = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 17 17", width: "1em"
|
|
|
61
61
|
});
|
|
62
62
|
Ie.displayName = "SearchSingle16";
|
|
63
63
|
const ye = "FIND_REPLACE_INPUT_FOCUS", De = "FIND_REPLACE_DIALOG_FOCUS", Fe = "FIND_REPLACE_REPLACE_REVEALED";
|
|
64
|
-
var Lt = Object.
|
|
65
|
-
for (var r = i > 1 ? void 0 : i ?
|
|
66
|
-
(a = t[s]) && (r =
|
|
67
|
-
return
|
|
64
|
+
var Lt = Object.getOwnPropertyDescriptor, Pe = (t, e, n, i) => {
|
|
65
|
+
for (var r = i > 1 ? void 0 : i ? Lt(e, n) : e, s = t.length - 1, a; s >= 0; s--)
|
|
66
|
+
(a = t[s]) && (r = a(r) || r);
|
|
67
|
+
return r;
|
|
68
68
|
}, K = (t, e) => (n, i) => e(n, i, t);
|
|
69
|
-
class
|
|
69
|
+
class Ci extends ee {
|
|
70
70
|
}
|
|
71
71
|
const g = at("find-replace.service");
|
|
72
|
-
function
|
|
72
|
+
function wt(t) {
|
|
73
73
|
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";
|
|
74
74
|
}
|
|
75
|
-
let z = class extends
|
|
75
|
+
let z = class extends ee {
|
|
76
76
|
constructor(e, n, i) {
|
|
77
77
|
super();
|
|
78
78
|
o(this, "currentMatch$", new P(null));
|
|
@@ -86,7 +86,7 @@ let z = class extends X {
|
|
|
86
86
|
this._state = e, this._providers = n, this._univerInstanceService = i, this.disposeWithMe(
|
|
87
87
|
this._state.stateUpdates$.pipe(Rt(200, void 0, { leading: !0, trailing: !0 })).subscribe(async (r) => {
|
|
88
88
|
const s = this._state.state;
|
|
89
|
-
|
|
89
|
+
wt(r) && (s.findString !== "" && !s.replaceRevealed ? (await this._startSearching(), this._state.changeState({ findCompleted: !0 })) : r.replaceRevealed !== !0 && this._stopSearching());
|
|
90
90
|
})
|
|
91
91
|
);
|
|
92
92
|
}
|
|
@@ -130,7 +130,7 @@ let z = class extends X {
|
|
|
130
130
|
}
|
|
131
131
|
// When a document's content changes, we should reset all matches and try to move to the next match.
|
|
132
132
|
_subscribeToModelsChanges(e) {
|
|
133
|
-
const n = this._currentSearchingDisposables = new ot(), i =
|
|
133
|
+
const n = this._currentSearchingDisposables = new ot(), i = Se(e.map((r) => r.matchesUpdate$)).pipe(Mt(220)).subscribe(([...r]) => {
|
|
134
134
|
const s = this._matches = r.flat();
|
|
135
135
|
s.length ? (this._moveToInitialMatch(this._findModels, !0), this._state.changeState({ matchesCount: s.length }), this.replaceables$.next(s.filter((a) => a.replaceable))) : (this._state.changeState({ matchesCount: 0, matchesPosition: 0 }), this.replaceables$.next([]));
|
|
136
136
|
});
|
|
@@ -232,7 +232,7 @@ function ne() {
|
|
|
232
232
|
revealed: !0
|
|
233
233
|
};
|
|
234
234
|
}
|
|
235
|
-
class
|
|
235
|
+
class Ut {
|
|
236
236
|
constructor() {
|
|
237
237
|
o(this, "_stateUpdates$", new Ce());
|
|
238
238
|
o(this, "stateUpdates$", this._stateUpdates$.asObservable());
|
|
@@ -314,11 +314,11 @@ class Bt {
|
|
|
314
314
|
}), this._stateUpdates$.next(i));
|
|
315
315
|
}
|
|
316
316
|
}
|
|
317
|
-
let J = class extends
|
|
317
|
+
let J = class extends ee {
|
|
318
318
|
constructor(e, n) {
|
|
319
319
|
super();
|
|
320
320
|
o(this, "_providers", /* @__PURE__ */ new Set());
|
|
321
|
-
o(this, "_state", new
|
|
321
|
+
o(this, "_state", new Ut());
|
|
322
322
|
o(this, "_model");
|
|
323
323
|
o(this, "_currentMatch$", new P(null));
|
|
324
324
|
o(this, "currentMatch$", this._currentMatch$.asObservable());
|
|
@@ -427,19 +427,19 @@ let J = class extends X {
|
|
|
427
427
|
};
|
|
428
428
|
J = Pe([
|
|
429
429
|
K(0, D(Q)),
|
|
430
|
-
K(1,
|
|
430
|
+
K(1, X)
|
|
431
431
|
], J);
|
|
432
432
|
const xe = {
|
|
433
433
|
id: "ui.command.replace-current-match",
|
|
434
434
|
type: y.COMMAND,
|
|
435
435
|
handler: (t) => t.get(g).replace()
|
|
436
|
-
},
|
|
436
|
+
}, Bt = "CONFIRM_REPLACE_ALL", Te = {
|
|
437
437
|
id: "ui.command.replace-all-matches",
|
|
438
438
|
type: y.COMMAND,
|
|
439
439
|
handler: async (t) => {
|
|
440
440
|
const e = t.get(ft), n = t.get(B), i = t.get(me);
|
|
441
441
|
if (!await e.confirm({
|
|
442
|
-
id:
|
|
442
|
+
id: Bt,
|
|
443
443
|
title: { title: n.t("find-replace.replace.confirm.title") },
|
|
444
444
|
cancelText: n.t("button.cancel"),
|
|
445
445
|
confirmText: n.t("button.confirm")
|
|
@@ -447,13 +447,13 @@ const xe = {
|
|
|
447
447
|
return !1;
|
|
448
448
|
const s = await t.get(g).replaceAll(), { success: a, failure: c } = s;
|
|
449
449
|
return c > 0 ? (a === 0 ? i.show({
|
|
450
|
-
type:
|
|
450
|
+
type: O.Error,
|
|
451
451
|
content: n.t("find-replace.replace.all-failure")
|
|
452
452
|
}) : i.show({
|
|
453
|
-
type:
|
|
453
|
+
type: O.Warning,
|
|
454
454
|
content: n.t("find-replace.replace.partial-success", `${a}`, `${c}`)
|
|
455
455
|
}), !1) : (i.show({
|
|
456
|
-
type:
|
|
456
|
+
type: O.Success,
|
|
457
457
|
content: n.t("find-replace.replace.all-success", `${a}`)
|
|
458
458
|
}), !0);
|
|
459
459
|
}
|
|
@@ -471,20 +471,19 @@ const xe = {
|
|
|
471
471
|
const e = t.get(g);
|
|
472
472
|
return e.revealed ? e.replaceRevealed ? e.focusFindInput() : e.revealReplace() : e.start(!0), !0;
|
|
473
473
|
}
|
|
474
|
-
},
|
|
474
|
+
}, Ee = {
|
|
475
475
|
type: y.OPERATION,
|
|
476
476
|
id: "ui.operation.go-to-next-match",
|
|
477
477
|
handler: (t) => (t.get(g).moveToNextMatch(), !0)
|
|
478
|
-
},
|
|
478
|
+
}, Oe = {
|
|
479
479
|
type: y.OPERATION,
|
|
480
480
|
id: "ui.operation.go-to-previous-match",
|
|
481
481
|
handler: (t) => (t.get(g).moveToPreviousMatch(), !0)
|
|
482
|
-
},
|
|
483
|
-
findReplaceDialogContainer:
|
|
484
|
-
findReplaceExpandContainer:
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
findReplaceButtonsGroupRight: Ht
|
|
482
|
+
}, Wt = "univer-find-replace-dialog-container", kt = "univer-find-replace-expand-container", jt = "univer-find-replace-buttons-group", Gt = "univer-find-replace-buttons-group-right", w = {
|
|
483
|
+
findReplaceDialogContainer: Wt,
|
|
484
|
+
findReplaceExpandContainer: kt,
|
|
485
|
+
findReplaceButtonsGroup: jt,
|
|
486
|
+
findReplaceButtonsGroupRight: Gt
|
|
488
487
|
};
|
|
489
488
|
function Ne(t) {
|
|
490
489
|
const { findCompleted: e, localeService: n, matchesCount: i, matchesPosition: r, findString: s, findReplaceService: a, onChange: c, ...d } = t, f = e && i === 0 ? n.t("find-replace.dialog.no-result") : i === 0 ? " " : void 0;
|
|
@@ -524,48 +523,48 @@ function $e(t, e) {
|
|
|
524
523
|
return () => r.unsubscribe();
|
|
525
524
|
}, [t, n]), { focus: n, selectHasFocus: i };
|
|
526
525
|
}
|
|
527
|
-
const
|
|
528
|
-
const i =
|
|
526
|
+
const Vt = W(function(e, n) {
|
|
527
|
+
const i = v(B), r = v(g), s = v(te), a = F(r.state$, void 0, !0), { findCompleted: c, findString: d, matchesCount: S, matchesPosition: f } = a, p = u(() => {
|
|
529
528
|
s.executeCommand(re.id);
|
|
530
|
-
}, [s]),
|
|
529
|
+
}, [s]), E = u((C) => r.changeFindString(C), [r]);
|
|
531
530
|
return $e(r, n), /* @__PURE__ */ b($, { children: [
|
|
532
531
|
/* @__PURE__ */ l(
|
|
533
532
|
Ne,
|
|
534
533
|
{
|
|
535
534
|
findCompleted: c,
|
|
536
535
|
className: "univer-find-input",
|
|
537
|
-
matchesCount:
|
|
536
|
+
matchesCount: S,
|
|
538
537
|
matchesPosition: f,
|
|
539
538
|
findReplaceService: r,
|
|
540
539
|
localeService: i,
|
|
541
540
|
findString: d,
|
|
542
|
-
onChange:
|
|
541
|
+
onChange: E
|
|
543
542
|
}
|
|
544
543
|
),
|
|
545
544
|
/* @__PURE__ */ l("div", { className: w.findReplaceExpandContainer, children: /* @__PURE__ */ l(N, { type: "text", size: "small", onClick: p, children: i.t("find-replace.dialog.advanced-finding") }) })
|
|
546
545
|
] });
|
|
547
|
-
}),
|
|
548
|
-
const i =
|
|
546
|
+
}), Ht = W(function(e, n) {
|
|
547
|
+
const i = v(g), r = v(B), s = v(te), a = v(me), c = F(i.currentMatch$, void 0, !0), d = F(i.replaceables$, void 0, !0), S = F(i.state$, void 0, !0), {
|
|
549
548
|
matchesCount: f,
|
|
550
549
|
matchesPosition: p,
|
|
551
|
-
findString:
|
|
550
|
+
findString: E,
|
|
552
551
|
inputtingFindString: C,
|
|
553
552
|
replaceString: we,
|
|
554
553
|
caseSensitive: Ue,
|
|
555
554
|
matchesTheWholeCell: Be,
|
|
556
555
|
findDirection: We,
|
|
557
|
-
findScope:
|
|
558
|
-
findBy:
|
|
559
|
-
findCompleted:
|
|
560
|
-
} =
|
|
556
|
+
findScope: ke,
|
|
557
|
+
findBy: je,
|
|
558
|
+
findCompleted: j
|
|
559
|
+
} = S, Ge = C.length === 0, Ve = f === 0 || !(c != null && c.replaceable), He = d.length === 0, Ke = u(
|
|
561
560
|
(h) => i.changeInputtingFindString(h),
|
|
562
561
|
[i]
|
|
563
562
|
), ze = u(
|
|
564
563
|
(h) => i.changeReplaceString(h),
|
|
565
564
|
[i]
|
|
566
565
|
), { focus: qe } = $e(i, n), Ye = u(() => {
|
|
567
|
-
|
|
568
|
-
}, [
|
|
566
|
+
E === C ? i.moveToNextMatch() : (i.changeFindString(C), i.find());
|
|
567
|
+
}, [E, C, i]), Ze = u(() => s.executeCommand(xe.id), [s]), Je = u(async () => {
|
|
569
568
|
await s.executeCommand(Te.id), qe();
|
|
570
569
|
}, [s]), Qe = u((h) => {
|
|
571
570
|
i.changeFindDirection(h);
|
|
@@ -573,18 +572,18 @@ const Kt = W(function(e, n) {
|
|
|
573
572
|
i.changeFindScope(h);
|
|
574
573
|
}, [i]), et = u((h) => {
|
|
575
574
|
i.changeFindBy(h);
|
|
576
|
-
}, [i]), tt =
|
|
575
|
+
}, [i]), tt = zt(r), it = qt(r), nt = Yt(r);
|
|
577
576
|
return L(() => {
|
|
578
|
-
|
|
577
|
+
j && f === 0 && a.show({
|
|
579
578
|
content: r.t("find-replace.dialog.no-match"),
|
|
580
|
-
type:
|
|
579
|
+
type: O.Warning,
|
|
581
580
|
duration: 5e3
|
|
582
581
|
});
|
|
583
|
-
}, [
|
|
582
|
+
}, [j, f, a, r]), /* @__PURE__ */ b($, { children: [
|
|
584
583
|
/* @__PURE__ */ l(R, { label: r.t("find-replace.dialog.find"), children: /* @__PURE__ */ l(
|
|
585
584
|
Ne,
|
|
586
585
|
{
|
|
587
|
-
findCompleted:
|
|
586
|
+
findCompleted: j,
|
|
588
587
|
className: "univer-find-input",
|
|
589
588
|
matchesCount: f,
|
|
590
589
|
matchesPosition: p,
|
|
@@ -602,10 +601,10 @@ const Kt = W(function(e, n) {
|
|
|
602
601
|
onChange: (h) => ze(h)
|
|
603
602
|
}
|
|
604
603
|
) }),
|
|
605
|
-
/* @__PURE__ */ l(R, { label: r.t("find-replace.dialog.find-direction.title"), children: /* @__PURE__ */ l(
|
|
604
|
+
/* @__PURE__ */ l(R, { label: r.t("find-replace.dialog.find-direction.title"), children: /* @__PURE__ */ l(G, { value: We, options: it, onChange: Qe }) }),
|
|
606
605
|
/* @__PURE__ */ l(ce, { children: /* @__PURE__ */ b($, { children: [
|
|
607
|
-
/* @__PURE__ */ l(R, { label: r.t("find-replace.dialog.find-scope.title"), children: /* @__PURE__ */ l(
|
|
608
|
-
/* @__PURE__ */ l(R, { label: r.t("find-replace.dialog.find-by.title"), children: /* @__PURE__ */ l(
|
|
606
|
+
/* @__PURE__ */ l(R, { label: r.t("find-replace.dialog.find-scope.title"), children: /* @__PURE__ */ l(G, { value: ke, options: tt, onChange: Xe }) }),
|
|
607
|
+
/* @__PURE__ */ l(R, { label: r.t("find-replace.dialog.find-by.title"), children: /* @__PURE__ */ l(G, { value: je, options: nt, onChange: et }) })
|
|
609
608
|
] }) }),
|
|
610
609
|
/* @__PURE__ */ l(ce, { children: /* @__PURE__ */ b($, { children: [
|
|
611
610
|
/* @__PURE__ */ l(R, { children: /* @__PURE__ */ l(
|
|
@@ -630,16 +629,16 @@ const Kt = W(function(e, n) {
|
|
|
630
629
|
) })
|
|
631
630
|
] }) }),
|
|
632
631
|
/* @__PURE__ */ b("div", { className: w.findReplaceButtonsGroup, children: [
|
|
633
|
-
/* @__PURE__ */ l(N, { type: "primary", onClick: Ye, disabled:
|
|
632
|
+
/* @__PURE__ */ l(N, { type: "primary", onClick: Ye, disabled: Ge, children: r.t("find-replace.dialog.find") }),
|
|
634
633
|
/* @__PURE__ */ b("span", { className: w.findReplaceButtonsGroupRight, children: [
|
|
635
|
-
/* @__PURE__ */ l(N, { disabled:
|
|
634
|
+
/* @__PURE__ */ l(N, { disabled: Ve, onClick: Ze, children: r.t("find-replace.dialog.replace") }),
|
|
636
635
|
/* @__PURE__ */ l(N, { disabled: He, onClick: Je, children: r.t("find-replace.dialog.replace-all") })
|
|
637
636
|
] })
|
|
638
637
|
] })
|
|
639
638
|
] });
|
|
640
639
|
});
|
|
641
|
-
function
|
|
642
|
-
const t =
|
|
640
|
+
function Kt() {
|
|
641
|
+
const t = v(g), e = v(ve), n = v(X), i = F(t.state$, void 0, !0), r = H(null);
|
|
643
642
|
L(() => {
|
|
644
643
|
let d;
|
|
645
644
|
return r.current && (d = e.registerContainerElement(r.current)), () => d == null ? void 0 : d.dispose();
|
|
@@ -652,31 +651,31 @@ function qt() {
|
|
|
652
651
|
[n]
|
|
653
652
|
);
|
|
654
653
|
return L(() => {
|
|
655
|
-
var
|
|
654
|
+
var S;
|
|
656
655
|
const d = bt(document, "focusin").subscribe((f) => {
|
|
657
656
|
var p;
|
|
658
657
|
f.target && ((p = r.current) != null && p.contains(f.target)) ? a(!0) : a(!1), !s.current || !s.current.selectHasFocus() ? c(!0) : c(!1);
|
|
659
658
|
});
|
|
660
|
-
return (
|
|
659
|
+
return (S = s.current) == null || S.focus(), a(!0), c(!0), () => {
|
|
661
660
|
d.unsubscribe(), a(!1);
|
|
662
661
|
};
|
|
663
|
-
}, [a, c]), /* @__PURE__ */ l("div", { className: w.findReplaceDialogContainer, ref: r, children: i.replaceRevealed ? /* @__PURE__ */ l(
|
|
662
|
+
}, [a, c]), /* @__PURE__ */ l("div", { className: w.findReplaceDialogContainer, ref: r, children: i.replaceRevealed ? /* @__PURE__ */ l(Ht, { ref: s }) : /* @__PURE__ */ l(Vt, { ref: s }) });
|
|
664
663
|
}
|
|
665
|
-
function
|
|
664
|
+
function zt(t) {
|
|
666
665
|
const e = t.getCurrentLocale();
|
|
667
666
|
return ie(() => [
|
|
668
667
|
{ label: t.t("find-replace.dialog.find-scope.current-sheet"), value: Z.SUBUNIT },
|
|
669
668
|
{ label: t.t("find-replace.dialog.find-scope.workbook"), value: Z.UNIT }
|
|
670
669
|
], [e]);
|
|
671
670
|
}
|
|
672
|
-
function
|
|
671
|
+
function qt(t) {
|
|
673
672
|
const e = t.getCurrentLocale();
|
|
674
673
|
return ie(() => [
|
|
675
674
|
{ label: t.t("find-replace.dialog.find-direction.row"), value: q.ROW },
|
|
676
675
|
{ label: t.t("find-replace.dialog.find-direction.column"), value: q.COLUMN }
|
|
677
676
|
], [e]);
|
|
678
677
|
}
|
|
679
|
-
function
|
|
678
|
+
function Yt(t) {
|
|
680
679
|
const e = t.getCurrentLocale();
|
|
681
680
|
return ie(() => [
|
|
682
681
|
{ label: t.t("find-replace.dialog.find-by.value"), value: Y.VALUE },
|
|
@@ -686,28 +685,28 @@ function Jt(t) {
|
|
|
686
685
|
function T(t) {
|
|
687
686
|
return t.getContextValue(De);
|
|
688
687
|
}
|
|
689
|
-
function
|
|
688
|
+
function Zt(t) {
|
|
690
689
|
return t.getContextValue(Fe);
|
|
691
690
|
}
|
|
692
691
|
function Ae(t) {
|
|
693
692
|
return t.getContextValue(ye);
|
|
694
693
|
}
|
|
695
|
-
const
|
|
694
|
+
const k = "7_find-replace-shortcuts";
|
|
696
695
|
function se(t) {
|
|
697
696
|
return t.getContextValue(_e);
|
|
698
697
|
}
|
|
699
698
|
function ae(t) {
|
|
700
699
|
return !t.getContextValue(ge);
|
|
701
700
|
}
|
|
702
|
-
const
|
|
701
|
+
const Jt = {
|
|
703
702
|
id: x.id,
|
|
704
703
|
description: "find-replace.shortcut.open-find-dialog",
|
|
705
704
|
binding: M.F | I.CTRL_COMMAND,
|
|
706
|
-
group:
|
|
705
|
+
group: k,
|
|
707
706
|
preconditions(t) {
|
|
708
707
|
return !T(t) && se(t) && ae(t);
|
|
709
708
|
}
|
|
710
|
-
},
|
|
709
|
+
}, Qt = {
|
|
711
710
|
id: x.id,
|
|
712
711
|
description: "find-replace.shortcut.open-find-dialog",
|
|
713
712
|
binding: M.F | I.CTRL_COMMAND,
|
|
@@ -715,67 +714,67 @@ const Xt = {
|
|
|
715
714
|
preconditions(t) {
|
|
716
715
|
return !T(t) && se(t) && ae(t);
|
|
717
716
|
}
|
|
718
|
-
},
|
|
717
|
+
}, Xt = {
|
|
719
718
|
id: re.id,
|
|
720
719
|
description: "find-replace.shortcut.open-replace-dialog",
|
|
721
720
|
binding: M.H | I.CTRL_COMMAND,
|
|
722
721
|
mac: M.H | I.MAC_CTRL,
|
|
723
|
-
group:
|
|
722
|
+
group: k,
|
|
724
723
|
preconditions(t) {
|
|
725
|
-
return se(t) && ae(t) && (!T(t) || !
|
|
724
|
+
return se(t) && ae(t) && (!T(t) || !Zt(t));
|
|
726
725
|
}
|
|
727
|
-
},
|
|
728
|
-
id:
|
|
726
|
+
}, ei = {
|
|
727
|
+
id: Ee.id,
|
|
729
728
|
description: "find-replace.shortcut.go-to-next-match",
|
|
730
729
|
binding: M.ENTER,
|
|
731
|
-
group:
|
|
730
|
+
group: k,
|
|
732
731
|
priority: 1e3,
|
|
733
732
|
preconditions(t) {
|
|
734
733
|
return Ae(t) && T(t);
|
|
735
734
|
}
|
|
736
|
-
},
|
|
737
|
-
id:
|
|
735
|
+
}, ti = {
|
|
736
|
+
id: Oe.id,
|
|
738
737
|
description: "find-replace.shortcut.go-to-previous-match",
|
|
739
738
|
binding: M.ENTER | I.SHIFT,
|
|
740
|
-
group:
|
|
739
|
+
group: k,
|
|
741
740
|
priority: 1e3,
|
|
742
741
|
preconditions(t) {
|
|
743
742
|
return Ae(t) && T(t);
|
|
744
743
|
}
|
|
745
744
|
};
|
|
746
|
-
function
|
|
747
|
-
const e = t.get(
|
|
745
|
+
function ii(t) {
|
|
746
|
+
const e = t.get(X);
|
|
748
747
|
return {
|
|
749
748
|
id: x.id,
|
|
750
749
|
icon: "SearchIcon",
|
|
751
750
|
tooltip: "find-replace.toolbar",
|
|
752
|
-
type:
|
|
753
|
-
hidden$:
|
|
754
|
-
disabled$:
|
|
751
|
+
type: _t.BUTTON,
|
|
752
|
+
hidden$: pt(t, ct.UNIVER_SHEET),
|
|
753
|
+
disabled$: Se([
|
|
755
754
|
e.subscribeContextValue$(ge),
|
|
756
755
|
e.subscribeContextValue$(_e)
|
|
757
756
|
]).pipe(It(([n, i]) => n || !i))
|
|
758
757
|
};
|
|
759
758
|
}
|
|
760
|
-
const
|
|
759
|
+
const ni = {
|
|
761
760
|
[gt.OTHERS]: {
|
|
762
761
|
[x.id]: {
|
|
763
762
|
order: 2,
|
|
764
|
-
menuItemFactory:
|
|
763
|
+
menuItemFactory: ii
|
|
765
764
|
}
|
|
766
765
|
}
|
|
767
766
|
};
|
|
768
|
-
var
|
|
769
|
-
for (var r = i > 1 ? void 0 : i ?
|
|
770
|
-
(a = t[s]) && (r =
|
|
771
|
-
return
|
|
767
|
+
var ri = Object.getOwnPropertyDescriptor, si = (t, e, n, i) => {
|
|
768
|
+
for (var r = i > 1 ? void 0 : i ? ri(e, n) : e, s = t.length - 1, a; s >= 0; s--)
|
|
769
|
+
(a = t[s]) && (r = a(r) || r);
|
|
770
|
+
return r;
|
|
772
771
|
}, m = (t, e) => (n, i) => e(n, i, t);
|
|
773
|
-
const he = "DESKTOP_FIND_REPLACE_DIALOG", Le = 350,
|
|
772
|
+
const he = "DESKTOP_FIND_REPLACE_DIALOG", Le = 350, ai = 20, oi = -90;
|
|
774
773
|
let U = class extends lt {
|
|
775
|
-
constructor(e, n, i, r, s, a, c, d,
|
|
774
|
+
constructor(e, n, i, r, s, a, c, d, S, f) {
|
|
776
775
|
super();
|
|
777
776
|
o(this, "_closingListenerDisposable");
|
|
778
|
-
this._univerInstanceService = e, this._menuManagerService = n, this._shortcutService = i, this._commandService = r, this._findReplaceService = s, this._dialogService = a, this._layoutService = c, this._localeService = d, this._componentManager =
|
|
777
|
+
this._univerInstanceService = e, this._menuManagerService = n, this._shortcutService = i, this._commandService = r, this._findReplaceService = s, this._dialogService = a, this._layoutService = c, this._localeService = d, this._componentManager = S, this._injector = f, this._initCommands(), this._initUI(), this._initShortcuts();
|
|
779
778
|
}
|
|
780
779
|
dispose() {
|
|
781
780
|
var e;
|
|
@@ -785,8 +784,8 @@ let U = class extends lt {
|
|
|
785
784
|
[
|
|
786
785
|
x,
|
|
787
786
|
re,
|
|
788
|
-
Oe,
|
|
789
787
|
Ee,
|
|
788
|
+
Oe,
|
|
790
789
|
Te,
|
|
791
790
|
xe
|
|
792
791
|
].forEach((e) => {
|
|
@@ -795,15 +794,15 @@ let U = class extends lt {
|
|
|
795
794
|
}
|
|
796
795
|
_initShortcuts() {
|
|
797
796
|
[
|
|
798
|
-
ti,
|
|
799
797
|
Xt,
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
798
|
+
Jt,
|
|
799
|
+
Qt,
|
|
800
|
+
ti,
|
|
801
|
+
ei
|
|
803
802
|
].forEach((e) => this.disposeWithMe(this._shortcutService.registerShortcut(e)));
|
|
804
803
|
}
|
|
805
804
|
_initUI() {
|
|
806
|
-
this.disposeWithMe(this._componentManager.register("FindReplaceDialog",
|
|
805
|
+
this.disposeWithMe(this._componentManager.register("FindReplaceDialog", Kt)), this.disposeWithMe(this._componentManager.register("SearchIcon", Ie)), this._menuManagerService.mergeMenu(ni), this._findReplaceService.stateUpdates$.pipe(oe(this.dispose$)).subscribe((e) => {
|
|
807
806
|
e.revealed === !0 && this._openPanel();
|
|
808
807
|
});
|
|
809
808
|
}
|
|
@@ -815,7 +814,7 @@ let U = class extends lt {
|
|
|
815
814
|
title: { title: this._localeService.t("find-replace.dialog.title") },
|
|
816
815
|
children: { label: "FindReplaceDialog" },
|
|
817
816
|
destroyOnClose: !0,
|
|
818
|
-
defaultPosition:
|
|
817
|
+
defaultPosition: ci(),
|
|
819
818
|
preservePositionOnDestroy: !0,
|
|
820
819
|
onClose: () => this.closePanel()
|
|
821
820
|
}), this._closingListenerDisposable = A(this._univerInstanceService.focused$.pipe(oe(this.dispose$)).subscribe((e) => {
|
|
@@ -826,33 +825,33 @@ let U = class extends lt {
|
|
|
826
825
|
this._closingListenerDisposable && (this._closingListenerDisposable.dispose(), this._closingListenerDisposable = null, this._dialogService.close(he), this._findReplaceService.terminate(), queueMicrotask(() => this._layoutService.focus()));
|
|
827
826
|
}
|
|
828
827
|
};
|
|
829
|
-
U =
|
|
828
|
+
U = si([
|
|
830
829
|
m(0, pe),
|
|
831
|
-
m(1,
|
|
830
|
+
m(1, mt),
|
|
832
831
|
m(2, vt),
|
|
833
832
|
m(3, te),
|
|
834
833
|
m(4, g),
|
|
835
|
-
m(5,
|
|
836
|
-
m(6,
|
|
834
|
+
m(5, St),
|
|
835
|
+
m(6, ve),
|
|
837
836
|
m(7, D(B)),
|
|
838
|
-
m(8, D(
|
|
837
|
+
m(8, D(Ct)),
|
|
839
838
|
m(9, D(Q))
|
|
840
839
|
], U);
|
|
841
|
-
function
|
|
840
|
+
function ci() {
|
|
842
841
|
const { innerWidth: t } = window;
|
|
843
|
-
return { x: (t - Le) / 2 -
|
|
842
|
+
return { x: (t - Le) / 2 - ai, y: oi };
|
|
844
843
|
}
|
|
845
|
-
var
|
|
846
|
-
for (var r = i > 1 ? void 0 : i ?
|
|
847
|
-
(a = t[s]) && (r =
|
|
848
|
-
return
|
|
844
|
+
var li = Object.getOwnPropertyDescriptor, di = (t, e, n, i) => {
|
|
845
|
+
for (var r = i > 1 ? void 0 : i ? li(e, n) : e, s = t.length - 1, a; s >= 0; s--)
|
|
846
|
+
(a = t[s]) && (r = a(r) || r);
|
|
847
|
+
return r;
|
|
849
848
|
}, ue = (t, e) => (n, i) => e(n, i, t);
|
|
850
|
-
const
|
|
851
|
-
var
|
|
852
|
-
let fe = (
|
|
849
|
+
const hi = "UNIVER_FIND_REPLACE_PLUGIN";
|
|
850
|
+
var V;
|
|
851
|
+
let fe = (V = class extends ht {
|
|
853
852
|
constructor(t = de, e, n) {
|
|
854
853
|
super(), this._config = t, this._injector = e, this._configService = n;
|
|
855
|
-
const { ...i } =
|
|
854
|
+
const { ...i } = ut(
|
|
856
855
|
{},
|
|
857
856
|
de,
|
|
858
857
|
this._config
|
|
@@ -868,21 +867,21 @@ let fe = (k = class extends dt {
|
|
|
868
867
|
onRendered() {
|
|
869
868
|
this._injector.get(U);
|
|
870
869
|
}
|
|
871
|
-
}, o(
|
|
872
|
-
fe =
|
|
870
|
+
}, o(V, "pluginName", hi), V);
|
|
871
|
+
fe = di([
|
|
873
872
|
ue(1, D(Q)),
|
|
874
|
-
ue(2,
|
|
873
|
+
ue(2, dt)
|
|
875
874
|
], fe);
|
|
876
875
|
export {
|
|
877
876
|
Y as FindBy,
|
|
878
877
|
q as FindDirection,
|
|
879
|
-
|
|
878
|
+
Ci as FindModel,
|
|
880
879
|
U as FindReplaceController,
|
|
881
880
|
z as FindReplaceModel,
|
|
882
|
-
|
|
881
|
+
Ut as FindReplaceState,
|
|
883
882
|
Z as FindScope,
|
|
884
|
-
|
|
885
|
-
|
|
883
|
+
Ee as GoToNextMatchOperation,
|
|
884
|
+
Oe as GoToPreviousMatchOperation,
|
|
886
885
|
g as IFindReplaceService,
|
|
887
886
|
x as OpenFindDialogOperation,
|
|
888
887
|
re as OpenReplaceDialogOperation,
|
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("rxjs"),require("@univerjs/design"),require("@univerjs/engine-render"),require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/ui","rxjs","@univerjs/design","@univerjs/engine-render","react/jsx-runtime","react"],o):(l=typeof globalThis<"u"?globalThis:l||self,o(l.UniverFindReplace={},l.UniverCore,l.UniverUi,l.rxjs,l.UniverDesign,l.UniverEngineRender,l.React,l.React))})(this,function(l,o,c,m,p,re,h,f){"use strict";var lt=Object.defineProperty;var dt=(l,o,c)=>o in l?lt(l,o,{enumerable:!0,configurable:!0,writable:!0,value:c}):l[o]=c;var u=(l,o,c)=>dt(l,typeof o!="symbol"?o+"":o,c);var G;const oe="find-replace.config",H={};var M=function(){return M=Object.assign||function(n){for(var e,i=1,t=arguments.length;i<t;i++){e=arguments[i];for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&(n[a]=e[a])}return n},M.apply(this,arguments)},ce=function(n,e){var i={};for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&e.indexOf(t)<0&&(i[t]=n[t]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var a=0,t=Object.getOwnPropertySymbols(n);a<t.length;a++)e.indexOf(t[a])<0&&Object.prototype.propertyIsEnumerable.call(n,t[a])&&(i[t[a]]=n[t[a]]);return i},K=f.forwardRef(function(n,e){var i=n.icon,t=n.id,a=n.className,s=n.extend,r=ce(n,["icon","id","className","extend"]),d="univerjs-icon univerjs-icon-".concat(t," ").concat(a||"").trim(),_=f.useRef("_".concat(he()));return q(i,"".concat(t),{defIds:i.defIds,idSuffix:_.current},M({ref:e,className:d},r),s)});function q(n,e,i,t,a){return f.createElement(n.tag,M(M({key:e},le(n,i,a)),t),(de(n,i).children||[]).map(function(s,r){return q(s,"".concat(e,"-").concat(n.tag,"-").concat(r),i,void 0,a)}))}function le(n,e,i){var t=M({},n.attrs);i!=null&&i.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=i.colorChannel1);var a=e.defIds;return!a||a.length===0||(n.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+e.idSuffix),Object.entries(t).forEach(function(s){var r=s[0],d=s[1];typeof d=="string"&&(t[r]=d.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),t}function de(n,e){var i,t=e.defIds;return!t||t.length===0?n:n.tag==="defs"&&(!((i=n.children)===null||i===void 0)&&i.length)?M(M({},n),{children:n.children.map(function(a){return typeof a.attrs.id=="string"&&t&&t.indexOf(a.attrs.id)>-1?M(M({},a),{attrs:M(M({},a.attrs),{id:a.attrs.id+e.idSuffix})}):a})}):n}function he(){return Math.random().toString(36).substring(2,8)}K.displayName="UniverIcon";var ue={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_217_40",style:{maskType:"alpha"},width:17,height:17,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#D9D9D9",d:"M0.9 0.09H16.9V16.09H0.9z"}}]},{tag:"g",attrs:{mask:"url(#mask0_217_40)"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.39551 7.37266C2.39551 4.18105 4.98281 1.59375 8.17441 1.59375C11.366 1.59375 13.9533 4.18105 13.9533 7.37266C13.9533 8.72342 13.4898 9.96603 12.7133 10.95L15.1964 13.4331C15.4619 13.6986 15.4619 14.1291 15.1964 14.3946C14.9309 14.6601 14.5004 14.6601 14.2349 14.3946L11.7518 11.9115C10.7678 12.6881 9.52525 13.1516 8.17441 13.1516C4.98281 13.1516 2.39551 10.5642 2.39551 7.37266ZM8.17441 2.95349C5.73378 2.95349 3.75525 4.93202 3.75525 7.37266C3.75525 9.81333 5.73378 11.7918 8.17441 11.7918C10.6151 11.7918 12.5936 9.81333 12.5936 7.37266C12.5936 4.93202 10.6151 2.95349 8.17441 2.95349Z",fillRule:"evenodd",clipRule:"evenodd"}}]}]},z=f.forwardRef(function(n,e){return f.createElement(K,Object.assign({},n,{id:"search-single-16",ref:e,icon:ue}))});z.displayName="SearchSingle16";const Y="FIND_REPLACE_INPUT_FOCUS",Z="FIND_REPLACE_DIALOG_FOCUS",J="FIND_REPLACE_REPLACE_REVEALED";var fe=Object.defineProperty,pe=Object.getOwnPropertyDescriptor,Q=(n,e,i,t)=>{for(var a=t>1?void 0:t?pe(e,i):e,s=n.length-1,r;s>=0;s--)(r=n[s])&&(a=(t?r(e,i,a):r(a))||a);return t&&a&&fe(e,i,a),a},A=(n,e)=>(i,t)=>e(i,t,n);class _e extends o.Disposable{}const b=o.createIdentifier("find-replace.service");function ge(n){return typeof n.findString<"u"||typeof n.inputtingFindString<"u"||typeof n.findDirection<"u"||typeof n.matchesTheWholeCell<"u"||typeof n.caseSensitive<"u"||typeof n.findScope<"u"||typeof n.findBy<"u"}l.FindReplaceModel=class extends o.Disposable{constructor(i,t,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=i,this._providers=t,this._univerInstanceService=a,this.disposeWithMe(this._state.stateUpdates$.pipe(m.throttleTime(200,void 0,{leading:!0,trailing:!0})).subscribe(async s=>{const r=this._state.state;ge(s)&&(r.findString!==""&&!r.replaceRevealed?(await this._startSearching(),this._state.changeState({findCompleted:!0})):s.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 i=await this._startSearching();return this._state.changeState({findCompleted:!0}),i}async _startSearching(){if(!this._state.findString)return{results:[]};const i=Array.from(this._providers),t=this._findModels=(await Promise.all(i.map(s=>s.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 a=this._matches=t.map(s=>s.getMatches()).flat();return this.replaceables$.next(a.filter(s=>s.replaceable)),a.length?(this._moveToInitialMatch(t),this._state.changeState({matchesCount:a.length}),{results:a}):(this._state.changeState({matchesCount:0,matchesPosition:0}),{results:[]})}_stopSearching(){var i;this._providers.forEach(t=>t.terminate()),this._findModels=[],this._matches=[],this._matchingModel=null,(i=this._currentSearchingDisposables)==null||i.dispose(),this._currentSearchingDisposables=null,this.currentMatch$.next(null),this.replaceables$.next([]),this._state.changeState({findCompleted:!1,matchesCount:0,matchesPosition:0})}_subscribeToModelsChanges(i){const t=this._currentSearchingDisposables=new o.DisposableCollection,a=m.combineLatest(i.map(s=>s.matchesUpdate$)).pipe(m.debounceTime(220)).subscribe(([...s])=>{const r=this._matches=s.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([]))});i.forEach(s=>t.add(o.toDisposable(s.activelyChangingMatch$.subscribe(r=>{const d=this._matches.findIndex(_=>_===r);this._state.changeState({matchesPosition:d+1})})))),t.add(o.toDisposable(a))}async replace(){return this._matchingModel?this._matchingModel.replace(this._state.replaceString):!1}async replaceAll(){const i=await Promise.all(this._findModels.map(t=>t.replaceAll(this._state.replaceString))).then(t=>t.reduce((a,s)=>(a.success+=s.success,a.failure+=s.failure,a),{success:0,failure:0}));return i.failure===0&&this._stopSearching(),i}getCurrentMatch(){return this._state.matchesPosition>0?this._matches[this._state.matchesPosition-1]:null}_markMatch(i){const t=this._matches.findIndex(a=>a===i);this.currentMatch$.next(i),this._state.changeState({matchesPosition:t+1})}moveToNextMatch(){if(!this._matchingModel)return;const i=this._findModels.length===1,t=this._matchingModel.moveToNextMatch({loop:i});if(t)return this._markMatch(t),t;{const a=this._findModels.findIndex(s=>s===this._matchingModel);return this._moveToNextUnitMatch(a)}}_moveToNextUnitMatch(i){const t=this._findModels.length;for(let a=(i+1)%t;a!==i;){const s=this._findModels[a],r=s.moveToNextMatch({ignoreSelection:!0});if(r)return this._matchingModel=s,this._markMatch(r),r;a=(a+1)%t}if(this._matchingModel){const a=this._matchingModel.moveToNextMatch({ignoreSelection:!0});return a&&this._markMatch(a),a}}moveToPreviousMatch(){if(!this._matchingModel)return;const i=this._findModels.length===1,t=this._matchingModel.moveToPreviousMatch({loop:i});if(t){const a=this._matches.findIndex(s=>s===t);return this.currentMatch$.next(t),this._state.changeState({matchesPosition:a+1}),t}else{const a=this._findModels.length,s=this._findModels.findIndex(d=>d===this._matchingModel);for(let d=(s-1+a)%a;d!==s;){const _=this._findModels[d],S=_.moveToPreviousMatch({ignoreSelection:!0});if(S)return this._matchingModel=_,this._markMatch(S),S;d=(d-1)%a}const r=this._matchingModel.moveToPreviousMatch({ignoreSelection:!0});return r&&this._markMatch(r),r}}_moveToInitialMatch(i,t=!1){var r;const a=(r=this._univerInstanceService.getFocusedUnit())==null?void 0:r.getUnitId();if(!a)return-1;const s=i.findIndex(d=>d.unitId===a);if(s!==-1){this._matchingModel=i[s];const d=this._matchingModel.moveToNextMatch({stayIfOnMatch:!0,noFocus:t});if(d)return this._markMatch(d),s}return this._moveToNextUnitMatch(s),0}},l.FindReplaceModel=Q([A(2,o.IUniverInstanceService)],l.FindReplaceModel);var D=(n=>(n.ROW="row",n.COLUMN="column",n))(D||{}),T=(n=>(n.VALUE="value",n.FORMULA="formula",n))(T||{}),P=(n=>(n.SUBUNIT="subunit",n.UNIT="unit",n))(P||{});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 X{constructor(){u(this,"_stateUpdates$",new m.Subject);u(this,"stateUpdates$",this._stateUpdates$.asObservable());u(this,"_state$",new m.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 i=!1;const t={};typeof e.findString<"u"&&e.findString!==this._findString&&(this._findString=e.findString,t.findString=this._findString,i=!0),typeof e.revealed<"u"&&e.revealed!==this._revealed&&(this._revealed=e.revealed,t.revealed=e.revealed,i=!0),typeof e.replaceRevealed<"u"&&e.replaceRevealed!==this._replaceRevealed&&(this._replaceRevealed=e.replaceRevealed,t.replaceRevealed=e.replaceRevealed,i=!0),typeof e.replaceString<"u"&&e.replaceString!==this._replaceString&&(this._replaceString=e.replaceString,t.replaceString=e.replaceString,i=!0),typeof e.matchesCount<"u"&&e.matchesCount!==this._matchesCount&&(this._matchesCount=e.matchesCount,t.matchesCount=e.matchesCount,i=!0),typeof e.matchesPosition<"u"&&e.matchesPosition!==this._matchesPosition&&(this._matchesPosition=e.matchesPosition,t.matchesPosition=e.matchesPosition,i=!0),typeof e.findBy<"u"&&e.findBy!==this._findBy&&(this._findBy=e.findBy,t.findBy=e.findBy,i=!0),typeof e.findScope<"u"&&e.findScope!==this._findScope&&(this._findScope=e.findScope,t.findScope=e.findScope,i=!0),typeof e.findDirection<"u"&&e.findDirection!==this._findDirection&&(this._findDirection=e.findDirection,t.findDirection=e.findDirection,i=!0),typeof e.caseSensitive<"u"&&e.caseSensitive!==this._caseSensitive&&(this._caseSensitive=e.caseSensitive,t.caseSensitive=e.caseSensitive,i=!0),typeof e.matchesTheWholeCell<"u"&&e.matchesTheWholeCell!==this._matchesTheWholeCell&&(this._matchesTheWholeCell=e.matchesTheWholeCell,t.matchesTheWholeCell=e.matchesTheWholeCell,i=!0),typeof e.inputtingFindString<"u"&&e.inputtingFindString!==this._inputtingFindString&&(this._inputtingFindString=e.inputtingFindString,t.inputtingFindString=e.inputtingFindString,i=!0),typeof e.findCompleted<"u"&&e.findCompleted!==this._findCompleted&&(this._findCompleted=e.findCompleted,t.findCompleted=e.findCompleted,i=!0),i&&(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 x=class extends o.Disposable{constructor(e,i){super();u(this,"_providers",new Set);u(this,"_state",new X);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=i}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)}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 i=O();return e&&(i.replaceRevealed=!0),this._state.changeState(i),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(J,e)}_toggleDisplayRawFormula(e){this._contextService.setContextValue(re.RENDER_RAW_FORMULA_KEY,e)}};x=Q([A(0,o.Inject(o.Injector)),A(1,o.IContextService)],x);const U={id:"ui.command.replace-current-match",type:o.CommandType.COMMAND,handler:n=>n.get(b).replace()},me="CONFIRM_REPLACE_ALL",w={id:"ui.command.replace-all-matches",type:o.CommandType.COMMAND,handler:async n=>{const e=n.get(c.IConfirmService),i=n.get(o.LocaleService),t=n.get(c.IMessageService);if(!await e.confirm({id:me,title:{title:i.t("find-replace.replace.confirm.title")},cancelText:i.t("button.cancel"),confirmText:i.t("button.confirm")}))return!1;const s=await n.get(b).replaceAll(),{success:r,failure:d}=s;return d>0?(r===0?t.show({type:p.MessageType.Error,content:i.t("find-replace.replace.all-failure")}):t.show({type:p.MessageType.Warning,content:i.t("find-replace.replace.partial-success",`${r}`,`${d}`)}),!1):(t.show({type:p.MessageType.Success,content:i.t("find-replace.replace.all-success",`${r}`)}),!0)}},I={id:"ui.operation.open-find-dialog",type:o.CommandType.OPERATION,handler:n=>{const e=n.get(b);return e.revealed?e.focusFindInput():e.start(),!0}},E={id:"ui.operation.open-replace-dialog",type:o.CommandType.OPERATION,handler:n=>{const e=n.get(b);return e.revealed?e.replaceRevealed?e.focusFindInput():e.revealReplace():e.start(!0),!0}},B={type:o.CommandType.OPERATION,id:"ui.operation.go-to-next-match",handler:n=>(n.get(b).moveToNextMatch(),!0)},j={type:o.CommandType.OPERATION,id:"ui.operation.go-to-previous-match",handler:n=>(n.get(b).moveToPreviousMatch(),!0)},N={findReplaceDialogContainer:"univer-find-replace-dialog-container",findReplaceExpandContainer:"univer-find-replace-expand-container",buttonText:"univer-button-text",findReplaceButtonsGroup:"univer-find-replace-buttons-group",findReplaceButtonsGroupRight:"univer-find-replace-buttons-group-right"};function ee(n){const{findCompleted:e,localeService:i,matchesCount:t,matchesPosition:a,findString:s,findReplaceService:r,onChange:d,..._}=n,C=e&&t===0?i.t("find-replace.dialog.no-result"):t===0?" ":void 0;return h.jsx(p.InputWithSlot,{autoFocus:!0,placeholder:i.t("find-replace.dialog.find-placeholder"),slot:h.jsx(p.Pager,{loop:!0,text:C,value:a,total:t,onChange:v=>{a===t&&v===1?r.moveToNextMatch():a===1&&v===t||v<a?r.moveToPreviousMatch():r.moveToNextMatch()}}),value:s,onChange:v=>d==null?void 0:d(v),..._})}function te(n,e){const i=f.useCallback(()=>{var a;(a=document.querySelector(".univer-find-input input"))==null||a.focus()},[]),t=f.useCallback(()=>{const a=document.querySelectorAll(".univer-find-replace-dialog-container .univer-select-selection-search-input");return Array.from(a).some(s=>s===document.activeElement)},[]);return f.useImperativeHandle(e,()=>({focus:i,selectHasFocus:t})),f.useEffect(()=>{const a=n.focusSignal$.subscribe(()=>i());return()=>a.unsubscribe()},[n,i]),{focus:i,selectHasFocus:t}}const ve=f.forwardRef(function(e,i){const t=c.useDependency(o.LocaleService),a=c.useDependency(b),s=c.useDependency(o.ICommandService),r=c.useObservable(a.state$,void 0,!0),{findCompleted:d,findString:_,matchesCount:S,matchesPosition:C}=r,v=f.useCallback(()=>{s.executeCommand(E.id)},[s]),$=f.useCallback(R=>a.changeFindString(R),[a]);return te(a,i),h.jsxs(h.Fragment,{children:[h.jsx(ee,{findCompleted:d,className:"univer-find-input",matchesCount:S,matchesPosition:C,findReplaceService:a,localeService:t,findString:_,onChange:$}),h.jsx("div",{className:N.findReplaceExpandContainer,children:h.jsx(p.Button,{type:"text",size:"small",onClick:v,children:t.t("find-replace.dialog.advanced-finding")})})]})}),Se=f.forwardRef(function(e,i){const t=c.useDependency(b),a=c.useDependency(o.LocaleService),s=c.useDependency(o.ICommandService),r=c.useDependency(c.IMessageService),d=c.useObservable(t.currentMatch$,void 0,!0),_=c.useObservable(t.replaceables$,void 0,!0),S=c.useObservable(t.state$,void 0,!0),{matchesCount:C,matchesPosition:v,findString:$,inputtingFindString:R,replaceString:We,caseSensitive:Ge,matchesTheWholeCell:Ve,findDirection:He,findScope:Ke,findBy:qe,findCompleted:V}=S,ze=R.length===0,Ye=C===0||!(d!=null&&d.replaceable),Ze=_.length===0,Je=f.useCallback(g=>t.changeInputtingFindString(g),[t]),Qe=f.useCallback(g=>t.changeReplaceString(g),[t]),{focus:Xe}=te(t,i),et=f.useCallback(()=>{$===R?t.moveToNextMatch():(t.changeFindString(R),t.find())},[$,R,t]),tt=f.useCallback(()=>s.executeCommand(U.id),[s]),nt=f.useCallback(async()=>{await s.executeCommand(w.id),Xe()},[s]),it=f.useCallback(g=>{t.changeFindDirection(g)},[t]),at=f.useCallback(g=>{t.changeFindScope(g)},[t]),st=f.useCallback(g=>{t.changeFindBy(g)},[t]),rt=Me(a),ot=be(a),ct=ye(a);return f.useEffect(()=>{V&&C===0&&r.show({content:a.t("find-replace.dialog.no-match"),type:p.MessageType.Warning,duration:5e3})},[V,C,r,a]),h.jsxs(h.Fragment,{children:[h.jsx(p.FormLayout,{label:a.t("find-replace.dialog.find"),children:h.jsx(ee,{findCompleted:V,className:"univer-find-input",matchesCount:C,matchesPosition:v,findReplaceService:t,localeService:a,findString:R,onChange:Je})}),h.jsx(p.FormLayout,{label:a.t("find-replace.dialog.replace"),children:h.jsx(p.Input,{placeholder:a.t("find-replace.dialog.replace-placeholder"),value:We,onChange:g=>Qe(g)})}),h.jsx(p.FormLayout,{label:a.t("find-replace.dialog.find-direction.title"),children:h.jsx(p.Select,{value:He,options:ot,onChange:it})}),h.jsx(p.FormDualColumnLayout,{children:h.jsxs(h.Fragment,{children:[h.jsx(p.FormLayout,{label:a.t("find-replace.dialog.find-scope.title"),children:h.jsx(p.Select,{value:Ke,options:rt,onChange:at})}),h.jsx(p.FormLayout,{label:a.t("find-replace.dialog.find-by.title"),children:h.jsx(p.Select,{value:qe,options:ct,onChange:st})})]})}),h.jsx(p.FormDualColumnLayout,{children:h.jsxs(h.Fragment,{children:[h.jsx(p.FormLayout,{children:h.jsx(p.Checkbox,{checked:Ge,onChange:g=>{t.changeCaseSensitive(g)},children:a.t("find-replace.dialog.case-sensitive")})}),h.jsx(p.FormLayout,{children:h.jsx(p.Checkbox,{checked:Ve,onChange:g=>{t.changeMatchesTheWholeCell(g)},children:a.t("find-replace.dialog.match-the-whole-cell")})})]})}),h.jsxs("div",{className:N.findReplaceButtonsGroup,children:[h.jsx(p.Button,{type:"primary",onClick:et,disabled:ze,children:a.t("find-replace.dialog.find")}),h.jsxs("span",{className:N.findReplaceButtonsGroupRight,children:[h.jsx(p.Button,{disabled:Ye,onClick:tt,children:a.t("find-replace.dialog.replace")}),h.jsx(p.Button,{disabled:Ze,onClick:nt,children:a.t("find-replace.dialog.replace-all")})]})]})]})});function Ce(){const n=c.useDependency(b),e=c.useDependency(c.ILayoutService),i=c.useDependency(o.IContextService),t=c.useObservable(n.state$,void 0,!0),a=f.useRef(null);f.useEffect(()=>{let _;return a.current&&(_=e.registerContainerElement(a.current)),()=>_==null?void 0:_.dispose()},[e]);const s=f.useRef(null),r=f.useCallback(_=>i.setContextValue(Z,_),[i]),d=f.useCallback(_=>i.setContextValue(Y,_),[i]);return f.useEffect(()=>{var S;const _=m.fromEvent(document,"focusin").subscribe(C=>{var v;C.target&&((v=a.current)!=null&&v.contains(C.target))?r(!0):r(!1),!s.current||!s.current.selectHasFocus()?d(!0):d(!1)});return(S=s.current)==null||S.focus(),r(!0),d(!0),()=>{_.unsubscribe(),r(!1)}},[r,d]),h.jsx("div",{className:N.findReplaceDialogContainer,ref:a,children:t.replaceRevealed?h.jsx(Se,{ref:s}):h.jsx(ve,{ref:s})})}function Me(n){const e=n.getCurrentLocale();return f.useMemo(()=>[{label:n.t("find-replace.dialog.find-scope.current-sheet"),value:P.SUBUNIT},{label:n.t("find-replace.dialog.find-scope.workbook"),value:P.UNIT}],[e])}function be(n){const e=n.getCurrentLocale();return f.useMemo(()=>[{label:n.t("find-replace.dialog.find-direction.row"),value:D.ROW},{label:n.t("find-replace.dialog.find-direction.column"),value:D.COLUMN}],[e])}function ye(n){const e=n.getCurrentLocale();return f.useMemo(()=>[{label:n.t("find-replace.dialog.find-by.value"),value:T.VALUE},{label:n.t("find-replace.dialog.find-by.formula"),value:T.FORMULA}],[e])}function F(n){return n.getContextValue(Z)}function Re(n){return n.getContextValue(J)}function ne(n){return n.getContextValue(Y)}const L="7_find-replace-shortcuts";function k(n){return n.getContextValue(o.FOCUSING_SHEET)}function W(n){return!n.getContextValue(o.EDITOR_ACTIVATED)}const Ie={id:I.id,description:"find-replace.shortcut.open-find-dialog",binding:c.KeyCode.F|c.MetaKeys.CTRL_COMMAND,group:L,preconditions(n){return!F(n)&&k(n)&&W(n)}},Fe={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(n){return!F(n)&&k(n)&&W(n)}},De={id:E.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:L,preconditions(n){return k(n)&&W(n)&&(!F(n)||!Re(n))}},Te={id:B.id,description:"find-replace.shortcut.go-to-next-match",binding:c.KeyCode.ENTER,group:L,priority:1e3,preconditions(n){return ne(n)&&F(n)}},Pe={id:j.id,description:"find-replace.shortcut.go-to-previous-match",binding:c.KeyCode.ENTER|c.MetaKeys.SHIFT,group:L,priority:1e3,preconditions(n){return ne(n)&&F(n)}};function Oe(n){const e=n.get(o.IContextService);return{id:I.id,icon:"SearchIcon",tooltip:"find-replace.toolbar",type:c.MenuItemType.BUTTON,hidden$:c.getMenuHiddenObservable(n,o.UniverInstanceType.UNIVER_SHEET),disabled$:m.combineLatest([e.subscribeContextValue$(o.EDITOR_ACTIVATED),e.subscribeContextValue$(o.FOCUSING_SHEET)]).pipe(m.map(([i,t])=>i||!t))}}const Ee={[c.RibbonStartGroup.OTHERS]:{[I.id]:{order:2,menuItemFactory:Oe}}};var Ne=Object.defineProperty,Le=Object.getOwnPropertyDescriptor,$e=(n,e,i,t)=>{for(var a=t>1?void 0:t?Le(e,i):e,s=n.length-1,r;s>=0;s--)(r=n[s])&&(a=(t?r(e,i,a):r(a))||a);return t&&a&&Ne(e,i,a),a},y=(n,e)=>(i,t)=>e(i,t,n);const ie="DESKTOP_FIND_REPLACE_DIALOG",ae=350,Ae=20,xe=-90;l.FindReplaceController=class extends o.RxDisposable{constructor(i,t,a,s,r,d,_,S,C,v){super();u(this,"_closingListenerDisposable");this._univerInstanceService=i,this._menuManagerService=t,this._shortcutService=a,this._commandService=s,this._findReplaceService=r,this._dialogService=d,this._layoutService=_,this._localeService=S,this._componentManager=C,this._injector=v,this._initCommands(),this._initUI(),this._initShortcuts()}dispose(){var i;super.dispose(),(i=this._closingListenerDisposable)==null||i.dispose(),this._closingListenerDisposable=null}_initCommands(){[I,E,B,j,w,U].forEach(i=>{this.disposeWithMe(this._commandService.registerCommand(i))})}_initShortcuts(){[De,Ie,Fe,Pe,Te].forEach(i=>this.disposeWithMe(this._shortcutService.registerShortcut(i)))}_initUI(){this.disposeWithMe(this._componentManager.register("FindReplaceDialog",Ce)),this.disposeWithMe(this._componentManager.register("SearchIcon",z)),this._menuManagerService.mergeMenu(Ee),this._findReplaceService.stateUpdates$.pipe(m.takeUntil(this.dispose$)).subscribe(i=>{i.revealed===!0&&this._openPanel()})}_openPanel(){this._dialogService.open({id:ie,draggable:!0,width:ae,title:{title:this._localeService.t("find-replace.dialog.title")},children:{label:"FindReplaceDialog"},destroyOnClose:!0,defaultPosition:Ue(),preservePositionOnDestroy:!0,onClose:()=>this.closePanel()}),this._closingListenerDisposable=o.toDisposable(this._univerInstanceService.focused$.pipe(m.takeUntil(this.dispose$)).subscribe(i=>{(!i||!this._univerInstanceService.getUniverSheetInstance(i))&&this.closePanel()}))}closePanel(){this._closingListenerDisposable&&(this._closingListenerDisposable.dispose(),this._closingListenerDisposable=null,this._dialogService.close(ie),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus()))}},l.FindReplaceController=$e([y(0,o.IUniverInstanceService),y(1,c.IMenuManagerService),y(2,c.IShortcutService),y(3,o.ICommandService),y(4,b),y(5,c.IDialogService),y(6,c.ILayoutService),y(7,o.Inject(o.LocaleService)),y(8,o.Inject(c.ComponentManager)),y(9,o.Inject(o.Injector))],l.FindReplaceController);function Ue(){const{innerWidth:n}=window;return{x:(n-ae)/2-Ae,y:xe}}var we=Object.defineProperty,Be=Object.getOwnPropertyDescriptor,je=(n,e,i,t)=>{for(var a=t>1?void 0:t?Be(e,i):e,s=n.length-1,r;s>=0;s--)(r=n[s])&&(a=(t?r(e,i,a):r(a))||a);return t&&a&&we(e,i,a),a},se=(n,e)=>(i,t)=>e(i,t,n);const ke="UNIVER_FIND_REPLACE_PLUGIN";l.UniverFindReplacePlugin=(G=class extends o.Plugin{constructor(e=H,i,t){super(),this._config=e,this._injector=i,this._configService=t;const{...a}=o.merge({},H,this._config);this._configService.setConfig(oe,a)}onStarting(){[[l.FindReplaceController],[b,{useClass:x}]].forEach(e=>this._injector.add(e))}onRendered(){this._injector.get(l.FindReplaceController)}},u(G,"pluginName",ke),G),l.UniverFindReplacePlugin=je([se(1,o.Inject(o.Injector)),se(2,o.IConfigService)],l.UniverFindReplacePlugin),l.FindBy=T,l.FindDirection=D,l.FindModel=_e,l.FindReplaceState=X,l.FindScope=P,l.GoToNextMatchOperation=B,l.GoToPreviousMatchOperation=j,l.IFindReplaceService=b,l.OpenFindDialogOperation=I,l.OpenReplaceDialogOperation=E,l.ReplaceAllMatchesCommand=w,l.ReplaceCurrentMatchCommand=U,l.createInitFindReplaceState=O,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(l,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("@univerjs/core"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/design"),require("@univerjs/engine-render"),require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/ui","rxjs","@univerjs/design","@univerjs/engine-render","react/jsx-runtime","react"],r):(l=typeof globalThis<"u"?globalThis:l||self,r(l.UniverFindReplace={},l.UniverCore,l.UniverUi,l.rxjs,l.UniverDesign,l.UniverEngineRender,l.React,l.React))})(this,function(l,r,c,v,p,re,h,f){"use strict";var rt=Object.defineProperty;var ot=(l,r,c)=>r in l?rt(l,r,{enumerable:!0,configurable:!0,writable:!0,value:c}):l[r]=c;var u=(l,r,c)=>ot(l,typeof r!="symbol"?r+"":r,c);var G;const oe="find-replace.config",H={};var M=function(){return M=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++){e=arguments[i];for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&(t[a]=e[a])}return t},M.apply(this,arguments)},ce=function(t,e){var i={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(i[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var a=0,n=Object.getOwnPropertySymbols(t);a<n.length;a++)e.indexOf(n[a])<0&&Object.prototype.propertyIsEnumerable.call(t,n[a])&&(i[n[a]]=t[n[a]]);return i},K=f.forwardRef(function(t,e){var i=t.icon,n=t.id,a=t.className,s=t.extend,o=ce(t,["icon","id","className","extend"]),d="univerjs-icon univerjs-icon-".concat(n," ").concat(a||"").trim(),_=f.useRef("_".concat(he()));return q(i,"".concat(n),{defIds:i.defIds,idSuffix:_.current},M({ref:e,className:d},o),s)});function q(t,e,i,n,a){return f.createElement(t.tag,M(M({key:e},le(t,i,a)),n),(de(t,i).children||[]).map(function(s,o){return q(s,"".concat(e,"-").concat(t.tag,"-").concat(o),i,void 0,a)}))}function le(t,e,i){var n=M({},t.attrs);i!=null&&i.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=i.colorChannel1);var a=e.defIds;return!a||a.length===0||(t.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+e.idSuffix),Object.entries(n).forEach(function(s){var o=s[0],d=s[1];typeof d=="string"&&(n[o]=d.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),n}function de(t,e){var i,n=e.defIds;return!n||n.length===0?t:t.tag==="defs"&&(!((i=t.children)===null||i===void 0)&&i.length)?M(M({},t),{children:t.children.map(function(a){return typeof a.attrs.id=="string"&&n&&n.indexOf(a.attrs.id)>-1?M(M({},a),{attrs:M(M({},a.attrs),{id:a.attrs.id+e.idSuffix})}):a})}):t}function he(){return Math.random().toString(36).substring(2,8)}K.displayName="UniverIcon";var ue={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_217_40",style:{maskType:"alpha"},width:17,height:17,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#D9D9D9",d:"M0.9 0.09H16.9V16.09H0.9z"}}]},{tag:"g",attrs:{mask:"url(#mask0_217_40)"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.39551 7.37266C2.39551 4.18105 4.98281 1.59375 8.17441 1.59375C11.366 1.59375 13.9533 4.18105 13.9533 7.37266C13.9533 8.72342 13.4898 9.96603 12.7133 10.95L15.1964 13.4331C15.4619 13.6986 15.4619 14.1291 15.1964 14.3946C14.9309 14.6601 14.5004 14.6601 14.2349 14.3946L11.7518 11.9115C10.7678 12.6881 9.52525 13.1516 8.17441 13.1516C4.98281 13.1516 2.39551 10.5642 2.39551 7.37266ZM8.17441 2.95349C5.73378 2.95349 3.75525 4.93202 3.75525 7.37266C3.75525 9.81333 5.73378 11.7918 8.17441 11.7918C10.6151 11.7918 12.5936 9.81333 12.5936 7.37266C12.5936 4.93202 10.6151 2.95349 8.17441 2.95349Z",fillRule:"evenodd",clipRule:"evenodd"}}]}]},z=f.forwardRef(function(t,e){return f.createElement(K,Object.assign({},t,{id:"search-single-16",ref:e,icon:ue}))});z.displayName="SearchSingle16";const Y="FIND_REPLACE_INPUT_FOCUS",Z="FIND_REPLACE_DIALOG_FOCUS",J="FIND_REPLACE_REPLACE_REVEALED";var fe=Object.getOwnPropertyDescriptor,Q=(t,e,i,n)=>{for(var a=n>1?void 0:n?fe(e,i):e,s=t.length-1,o;s>=0;s--)(o=t[s])&&(a=o(a)||a);return a},A=(t,e)=>(i,n)=>e(i,n,t);class pe extends r.Disposable{}const b=r.createIdentifier("find-replace.service");function _e(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"}l.FindReplaceModel=class extends r.Disposable{constructor(i,n,a){super();u(this,"currentMatch$",new v.BehaviorSubject(null));u(this,"replaceables$",new v.BehaviorSubject([]));u(this,"_findModels",[]);u(this,"_matchingModel",null);u(this,"_matches",[]);u(this,"_currentSearchingDisposables",null);this._state=i,this._providers=n,this._univerInstanceService=a,this.disposeWithMe(this._state.stateUpdates$.pipe(v.throttleTime(200,void 0,{leading:!0,trailing:!0})).subscribe(async s=>{const o=this._state.state;_e(s)&&(o.findString!==""&&!o.replaceRevealed?(await this._startSearching(),this._state.changeState({findCompleted:!0})):s.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({...P(),revealed:!1})}async start(){if(!this._state.findString)return{results:[]};const i=await this._startSearching();return this._state.changeState({findCompleted:!0}),i}async _startSearching(){if(!this._state.findString)return{results:[]};const i=Array.from(this._providers),n=this._findModels=(await Promise.all(i.map(s=>s.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(n);const a=this._matches=n.map(s=>s.getMatches()).flat();return this.replaceables$.next(a.filter(s=>s.replaceable)),a.length?(this._moveToInitialMatch(n),this._state.changeState({matchesCount:a.length}),{results:a}):(this._state.changeState({matchesCount:0,matchesPosition:0}),{results:[]})}_stopSearching(){var i;this._providers.forEach(n=>n.terminate()),this._findModels=[],this._matches=[],this._matchingModel=null,(i=this._currentSearchingDisposables)==null||i.dispose(),this._currentSearchingDisposables=null,this.currentMatch$.next(null),this.replaceables$.next([]),this._state.changeState({findCompleted:!1,matchesCount:0,matchesPosition:0})}_subscribeToModelsChanges(i){const n=this._currentSearchingDisposables=new r.DisposableCollection,a=v.combineLatest(i.map(s=>s.matchesUpdate$)).pipe(v.debounceTime(220)).subscribe(([...s])=>{const o=this._matches=s.flat();o.length?(this._moveToInitialMatch(this._findModels,!0),this._state.changeState({matchesCount:o.length}),this.replaceables$.next(o.filter(d=>d.replaceable))):(this._state.changeState({matchesCount:0,matchesPosition:0}),this.replaceables$.next([]))});i.forEach(s=>n.add(r.toDisposable(s.activelyChangingMatch$.subscribe(o=>{const d=this._matches.findIndex(_=>_===o);this._state.changeState({matchesPosition:d+1})})))),n.add(r.toDisposable(a))}async replace(){return this._matchingModel?this._matchingModel.replace(this._state.replaceString):!1}async replaceAll(){const i=await Promise.all(this._findModels.map(n=>n.replaceAll(this._state.replaceString))).then(n=>n.reduce((a,s)=>(a.success+=s.success,a.failure+=s.failure,a),{success:0,failure:0}));return i.failure===0&&this._stopSearching(),i}getCurrentMatch(){return this._state.matchesPosition>0?this._matches[this._state.matchesPosition-1]:null}_markMatch(i){const n=this._matches.findIndex(a=>a===i);this.currentMatch$.next(i),this._state.changeState({matchesPosition:n+1})}moveToNextMatch(){if(!this._matchingModel)return;const i=this._findModels.length===1,n=this._matchingModel.moveToNextMatch({loop:i});if(n)return this._markMatch(n),n;{const a=this._findModels.findIndex(s=>s===this._matchingModel);return this._moveToNextUnitMatch(a)}}_moveToNextUnitMatch(i){const n=this._findModels.length;for(let a=(i+1)%n;a!==i;){const s=this._findModels[a],o=s.moveToNextMatch({ignoreSelection:!0});if(o)return this._matchingModel=s,this._markMatch(o),o;a=(a+1)%n}if(this._matchingModel){const a=this._matchingModel.moveToNextMatch({ignoreSelection:!0});return a&&this._markMatch(a),a}}moveToPreviousMatch(){if(!this._matchingModel)return;const i=this._findModels.length===1,n=this._matchingModel.moveToPreviousMatch({loop:i});if(n){const a=this._matches.findIndex(s=>s===n);return this.currentMatch$.next(n),this._state.changeState({matchesPosition:a+1}),n}else{const a=this._findModels.length,s=this._findModels.findIndex(d=>d===this._matchingModel);for(let d=(s-1+a)%a;d!==s;){const _=this._findModels[d],S=_.moveToPreviousMatch({ignoreSelection:!0});if(S)return this._matchingModel=_,this._markMatch(S),S;d=(d-1)%a}const o=this._matchingModel.moveToPreviousMatch({ignoreSelection:!0});return o&&this._markMatch(o),o}}_moveToInitialMatch(i,n=!1){var o;const a=(o=this._univerInstanceService.getFocusedUnit())==null?void 0:o.getUnitId();if(!a)return-1;const s=i.findIndex(d=>d.unitId===a);if(s!==-1){this._matchingModel=i[s];const d=this._matchingModel.moveToNextMatch({stayIfOnMatch:!0,noFocus:n});if(d)return this._markMatch(d),s}return this._moveToNextUnitMatch(s),0}},l.FindReplaceModel=Q([A(2,r.IUniverInstanceService)],l.FindReplaceModel);var D=(t=>(t.ROW="row",t.COLUMN="column",t))(D||{}),T=(t=>(t.VALUE="value",t.FORMULA="formula",t))(T||{}),O=(t=>(t.SUBUNIT="subunit",t.UNIT="unit",t))(O||{});function P(){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 X{constructor(){u(this,"_stateUpdates$",new v.Subject);u(this,"stateUpdates$",this._stateUpdates$.asObservable());u(this,"_state$",new v.BehaviorSubject(P()));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 i=!1;const n={};typeof e.findString<"u"&&e.findString!==this._findString&&(this._findString=e.findString,n.findString=this._findString,i=!0),typeof e.revealed<"u"&&e.revealed!==this._revealed&&(this._revealed=e.revealed,n.revealed=e.revealed,i=!0),typeof e.replaceRevealed<"u"&&e.replaceRevealed!==this._replaceRevealed&&(this._replaceRevealed=e.replaceRevealed,n.replaceRevealed=e.replaceRevealed,i=!0),typeof e.replaceString<"u"&&e.replaceString!==this._replaceString&&(this._replaceString=e.replaceString,n.replaceString=e.replaceString,i=!0),typeof e.matchesCount<"u"&&e.matchesCount!==this._matchesCount&&(this._matchesCount=e.matchesCount,n.matchesCount=e.matchesCount,i=!0),typeof e.matchesPosition<"u"&&e.matchesPosition!==this._matchesPosition&&(this._matchesPosition=e.matchesPosition,n.matchesPosition=e.matchesPosition,i=!0),typeof e.findBy<"u"&&e.findBy!==this._findBy&&(this._findBy=e.findBy,n.findBy=e.findBy,i=!0),typeof e.findScope<"u"&&e.findScope!==this._findScope&&(this._findScope=e.findScope,n.findScope=e.findScope,i=!0),typeof e.findDirection<"u"&&e.findDirection!==this._findDirection&&(this._findDirection=e.findDirection,n.findDirection=e.findDirection,i=!0),typeof e.caseSensitive<"u"&&e.caseSensitive!==this._caseSensitive&&(this._caseSensitive=e.caseSensitive,n.caseSensitive=e.caseSensitive,i=!0),typeof e.matchesTheWholeCell<"u"&&e.matchesTheWholeCell!==this._matchesTheWholeCell&&(this._matchesTheWholeCell=e.matchesTheWholeCell,n.matchesTheWholeCell=e.matchesTheWholeCell,i=!0),typeof e.inputtingFindString<"u"&&e.inputtingFindString!==this._inputtingFindString&&(this._inputtingFindString=e.inputtingFindString,n.inputtingFindString=e.inputtingFindString,i=!0),typeof e.findCompleted<"u"&&e.findCompleted!==this._findCompleted&&(this._findCompleted=e.findCompleted,n.findCompleted=e.findCompleted,i=!0),i&&(this._state$.next({caseSensitive:this._caseSensitive,findBy:this._findBy,findCompleted:this._findCompleted,findDirection:this._findDirection,findScope:this._findScope,findString:this._findString,inputtingFindString:this._inputtingFindString,matchesCount:this._matchesCount,matchesPosition:this._matchesPosition,matchesTheWholeCell:this._matchesTheWholeCell,replaceRevealed:this._replaceRevealed,revealed:this._revealed}),this._stateUpdates$.next(n))}}let x=class extends r.Disposable{constructor(e,i){super();u(this,"_providers",new Set);u(this,"_state",new X);u(this,"_model");u(this,"_currentMatch$",new v.BehaviorSubject(null));u(this,"currentMatch$",this._currentMatch$.asObservable());u(this,"_replaceables$",new v.BehaviorSubject([]));u(this,"replaceables$",this._replaceables$.asObservable());u(this,"_focusSignal$",new v.Subject);u(this,"focusSignal$",this._focusSignal$.asObservable());this._injector=e,this._contextService=i}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)}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(n=>this._currentMatch$.next(n)),this._model.replaceables$.subscribe(n=>this._replaceables$.next(n));const i=P();return e&&(i.replaceRevealed=!0),this._state.changeState(i),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),r.toDisposable(()=>this._providers.delete(e))}_toggleRevealReplace(e){this._contextService.setContextValue(J,e)}_toggleDisplayRawFormula(e){this._contextService.setContextValue(re.RENDER_RAW_FORMULA_KEY,e)}};x=Q([A(0,r.Inject(r.Injector)),A(1,r.IContextService)],x);const U={id:"ui.command.replace-current-match",type:r.CommandType.COMMAND,handler:t=>t.get(b).replace()},ge="CONFIRM_REPLACE_ALL",w={id:"ui.command.replace-all-matches",type:r.CommandType.COMMAND,handler:async t=>{const e=t.get(c.IConfirmService),i=t.get(r.LocaleService),n=t.get(c.IMessageService);if(!await e.confirm({id:ge,title:{title:i.t("find-replace.replace.confirm.title")},cancelText:i.t("button.cancel"),confirmText:i.t("button.confirm")}))return!1;const s=await t.get(b).replaceAll(),{success:o,failure:d}=s;return d>0?(o===0?n.show({type:p.MessageType.Error,content:i.t("find-replace.replace.all-failure")}):n.show({type:p.MessageType.Warning,content:i.t("find-replace.replace.partial-success",`${o}`,`${d}`)}),!1):(n.show({type:p.MessageType.Success,content:i.t("find-replace.replace.all-success",`${o}`)}),!0)}},I={id:"ui.operation.open-find-dialog",type:r.CommandType.OPERATION,handler:t=>{const e=t.get(b);return e.revealed?e.focusFindInput():e.start(),!0}},E={id:"ui.operation.open-replace-dialog",type:r.CommandType.OPERATION,handler:t=>{const e=t.get(b);return e.revealed?e.replaceRevealed?e.focusFindInput():e.revealReplace():e.start(!0),!0}},B={type:r.CommandType.OPERATION,id:"ui.operation.go-to-next-match",handler:t=>(t.get(b).moveToNextMatch(),!0)},k={type:r.CommandType.OPERATION,id:"ui.operation.go-to-previous-match",handler:t=>(t.get(b).moveToPreviousMatch(),!0)},N={findReplaceDialogContainer:"univer-find-replace-dialog-container",findReplaceExpandContainer:"univer-find-replace-expand-container",findReplaceButtonsGroup:"univer-find-replace-buttons-group",findReplaceButtonsGroupRight:"univer-find-replace-buttons-group-right"};function ee(t){const{findCompleted:e,localeService:i,matchesCount:n,matchesPosition:a,findString:s,findReplaceService:o,onChange:d,..._}=t,C=e&&n===0?i.t("find-replace.dialog.no-result"):n===0?" ":void 0;return h.jsx(p.InputWithSlot,{autoFocus:!0,placeholder:i.t("find-replace.dialog.find-placeholder"),slot:h.jsx(p.Pager,{loop:!0,text:C,value:a,total:n,onChange:m=>{a===n&&m===1?o.moveToNextMatch():a===1&&m===n||m<a?o.moveToPreviousMatch():o.moveToNextMatch()}}),value:s,onChange:m=>d==null?void 0:d(m),..._})}function te(t,e){const i=f.useCallback(()=>{var a;(a=document.querySelector(".univer-find-input input"))==null||a.focus()},[]),n=f.useCallback(()=>{const a=document.querySelectorAll(".univer-find-replace-dialog-container .univer-select-selection-search-input");return Array.from(a).some(s=>s===document.activeElement)},[]);return f.useImperativeHandle(e,()=>({focus:i,selectHasFocus:n})),f.useEffect(()=>{const a=t.focusSignal$.subscribe(()=>i());return()=>a.unsubscribe()},[t,i]),{focus:i,selectHasFocus:n}}const ve=f.forwardRef(function(e,i){const n=c.useDependency(r.LocaleService),a=c.useDependency(b),s=c.useDependency(r.ICommandService),o=c.useObservable(a.state$,void 0,!0),{findCompleted:d,findString:_,matchesCount:S,matchesPosition:C}=o,m=f.useCallback(()=>{s.executeCommand(E.id)},[s]),$=f.useCallback(R=>a.changeFindString(R),[a]);return te(a,i),h.jsxs(h.Fragment,{children:[h.jsx(ee,{findCompleted:d,className:"univer-find-input",matchesCount:S,matchesPosition:C,findReplaceService:a,localeService:n,findString:_,onChange:$}),h.jsx("div",{className:N.findReplaceExpandContainer,children:h.jsx(p.Button,{type:"text",size:"small",onClick:m,children:n.t("find-replace.dialog.advanced-finding")})})]})}),me=f.forwardRef(function(e,i){const n=c.useDependency(b),a=c.useDependency(r.LocaleService),s=c.useDependency(r.ICommandService),o=c.useDependency(c.IMessageService),d=c.useObservable(n.currentMatch$,void 0,!0),_=c.useObservable(n.replaceables$,void 0,!0),S=c.useObservable(n.state$,void 0,!0),{matchesCount:C,matchesPosition:m,findString:$,inputtingFindString:R,replaceString:Be,caseSensitive:ke,matchesTheWholeCell:je,findDirection:We,findScope:Ge,findBy:Ve,findCompleted:V}=S,He=R.length===0,Ke=C===0||!(d!=null&&d.replaceable),qe=_.length===0,ze=f.useCallback(g=>n.changeInputtingFindString(g),[n]),Ye=f.useCallback(g=>n.changeReplaceString(g),[n]),{focus:Ze}=te(n,i),Je=f.useCallback(()=>{$===R?n.moveToNextMatch():(n.changeFindString(R),n.find())},[$,R,n]),Qe=f.useCallback(()=>s.executeCommand(U.id),[s]),Xe=f.useCallback(async()=>{await s.executeCommand(w.id),Ze()},[s]),et=f.useCallback(g=>{n.changeFindDirection(g)},[n]),tt=f.useCallback(g=>{n.changeFindScope(g)},[n]),nt=f.useCallback(g=>{n.changeFindBy(g)},[n]),it=Ce(a),at=Me(a),st=be(a);return f.useEffect(()=>{V&&C===0&&o.show({content:a.t("find-replace.dialog.no-match"),type:p.MessageType.Warning,duration:5e3})},[V,C,o,a]),h.jsxs(h.Fragment,{children:[h.jsx(p.FormLayout,{label:a.t("find-replace.dialog.find"),children:h.jsx(ee,{findCompleted:V,className:"univer-find-input",matchesCount:C,matchesPosition:m,findReplaceService:n,localeService:a,findString:R,onChange:ze})}),h.jsx(p.FormLayout,{label:a.t("find-replace.dialog.replace"),children:h.jsx(p.Input,{placeholder:a.t("find-replace.dialog.replace-placeholder"),value:Be,onChange:g=>Ye(g)})}),h.jsx(p.FormLayout,{label:a.t("find-replace.dialog.find-direction.title"),children:h.jsx(p.Select,{value:We,options:at,onChange:et})}),h.jsx(p.FormDualColumnLayout,{children:h.jsxs(h.Fragment,{children:[h.jsx(p.FormLayout,{label:a.t("find-replace.dialog.find-scope.title"),children:h.jsx(p.Select,{value:Ge,options:it,onChange:tt})}),h.jsx(p.FormLayout,{label:a.t("find-replace.dialog.find-by.title"),children:h.jsx(p.Select,{value:Ve,options:st,onChange:nt})})]})}),h.jsx(p.FormDualColumnLayout,{children:h.jsxs(h.Fragment,{children:[h.jsx(p.FormLayout,{children:h.jsx(p.Checkbox,{checked:ke,onChange:g=>{n.changeCaseSensitive(g)},children:a.t("find-replace.dialog.case-sensitive")})}),h.jsx(p.FormLayout,{children:h.jsx(p.Checkbox,{checked:je,onChange:g=>{n.changeMatchesTheWholeCell(g)},children:a.t("find-replace.dialog.match-the-whole-cell")})})]})}),h.jsxs("div",{className:N.findReplaceButtonsGroup,children:[h.jsx(p.Button,{type:"primary",onClick:Je,disabled:He,children:a.t("find-replace.dialog.find")}),h.jsxs("span",{className:N.findReplaceButtonsGroupRight,children:[h.jsx(p.Button,{disabled:Ke,onClick:Qe,children:a.t("find-replace.dialog.replace")}),h.jsx(p.Button,{disabled:qe,onClick:Xe,children:a.t("find-replace.dialog.replace-all")})]})]})]})});function Se(){const t=c.useDependency(b),e=c.useDependency(c.ILayoutService),i=c.useDependency(r.IContextService),n=c.useObservable(t.state$,void 0,!0),a=f.useRef(null);f.useEffect(()=>{let _;return a.current&&(_=e.registerContainerElement(a.current)),()=>_==null?void 0:_.dispose()},[e]);const s=f.useRef(null),o=f.useCallback(_=>i.setContextValue(Z,_),[i]),d=f.useCallback(_=>i.setContextValue(Y,_),[i]);return f.useEffect(()=>{var S;const _=v.fromEvent(document,"focusin").subscribe(C=>{var m;C.target&&((m=a.current)!=null&&m.contains(C.target))?o(!0):o(!1),!s.current||!s.current.selectHasFocus()?d(!0):d(!1)});return(S=s.current)==null||S.focus(),o(!0),d(!0),()=>{_.unsubscribe(),o(!1)}},[o,d]),h.jsx("div",{className:N.findReplaceDialogContainer,ref:a,children:n.replaceRevealed?h.jsx(me,{ref:s}):h.jsx(ve,{ref:s})})}function Ce(t){const e=t.getCurrentLocale();return f.useMemo(()=>[{label:t.t("find-replace.dialog.find-scope.current-sheet"),value:O.SUBUNIT},{label:t.t("find-replace.dialog.find-scope.workbook"),value:O.UNIT}],[e])}function Me(t){const e=t.getCurrentLocale();return f.useMemo(()=>[{label:t.t("find-replace.dialog.find-direction.row"),value:D.ROW},{label:t.t("find-replace.dialog.find-direction.column"),value:D.COLUMN}],[e])}function be(t){const e=t.getCurrentLocale();return f.useMemo(()=>[{label:t.t("find-replace.dialog.find-by.value"),value:T.VALUE},{label:t.t("find-replace.dialog.find-by.formula"),value:T.FORMULA}],[e])}function F(t){return t.getContextValue(Z)}function ye(t){return t.getContextValue(J)}function ne(t){return t.getContextValue(Y)}const L="7_find-replace-shortcuts";function j(t){return t.getContextValue(r.FOCUSING_SHEET)}function W(t){return!t.getContextValue(r.EDITOR_ACTIVATED)}const Re={id:I.id,description:"find-replace.shortcut.open-find-dialog",binding:c.KeyCode.F|c.MetaKeys.CTRL_COMMAND,group:L,preconditions(t){return!F(t)&&j(t)&&W(t)}},Ie={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(t){return!F(t)&&j(t)&&W(t)}},Fe={id:E.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:L,preconditions(t){return j(t)&&W(t)&&(!F(t)||!ye(t))}},De={id:B.id,description:"find-replace.shortcut.go-to-next-match",binding:c.KeyCode.ENTER,group:L,priority:1e3,preconditions(t){return ne(t)&&F(t)}},Te={id:k.id,description:"find-replace.shortcut.go-to-previous-match",binding:c.KeyCode.ENTER|c.MetaKeys.SHIFT,group:L,priority:1e3,preconditions(t){return ne(t)&&F(t)}};function Oe(t){const e=t.get(r.IContextService);return{id:I.id,icon:"SearchIcon",tooltip:"find-replace.toolbar",type:c.MenuItemType.BUTTON,hidden$:c.getMenuHiddenObservable(t,r.UniverInstanceType.UNIVER_SHEET),disabled$:v.combineLatest([e.subscribeContextValue$(r.EDITOR_ACTIVATED),e.subscribeContextValue$(r.FOCUSING_SHEET)]).pipe(v.map(([i,n])=>i||!n))}}const Pe={[c.RibbonStartGroup.OTHERS]:{[I.id]:{order:2,menuItemFactory:Oe}}};var Ee=Object.getOwnPropertyDescriptor,Ne=(t,e,i,n)=>{for(var a=n>1?void 0:n?Ee(e,i):e,s=t.length-1,o;s>=0;s--)(o=t[s])&&(a=o(a)||a);return a},y=(t,e)=>(i,n)=>e(i,n,t);const ie="DESKTOP_FIND_REPLACE_DIALOG",ae=350,Le=20,$e=-90;l.FindReplaceController=class extends r.RxDisposable{constructor(i,n,a,s,o,d,_,S,C,m){super();u(this,"_closingListenerDisposable");this._univerInstanceService=i,this._menuManagerService=n,this._shortcutService=a,this._commandService=s,this._findReplaceService=o,this._dialogService=d,this._layoutService=_,this._localeService=S,this._componentManager=C,this._injector=m,this._initCommands(),this._initUI(),this._initShortcuts()}dispose(){var i;super.dispose(),(i=this._closingListenerDisposable)==null||i.dispose(),this._closingListenerDisposable=null}_initCommands(){[I,E,B,k,w,U].forEach(i=>{this.disposeWithMe(this._commandService.registerCommand(i))})}_initShortcuts(){[Fe,Re,Ie,Te,De].forEach(i=>this.disposeWithMe(this._shortcutService.registerShortcut(i)))}_initUI(){this.disposeWithMe(this._componentManager.register("FindReplaceDialog",Se)),this.disposeWithMe(this._componentManager.register("SearchIcon",z)),this._menuManagerService.mergeMenu(Pe),this._findReplaceService.stateUpdates$.pipe(v.takeUntil(this.dispose$)).subscribe(i=>{i.revealed===!0&&this._openPanel()})}_openPanel(){this._dialogService.open({id:ie,draggable:!0,width:ae,title:{title:this._localeService.t("find-replace.dialog.title")},children:{label:"FindReplaceDialog"},destroyOnClose:!0,defaultPosition:Ae(),preservePositionOnDestroy:!0,onClose:()=>this.closePanel()}),this._closingListenerDisposable=r.toDisposable(this._univerInstanceService.focused$.pipe(v.takeUntil(this.dispose$)).subscribe(i=>{(!i||!this._univerInstanceService.getUniverSheetInstance(i))&&this.closePanel()}))}closePanel(){this._closingListenerDisposable&&(this._closingListenerDisposable.dispose(),this._closingListenerDisposable=null,this._dialogService.close(ie),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus()))}},l.FindReplaceController=Ne([y(0,r.IUniverInstanceService),y(1,c.IMenuManagerService),y(2,c.IShortcutService),y(3,r.ICommandService),y(4,b),y(5,c.IDialogService),y(6,c.ILayoutService),y(7,r.Inject(r.LocaleService)),y(8,r.Inject(c.ComponentManager)),y(9,r.Inject(r.Injector))],l.FindReplaceController);function Ae(){const{innerWidth:t}=window;return{x:(t-ae)/2-Le,y:$e}}var xe=Object.getOwnPropertyDescriptor,Ue=(t,e,i,n)=>{for(var a=n>1?void 0:n?xe(e,i):e,s=t.length-1,o;s>=0;s--)(o=t[s])&&(a=o(a)||a);return a},se=(t,e)=>(i,n)=>e(i,n,t);const we="UNIVER_FIND_REPLACE_PLUGIN";l.UniverFindReplacePlugin=(G=class extends r.Plugin{constructor(e=H,i,n){super(),this._config=e,this._injector=i,this._configService=n;const{...a}=r.merge({},H,this._config);this._configService.setConfig(oe,a)}onStarting(){[[l.FindReplaceController],[b,{useClass:x}]].forEach(e=>this._injector.add(e))}onRendered(){this._injector.get(l.FindReplaceController)}},u(G,"pluginName",we),G),l.UniverFindReplacePlugin=Ue([se(1,r.Inject(r.Injector)),se(2,r.IConfigService)],l.UniverFindReplacePlugin),l.FindBy=T,l.FindDirection=D,l.FindModel=pe,l.FindReplaceState=X,l.FindScope=O,l.GoToNextMatchOperation=B,l.GoToPreviousMatchOperation=k,l.IFindReplaceService=b,l.OpenFindDialogOperation=I,l.OpenReplaceDialogOperation=E,l.ReplaceAllMatchesCommand=w,l.ReplaceCurrentMatchCommand=U,l.createInitFindReplaceState=P,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/find-replace",
|
|
3
|
-
"version": "0.6.0
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -55,10 +55,10 @@
|
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"@univerjs/icons": "^0.2.15",
|
|
58
|
-
"@univerjs/core": "0.6.0
|
|
59
|
-
"@univerjs/
|
|
60
|
-
"@univerjs/design": "0.6.0
|
|
61
|
-
"@univerjs/
|
|
58
|
+
"@univerjs/core": "0.6.0",
|
|
59
|
+
"@univerjs/engine-render": "0.6.0",
|
|
60
|
+
"@univerjs/design": "0.6.0",
|
|
61
|
+
"@univerjs/ui": "0.6.0"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"less": "^4.2.2",
|