@univerjs/sheets-data-validation-ui 0.17.0-insiders.20260318-5bef180 → 0.18.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 +1 -1
- package/lib/index.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +13 -13
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,4 +1,4 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`@univerjs/core`),l=require(`@univerjs/engine-render`),u=require(`@univerjs/sheets`),d=require(`@univerjs/sheets-data-validation`),f=require(`@univerjs/data-validation`),p=require(`@univerjs/ui`),m=require(`rxjs`),h=require(`@univerjs/sheets-numfmt`),g=require(`@univerjs/sheets-ui`),_=require(`@univerjs/design`),v=require(`react`);v=s(v);let y=require(`@univerjs/icons`),b=require(`@univerjs/engine-formula`),x=require(`@univerjs/sheets-formula-ui`),S=require(`react/jsx-runtime`);var C=`@univerjs/sheets-data-validation-ui`,w=`0.17.0-insiders.20260318-5bef180`;function T(e){"@babel/helpers - typeof";return T=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},T(e)}function E(e,t){if(T(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(T(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function D(e){var t=E(e,`string`);return T(t)==`symbol`?t:t+``}function O(e,t,n){return(t=D(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function k(e,t){return function(n,r){t(n,r,e)}}function A(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let j=class extends c.Disposable{get activeRule(){return this._activeRule}get isOpen(){return this._open$.getValue()}constructor(e,t){super(),this._univerInstanceService=e,this._sidebarService=t,O(this,`_open$`,new m.BehaviorSubject(!1)),O(this,`open$`,this._open$.pipe((0,m.distinctUntilChanged)())),O(this,`_activeRule`,void 0),O(this,`_activeRule$`,new m.BehaviorSubject(void 0)),O(this,`activeRule$`,this._activeRule$.asObservable()),O(this,`_closeDisposable`,null),O(this,`_focusFormulaEditorActiveRuleSubUnitId`,null),this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET).pipe((0,m.filter)(e=>!e)).subscribe(()=>{this.close()})),this.disposeWithMe(this._sidebarService.sidebarOptions$.subscribe(e=>{e.id===`DataValidationPanel`&&(e.visible||setTimeout(()=>{this._sidebarService.sidebarOptions$.next({visible:!1})}))}))}dispose(){var e;super.dispose(),this._open$.next(!1),this._open$.complete(),this._activeRule$.complete(),(e=this._closeDisposable)==null||e.dispose()}open(){this._open$.next(!0)}close(){var e;this._open$.next(!1),(e=this._closeDisposable)==null||e.dispose()}setCloseDisposable(e){this._closeDisposable=(0,c.toDisposable)(()=>{e.dispose(),this._closeDisposable=null})}setActiveRule(e){this._activeRule=e,this._activeRule$.next(e)}setFocusFormulaEditorActiveRuleSubUnitId(e){this._focusFormulaEditorActiveRuleSubUnitId=e}getFocusFormulaEditorActiveRuleSubUnitId(){return this._focusFormulaEditorActiveRuleSubUnitId}};j=A([k(0,c.IUniverInstanceService),k(1,p.ISidebarService)],j);const M=`sheets-data-validation-ui.config`;Symbol(M);const N={};let P=class extends c.Disposable{constructor(e,t,n,r,i,a){super(),this._sheetInterceptorService=e,this._dataValidationModel=t,this._dataValidatorRegistryService=n,this._dialogService=r,this._localeService=i,this._sheetsDataValidationValidatorService=a,this._initEditorBridgeInterceptor()}_initEditorBridgeInterceptor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(u.VALIDATE_CELL,{handler:async(e,t,n)=>{let r=await e,{row:i,col:a,unitId:o,subUnitId:s}=t,l=this._dataValidationModel.getRuleIdByLocation(o,s,i,a),u=l?this._dataValidationModel.getRuleById(o,s,l):void 0;if(r===!1)return n(Promise.resolve(!1));if(!u||u.errorStyle!==c.DataValidationErrorStyle.STOP)return n(Promise.resolve(!0));let d=this._dataValidatorRegistryService.getValidatorItem(u.type);return!d||await this._sheetsDataValidationValidatorService.validatorCell(o,s,i,a)===c.DataValidationStatus.VALID?n(Promise.resolve(!0)):(this._dialogService.open({width:368,title:{title:this._localeService.t(`dataValidation.alert.title`)},id:`reject-input-dialog`,children:{title:d.getRuleFinalError(u,{row:i,col:a,unitId:o,subUnitId:s})},footer:{title:(0,v.createElement)(_.Button,{variant:`primary`,onClick:()=>this._dialogService.close(`reject-input-dialog`)},this._localeService.t(`dataValidation.alert.ok`))},onClose:()=>{this._dialogService.close(`reject-input-dialog`)}}),n(Promise.resolve(!1)))}}))}showReject(e){this._dialogService.open({width:368,title:{title:this._localeService.t(`dataValidation.alert.title`)},id:`reject-input-dialog`,children:{title:e},footer:{title:(0,v.createElement)(_.Button,{variant:`primary`,onClick:()=>this._dialogService.close(`reject-input-dialog`)},this._localeService.t(`dataValidation.alert.ok`))},onClose:()=>{this._dialogService.close(`reject-input-dialog`)}})}};P=A([k(0,(0,c.Inject)(u.SheetInterceptorService)),k(1,(0,c.Inject)(d.SheetDataValidationModel)),k(2,(0,c.Inject)(f.DataValidatorRegistryService)),k(3,p.IDialogService),k(4,(0,c.Inject)(c.LocaleService)),k(5,(0,c.Inject)(d.SheetsDataValidationValidatorService))],P);const F=e=>{if(e==null||typeof e==`boolean`)return;if(e===``)return(0,c.dayjs)();if(typeof e==`number`||!Number.isNaN(+e))return(0,c.dayjs)(c.numfmt.format(`yyyy-MM-dd HH:mm:ss`,Number(e)));let t=(0,c.dayjs)(e);if(t.isValid())return t};function I(e,t){if(e===(0,h.getPatternType)(t))return t;switch(e){case`datetime`:return`yyyy-MM-dd hh:mm:ss`;case`date`:return`yyyy-MM-dd`;case`time`:return`HH:mm:ss`}}let L=class extends c.Disposable{get activeDropdown(){return this._activeDropdown}constructor(e,t,n,r,i,a,o,s,c,l,u){super(),this._univerInstanceService=e,this._dataValidatorRegistryService=t,this._zenZoneService=n,this._dataValidationModel=r,this._sheetsSelectionsService=i,this._cellDropdownManagerService=a,this._sheetDataValidationModel=o,this._commandService=s,this._editorBridgeService=c,this._injector=l,this._configService=u,O(this,`_activeDropdown`,void 0),O(this,`_activeDropdown$`,new m.Subject),O(this,`_currentPopup`,null),O(this,`activeDropdown$`,this._activeDropdown$.asObservable()),O(this,`_zenVisible`,!1),this._init(),this._initSelectionChange(),this.disposeWithMe(()=>{this._activeDropdown$.complete()})}_init(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{this._zenVisible=e,e&&this.hideDropdown()}))}_getDropdownByCell(e,t,n,r){let i=e?this._univerInstanceService.getUnit(e,c.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET);if(!i)return;let a=t?i.getSheetBySheetId(t):i.getActiveSheet();if(!a)return;let o=this._dataValidationModel.getRuleByLocation(i.getUnitId(),a.getSheetId(),n,r);if(!o)return;let s=this._dataValidatorRegistryService.getValidatorItem(o.type);return s==null?void 0:s.dropdownType}_initSelectionChange(){this.disposeWithMe(this._sheetsSelectionsService.selectionMoveEnd$.subscribe(e=>{e&&e.every(e=>!(e.primary&&this._getDropdownByCell(e.primary.unitId,e.primary.sheetId,e.primary.actualRow,e.primary.actualColumn)))&&this.hideDropdown()}))}showDropdown(e){let{location:t}=e,{row:n,col:r,unitId:i,subUnitId:a,workbook:o,worksheet:s}=t;if(this._currentPopup&&this._currentPopup.dispose(),this._zenVisible)return;this._activeDropdown=e,this._activeDropdown$.next(this._activeDropdown);let m=this._sheetDataValidationModel.getRuleByLocation(i,a,n,r);if(!m)return;let h=this._dataValidatorRegistryService.getValidatorItem(m.type);if(!(h!=null&&h.dropdownType))return;let _,v=async(e,t)=>{var d,f,_;if(!e)return!0;let v=e,y=s.getCell(n,r),b=v.format(t===`date`?`YYYY-MM-DD 00:00:00`:`YYYY-MM-DD HH:mm:ss`),x=(d=c.numfmt.parseDate(b))==null?void 0:d.v,S=t===`time`?x%1:x,C=o.getStyles().getStyleByCell(y),w=(f=C==null||(_=C.n)==null?void 0:_.pattern)==null?``:f;return m.errorStyle!==c.DataValidationErrorStyle.STOP||await h.validator({value:S,unitId:i,subUnitId:a,row:n,column:r,worksheet:s,workbook:o,interceptValue:b.replace(`Z`,``).replace(`T`,` `),t:c.CellValueType.NUMBER},m)?(await this._commandService.executeCommand(u.SetRangeValuesCommand.id,{unitId:i,subUnitId:a,range:{startColumn:r,endColumn:r,startRow:n,endRow:n},value:{v:S,t:2,p:null,f:null,si:null,s:{n:{pattern:I(t,w)}}}}),await this._commandService.executeCommand(g.SetCellEditVisibleOperation.id,{visible:!1,eventType:l.DeviceInputEventType.Keyboard,unitId:i,keycode:p.KeyCode.ESC}),!0):(this._injector.has(P)&&this._injector.get(P).showReject(h.getRuleFinalError(m,{row:n,col:r,unitId:i,subUnitId:a})),!1)},y;switch(h.dropdownType){case f.DataValidatorDropdownType.DATE:{var b;let e=F((0,d.getCellValueOrigin)(s.getCellRaw(n,r))),i=!!((b=m.bizInfo)!=null&&b.showTime);y={location:t,type:`datepicker`,props:{showTime:i,onChange:e=>v(e,i?`datetime`:`date`),defaultValue:e,patternType:`date`}};break}case f.DataValidatorDropdownType.TIME:y={location:t,type:`datepicker`,props:{onChange:e=>v(e,`time`),defaultValue:F((0,d.getCellValueOrigin)(s.getCellRaw(n,r))),patternType:`time`}};break;case f.DataValidatorDropdownType.DATETIME:y={location:t,type:`datepicker`,props:{onChange:e=>v(e,`datetime`),defaultValue:F((0,d.getCellValueOrigin)(s.getCellRaw(n,r))),patternType:`datetime`}};break;case f.DataValidatorDropdownType.LIST:case f.DataValidatorDropdownType.MULTIPLE_LIST:{var x,S,C,w;let e=h.dropdownType===f.DataValidatorDropdownType.MULTIPLE_LIST,o=async t=>{let o=(0,d.serializeListOptions)(t),s={unitId:i,subUnitId:a,range:{startColumn:r,endColumn:r,startRow:n,endRow:n},value:{v:o,p:null,f:null,si:null}};return this._commandService.executeCommand(u.SetRangeValuesCommand.id,s),this._editorBridgeService.isVisible().visible&&await this._commandService.executeCommand(g.SetCellEditVisibleOperation.id,{visible:!1,eventType:l.DeviceInputEventType.Keyboard,unitId:i,keycode:p.KeyCode.ESC}),!e},v=(m==null?void 0:m.renderMode)===c.DataValidationRenderMode.CUSTOM||(m==null?void 0:m.renderMode)===void 0,b=h.getListWithColor(m,i,a),T=(0,d.getDataValidationCellValue)(s.getCellRaw(n,r));y={location:t,type:`list`,props:{onChange:e=>o(e),options:b.map(e=>({label:e.label,value:e.label,color:v||e.color?e.color||`#ECECEC`:`transparent`})),onEdit:()=>{this._commandService.executeCommand(z.id,{ruleId:m.uid}),_==null||_.dispose()},defaultValue:T,multiple:e,showEdit:(x=(S=this._configService.getConfig(`sheets-data-validation-ui.config`))==null?void 0:S.showEditOnDropdown)==null?!0:x,showSearch:(C=(w=this._configService.getConfig(`sheets-data-validation-ui.config`))==null?void 0:w.showSearchOnDropdown)==null?!0:C}};break}case f.DataValidatorDropdownType.CASCADE:var T;y={type:`cascader`,props:{onChange:e=>{let t={unitId:i,subUnitId:a,range:{startColumn:r,endColumn:r,startRow:n,endRow:n},value:{v:e.join(`/`),p:null,f:null,si:null}};return this._commandService.syncExecuteCommand(u.SetRangeValuesCommand.id,t),this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(g.SetCellEditVisibleOperation.id,{visible:!1,eventType:l.DeviceInputEventType.Keyboard,unitId:i,keycode:p.KeyCode.ESC}),!0},defaultValue:(0,d.getDataValidationCellValue)(s.getCellRaw(n,r)).split(`/`),options:JSON.parse((T=m.formula1)==null?`[]`:T)},location:t};break;case f.DataValidatorDropdownType.COLOR:y={type:`color`,props:{onChange:e=>{let t={unitId:i,subUnitId:a,range:{startColumn:r,endColumn:r,startRow:n,endRow:n},value:{v:e,p:null,f:null,si:null}};return this._commandService.syncExecuteCommand(u.SetRangeValuesCommand.id,t),this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(g.SetCellEditVisibleOperation.id,{visible:!1,eventType:l.DeviceInputEventType.Keyboard,unitId:i,keycode:p.KeyCode.ESC}),!0},defaultValue:(0,d.getDataValidationCellValue)(s.getCellRaw(n,r))},location:t};break;default:throw Error(`[DataValidationDropdownManagerService]: unknown type!`)}if(_=this._cellDropdownManagerService.showDropdown({...y,onHide:()=>{this._activeDropdown=null,this._activeDropdown$.next(null)}}),!_)throw Error(`[DataValidationDropdownManagerService]: cannot show dropdown!`);let E=new c.DisposableCollection;E.add(_),E.add({dispose:()=>{var e,t;(e=this._activeDropdown)==null||(t=e.onHide)==null||t.call(e)}}),this._currentPopup=E}hideDropdown(){this._activeDropdown&&(this._currentPopup&&this._currentPopup.dispose(),this._currentPopup=null,this._activeDropdown=null,this._activeDropdown$.next(null))}showDataValidationDropdown(e,t,n,r,i){let a=this._univerInstanceService.getUnit(e,c.UniverInstanceType.UNIVER_SHEET);if(!a)return;let o=a.getSheetBySheetId(t);if(!o)return;let s=this._dataValidationModel.getRuleByLocation(a.getUnitId(),o.getSheetId(),n,r);if(!s)return;let l=this._dataValidatorRegistryService.getValidatorItem(s.type);if(!l||!l.dropdownType){this.hideDropdown();return}this.showDropdown({location:{workbook:a,worksheet:o,row:n,col:r,unitId:e,subUnitId:t},onHide:i})}};L=A([k(0,c.IUniverInstanceService),k(1,(0,c.Inject)(f.DataValidatorRegistryService)),k(2,p.IZenZoneService),k(3,(0,c.Inject)(d.SheetDataValidationModel)),k(4,(0,c.Inject)(u.SheetsSelectionsService)),k(5,(0,c.Inject)(g.ISheetCellDropdownManagerService)),k(6,(0,c.Inject)(d.SheetDataValidationModel)),k(7,c.ICommandService),k(8,g.IEditorBridgeService),k(9,(0,c.Inject)(c.Injector)),k(10,c.IConfigService)],L);const R=`DataValidationPanel`,z={id:`data-validation.operation.open-validation-panel`,type:c.CommandType.OPERATION,handler(e,t){if(!t)return!1;let{ruleId:n,isAdd:r}=t,i=e.get(j),a=e.get(f.DataValidationModel),o=e.get(c.IUniverInstanceService),s=e.get(p.ISidebarService),l=(0,u.getSheetCommandTarget)(o);if(!l)return!1;let{unitId:d,subUnitId:m}=l,h=n?a.getRuleById(d,m,n):void 0;i.open(),i.setActiveRule(h&&{unitId:d,subUnitId:m,rule:h});let g=s.open({id:R,header:{title:r?`dataValidation.panel.addTitle`:`dataValidation.panel.title`},children:{label:R},width:312,onClose:()=>i.close()});return i.setCloseDisposable(g),!0}},B={id:`data-validation.operation.close-validation-panel`,type:c.CommandType.OPERATION,handler(e){return e.get(j).close(),!0}},V={id:`data-validation.operation.toggle-validation-panel`,type:c.CommandType.OPERATION,handler(e){let t=e.get(c.ICommandService),n=e.get(j);return n.open(),n.isOpen?t.executeCommand(B.id):t.executeCommand(z.id),!0}},H={type:c.CommandType.OPERATION,id:`sheet.operation.show-data-validation-dropdown`,handler(e,t){if(!t)return!1;let n=e.get(L),{unitId:r,subUnitId:i,row:a,column:o}=t,s=n.activeDropdown,c=s==null?void 0:s.location;return c&&c.unitId===r&&c.subUnitId===i&&c.row===a&&c.col===o||n.showDataValidationDropdown(r,i,a,o),!0}},U={type:c.CommandType.OPERATION,id:`sheet.operation.hide-data-validation-dropdown`,handler(e,t){return t?(e.get(L).hideDropdown(),!0):!1}},W={type:c.CommandType.COMMAND,id:`data-validation.command.addRuleAndOpen`,handler(e){let t=(0,u.getSheetCommandTarget)(e.get(c.IUniverInstanceService));if(!t)return!1;let{workbook:n,worksheet:r}=t,i=(0,d.createDefaultNewRule)(e),a=e.get(c.ICommandService),o={rule:i,unitId:n.getUnitId(),subUnitId:r.getSheetId()};return a.syncExecuteCommand(d.AddSheetDataValidationCommand.id,o)?(a.syncExecuteCommand(z.id,{ruleId:i.uid,isAdd:!0}),!0):!1}},G=`SHEET_DATA_VALIDATION_ALERT`;let K=class extends c.Disposable{constructor(e,t,n,r,i,a){super(),this._hoverManagerService=e,this._cellAlertManagerService=t,this._univerInstanceService=n,this._localeService=r,this._zenZoneService=i,this._dataValidationModel=a,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe((0,m.debounceTime)(100)).subscribe(e=>{if(e){let n=this._univerInstanceService.getUnit(e.location.unitId,c.UniverInstanceType.UNIVER_SHEET),r=n.getSheetBySheetId(e.location.subUnitId);if(!r)return;let i=this._dataValidationModel.getRuleByLocation(e.location.unitId,e.location.subUnitId,e.location.row,e.location.col);if(!i){this._cellAlertManagerService.removeAlert(G);return}if(this._dataValidationModel.validator(i,{...e.location,workbook:n,worksheet:r})===c.DataValidationStatus.INVALID){var t;let n=this._cellAlertManagerService.currentAlert.get(G),r=n==null||(t=n.alert)==null?void 0:t.location;if(r&&r.row===e.location.row&&r.col===e.location.col&&r.subUnitId===e.location.subUnitId&&r.unitId===e.location.unitId){this._cellAlertManagerService.removeAlert(G);return}let a=this._dataValidationModel.getValidator(i.type);if(!a){this._cellAlertManagerService.removeAlert(G);return}this._cellAlertManagerService.showAlert({type:g.CellAlertType.ERROR,title:this._localeService.t(`dataValidation.error.title`),message:a==null?void 0:a.getRuleFinalError(i,e.location),location:e.location,width:200,height:74,key:G});return}}this._cellAlertManagerService.removeAlert(G)}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._cellAlertManagerService.removeAlert(G)}))}};K=A([k(0,(0,c.Inject)(g.HoverManagerService)),k(1,(0,c.Inject)(g.CellAlertManagerService)),k(2,c.IUniverInstanceService),k(3,(0,c.Inject)(c.LocaleService)),k(4,p.IZenZoneService),k(5,(0,c.Inject)(d.SheetDataValidationModel))],K);let q=class extends c.Disposable{constructor(e,t,n){super(),this._autoFillService=e,this._sheetDataValidationModel=t,this._injector=n,this._initAutoFill()}_initAutoFill(){let e=()=>({redos:[],undos:[]}),t=(e,t)=>{let{source:n,target:r,unitId:i,subUnitId:a}=e,o=this._sheetDataValidationModel.getRuleObjectMatrix(i,a).clone(),s=(0,g.virtualizeDiscreteRanges)([n,r]),[l,f]=s.ranges,{mapFunc:p}=s,m={row:l.startRow,col:l.startColumn},h=u.AutoFillTools.getAutoFillRepeatRange(l,f),_=new c.ObjectMatrix,v=new Set;h.forEach(e=>{let t=e.repeatStartCell,n=e.relativeRange,r={startRow:m.row,startColumn:m.col,endColumn:m.col,endRow:m.row},o={startRow:t.row,startColumn:t.col,endColumn:t.col,endRow:t.row};c.Range.foreach(n,(e,t)=>{let n=c.Rectangle.getPositionRange({startRow:e,startColumn:t,endColumn:t,endRow:e},r),{row:s,col:l}=p(n.startRow,n.startColumn),u=this._sheetDataValidationModel.getRuleIdByLocation(i,a,s,l)||``,d=c.Rectangle.getPositionRange({startRow:e,startColumn:t,endColumn:t,endRow:e},o),{row:f,col:m}=p(d.startRow,d.startColumn);_.setValue(f,m,u),v.add(u)})});let y=Array.from(v).map(e=>({id:e,ranges:(0,c.queryObjectMatrix)(_,t=>t===e)}));o.addRangeRules(y);let{redoMutations:b,undoMutations:x}=(0,d.getDataValidationDiffMutations)(i,a,o.diff(this._sheetDataValidationModel.getRules(i,a)),this._injector,`patched`,t===u.AUTO_FILL_APPLY_TYPE.ONLY_FORMAT);return{undos:x,redos:b}},n={id:d.DATA_VALIDATION_PLUGIN_NAME,onBeforeFillData:e=>{let{source:t,unitId:n,subUnitId:r}=e;for(let e of t.rows)for(let i of t.cols){let t=this._sheetDataValidationModel.getRuleByLocation(n,r,e,i);if(t&&t.type===c.DataValidationType.CHECKBOX){this._autoFillService.setDisableApplyType(u.AUTO_FILL_APPLY_TYPE.SERIES,!0);return}}},onFillData:(n,r,i)=>i===u.AUTO_FILL_APPLY_TYPE.COPY||i===u.AUTO_FILL_APPLY_TYPE.ONLY_FORMAT||i===u.AUTO_FILL_APPLY_TYPE.SERIES?t(n,i):e(),onAfterFillData:()=>{}};this.disposeWithMe(this._autoFillService.addHook(n))}};q=A([k(0,u.IAutoFillService),k(1,(0,c.Inject)(d.SheetDataValidationModel)),k(2,(0,c.Inject)(c.Injector))],q);let J=class extends c.Disposable{constructor(e,t,n){super(),this._sheetClipboardService=e,this._sheetDataValidationModel=t,this._injector=n,O(this,`_copyInfo`,void 0),this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:d.DATA_VALIDATION_PLUGIN_NAME,onBeforeCopy:(e,t,n)=>this._collect(e,t,n),onPasteCells:(e,t,n,r)=>{let{copyType:i=g.COPY_TYPE.COPY,pasteType:a}=r,{range:o}=e||{},{range:s,unitId:c,subUnitId:l}=t;return this._generateMutations(s,{copyType:i,pasteType:a,copyRange:o,unitId:c,subUnitId:l})}})}_collect(e,t,n){let r=new c.ObjectMatrix;this._copyInfo={unitId:e,subUnitId:t,matrix:r};let i=this._injector.invoke(r=>(0,u.rangeToDiscreteRange)(n,r,e,t));if(!i)return;let{rows:a,cols:o}=i;a.forEach((n,i)=>{o.forEach((a,o)=>{let s=this._sheetDataValidationModel.getRuleIdByLocation(e,t,n,a);r.setValue(i,o,s==null?``:s)})})}_generateMutations(e,t){if(!this._copyInfo)return{redos:[],undos:[]};if(t.copyType===g.COPY_TYPE.CUT)return this._copyInfo=null,{redos:[],undos:[]};if(!this._copyInfo||!this._copyInfo.matrix.getSizeOf()||!t.copyRange||[g.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_COL_WIDTH,g.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_VALUE,g.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMAT,g.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMULA].includes(t.pasteType))return{redos:[],undos:[]};let{unitId:n,subUnitId:r}=this._copyInfo;if(t.unitId!==n||r!==t.subUnitId){let i=this._sheetDataValidationModel.getRuleObjectMatrix(t.unitId,t.subUnitId).clone(),a=new c.ObjectMatrix,o=new Set,{ranges:[s,l],mapFunc:u}=(0,g.virtualizeDiscreteRanges)([t.copyRange,e]),f=(0,g.getRepeatRange)(s,l,!0),p=new Map;f.forEach(({startRange:e})=>{var i;(i=this._copyInfo)==null||i.matrix.forValue((i,s,l)=>{let d=c.Rectangle.getPositionRange({startRow:i,endRow:i,startColumn:s,endColumn:s},e),f=`${r}-${l}`,m=this._sheetDataValidationModel.getRuleById(n,r,l);!this._sheetDataValidationModel.getRuleById(t.unitId,t.subUnitId,f)&&m&&p.set(f,{...m,uid:f});let{row:h,col:g}=u(d.startRow,d.startColumn);o.add(f),a.setValue(h,g,f)})});let m=Array.from(o).map(e=>({id:e,ranges:(0,c.queryObjectMatrix)(a,t=>t===e)}));i.addRangeRules(m);let{redoMutations:h,undoMutations:_}=(0,d.getDataValidationDiffMutations)(t.unitId,t.subUnitId,i.diffWithAddition(this._sheetDataValidationModel.getRules(t.unitId,t.subUnitId),p.values()),this._injector,`patched`,!1);return{redos:h,undos:_}}else{let i=this._sheetDataValidationModel.getRuleObjectMatrix(n,r).clone(),a=new c.ObjectMatrix,o=new Set,{ranges:[s,l],mapFunc:u}=(0,g.virtualizeDiscreteRanges)([t.copyRange,e]);(0,g.getRepeatRange)(s,l,!0).forEach(({startRange:e})=>{var t;(t=this._copyInfo)==null||t.matrix.forValue((t,n,r)=>{let i=c.Rectangle.getPositionRange({startRow:t,endRow:t,startColumn:n,endColumn:n},e),{row:s,col:l}=u(i.startRow,i.startColumn);a.setValue(s,l,r),o.add(r)})});let f=Array.from(o).map(e=>({id:e,ranges:(0,c.queryObjectMatrix)(a,t=>t===e)}));i.addRangeRules(f);let{redoMutations:p,undoMutations:m}=(0,d.getDataValidationDiffMutations)(n,r,i.diff(this._sheetDataValidationModel.getRules(n,r)),this._injector,`patched`,!1);return{redos:p,undos:m}}}};J=A([k(0,g.ISheetClipboardService),k(1,(0,c.Inject)(d.SheetDataValidationModel)),k(2,(0,c.Inject)(c.Injector))],J);let Y=class extends c.Disposable{constructor(e,t,n){super(),this._localeService=e,this._commandService=t,this._sheetPermissionCheckController=n,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===d.AddSheetDataValidationCommand.id){let{unitId:t,subUnitId:n,rule:{ranges:r}}=e.params;this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[u.WorkbookEditablePermission],rangeTypes:[u.RangeProtectionPermissionEditPoint],worksheetTypes:[u.WorksheetEditPermission,u.WorksheetSetCellStylePermission]},r,t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.setStyleErr`))}if(e.id===d.UpdateSheetDataValidationRangeCommand.id){let{unitId:t,subUnitId:n,ranges:r}=e.params;this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[u.WorkbookEditablePermission],rangeTypes:[u.RangeProtectionPermissionEditPoint],worksheetTypes:[u.WorksheetEditPermission,u.WorksheetSetCellStylePermission]},r,t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.setStyleErr`))}}))}};Y=A([k(0,(0,c.Inject)(c.LocaleService)),k(1,c.ICommandService),k(2,(0,c.Inject)(u.SheetPermissionCheckController))],Y);const ee=`sheet.menu.data-validation`;function te(e){return{id:ee,type:p.MenuItemType.SUBITEMS,icon:`DataValidationIcon`,tooltip:`dataValidation.title`,hidden$:(0,p.getMenuHiddenObservable)(e,c.UniverInstanceType.UNIVER_SHEET),disabled$:(0,g.getCurrentRangeDisable$)(e,{workbookTypes:[u.WorkbookEditablePermission],worksheetTypes:[u.WorksheetSetCellStylePermission,u.WorksheetEditPermission],rangeTypes:[u.RangeProtectionPermissionEditPoint]})}}function X(e){return{id:z.id,title:`dataValidation.panel.title`,type:p.MenuItemType.BUTTON}}function ne(e){return{id:W.id,title:`dataValidation.panel.add`,type:p.MenuItemType.BUTTON}}const re={[p.RibbonDataGroup.RULES]:{[ee]:{order:0,menuItemFactory:te,[z.id]:{order:0,menuItemFactory:X},[W.id]:{order:1,menuItemFactory:ne}}}},ie={tr:{size:6,color:`#fe4b4b`}};let Z=class extends c.RxDisposable{constructor(e,t,n,r,i,a,o,s,c,l,u){super(),this._commandService=e,this._menuManagerService=t,this._renderManagerService=n,this._univerInstanceService=r,this._autoHeightController=i,this._dropdownManagerService=a,this._sheetDataValidationModel=o,this._dataValidatorRegistryService=s,this._sheetInterceptorService=c,this._dataValidationCacheService=l,this._editorBridgeService=u,this._initMenu(),this._initDropdown(),this._initViewModelIntercept(),this._initAutoHeight()}_initMenu(){this._menuManagerService.mergeMenu(re)}_initDropdown(){this._editorBridgeService&&this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{if(!e.visible){var t;((t=this._dropdownManagerService.activeDropdown)==null?void 0:t.trigger)===`editor-bridge`&&this._dropdownManagerService.hideDropdown();return}let n=this._editorBridgeService.getEditCellState();if(n){let{unitId:e,sheetId:t,row:r,column:i}=n,a=this._univerInstanceService.getUniverSheetInstance(e);if(!a)return;let o=this._sheetDataValidationModel.getRuleByLocation(e,t,r,i);if(!o)return;let s=this._dataValidatorRegistryService.getValidatorItem(o.type);if(!(s!=null&&s.dropdownType))return;let c=a.getActiveSheet();if(!c)return;let l=this._dropdownManagerService.activeDropdown,u=l==null?void 0:l.location;if(u&&u.unitId===e&&u.subUnitId===t&&u.row===r&&u.col===i)return;this._dropdownManagerService.showDropdown({location:{unitId:e,subUnitId:t,row:r,col:i,workbook:a,worksheet:c},trigger:`editor-bridge`,closeOnOutSide:!1})}}))}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(u.INTERCEPTOR_POINT.CELL_CONTENT,{effect:c.InterceptorEffectEnum.Style,priority:u.InterceptCellContentPriority.DATA_VALIDATION,handler:(e,t,n)=>{var r,i,a,o,s;let{row:l,col:u,unitId:f,subUnitId:p,workbook:m,worksheet:h}=t,_=this._sheetDataValidationModel.getRuleIdByLocation(f,p,l,u);if(!_)return n(e);let v=this._sheetDataValidationModel.getRuleById(f,p,_);if(!v)return n(e);let y=(r=this._dataValidationCacheService.getValue(f,p,l,u))==null?c.DataValidationStatus.VALID:r,b=this._dataValidatorRegistryService.getValidatorItem(v.type),x=t.rawData,S,C={get value(){var e;return S===void 0&&(S=(e=(0,d.getCellValueOrigin)(x))==null?null:e),S}},w={get value(){var e;return`${(e=C.value)==null?``:e}`}};return(!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,...y===c.DataValidationStatus.INVALID?ie:null},e.customRender=[...(i=e==null?void 0:e.customRender)==null?[]:i,...b!=null&&b.canvasRender?[b.canvasRender]:[]],e.fontRenderExtension={...e==null?void 0:e.fontRenderExtension,isSkip:(e==null||(a=e.fontRenderExtension)==null?void 0:a.isSkip)||(b==null||(o=b.skipDefaultFontRender)==null?void 0:o.call(b,v,C.value,t))},e.interceptorStyle={...e==null?void 0:e.interceptorStyle,...b==null?void 0:b.getExtraStyle(v,w.value,{get style(){let t=m.getStyles();return(typeof(e==null?void 0:e.s)==`string`?t.get(e==null?void 0:e.s):e==null?void 0:e.s)||{}}},l,u)},e.interceptorAutoHeight=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(f))==null||(t=t.with(g.SheetSkeletonManagerService).getSkeletonParam(p))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(l,u),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?l:n,(r=s==null?void 0:s.startColumn)==null?u:r),unitId:f,subUnitId:p,row:l,col:u,workbook:m,worksheet:h};return b==null||(i=b.canvasRender)==null||(a=i.calcCellAutoHeight)==null?void 0:a.call(i,c)},e.interceptorAutoWidth=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(f))==null||(t=t.with(g.SheetSkeletonManagerService).getSkeletonParam(p))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(l,u),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?l:n,(r=s==null?void 0:s.startColumn)==null?u:r),unitId:f,subUnitId:p,row:l,col:u,workbook:m,worksheet:h};return b==null||(i=b.canvasRender)==null||(a=i.calcCellAutoWidth)==null?void 0:a.call(i,c)},e.coverable=((s=e==null?void 0:e.coverable)==null?!0:s)&&!(v.type===c.DataValidationType.LIST||v.type===c.DataValidationType.LIST_MULTIPLE),n(e)}}))}_initAutoHeight(){this._sheetDataValidationModel.ruleChange$.pipe((0,m.filter)(e=>e.source===`command`),(0,m.bufferTime)(100)).subscribe(e=>{if(e.length===0)return;let t=[];e.forEach(e=>{if(e.rule.type===c.DataValidationType.LIST_MULTIPLE||e.rule.type===c.DataValidationType.LIST){var n;(n=e.rule)!=null&&n.ranges&&t.push(...e.rule.ranges)}}),t.length&&(0,c.sequenceExecute)(this._autoHeightController.getUndoRedoParamsOfAutoHeight(t).redos,this._commandService)})}};Z=A([k(0,c.ICommandService),k(1,p.IMenuManagerService),k(2,l.IRenderManagerService),k(3,c.IUniverInstanceService),k(4,(0,c.Inject)(g.AutoHeightController)),k(5,(0,c.Inject)(L)),k(6,(0,c.Inject)(d.SheetDataValidationModel)),k(7,(0,c.Inject)(f.DataValidatorRegistryService)),k(8,(0,c.Inject)(u.SheetInterceptorService)),k(9,(0,c.Inject)(d.DataValidationCacheService)),k(10,(0,c.Optional)(g.IEditorBridgeService))],Z);let ae=class extends c.RxDisposable{constructor(e,t,n,r,i,a,o){super(),this._commandService=e,this._renderManagerService=t,this._autoHeightController=n,this._dataValidatorRegistryService=r,this._sheetInterceptorService=i,this._sheetDataValidationModel=a,this._dataValidationCacheService=o,this._initViewModelIntercept(),this._initAutoHeight()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(u.INTERCEPTOR_POINT.CELL_CONTENT,{effect:c.InterceptorEffectEnum.Style,priority:u.InterceptCellContentPriority.DATA_VALIDATION,handler:(e,t,n)=>{var r,i,a,o,s;let{row:l,col:u,unitId:f,subUnitId:p,workbook:m,worksheet:h}=t,_=this._sheetDataValidationModel.getRuleIdByLocation(f,p,l,u);if(!_)return n(e);let v=this._sheetDataValidationModel.getRuleById(f,p,_);if(!v)return n(e);let y=(r=this._dataValidationCacheService.getValue(f,p,l,u))==null?c.DataValidationStatus.VALID:r,b=this._dataValidatorRegistryService.getValidatorItem(v.type),x=(0,d.getCellValueOrigin)(h.getCellRaw(l,u)),S=`${x==null?``:x}`;return(!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,...y===c.DataValidationStatus.INVALID?ie:null},e.customRender=[...(i=e==null?void 0:e.customRender)==null?[]:i,...b!=null&&b.canvasRender?[b.canvasRender]:[]],e.fontRenderExtension={...e==null?void 0:e.fontRenderExtension,isSkip:(e==null||(a=e.fontRenderExtension)==null?void 0:a.isSkip)||(b==null||(o=b.skipDefaultFontRender)==null?void 0:o.call(b,v,x,t))},e.interceptorStyle={...e==null?void 0:e.interceptorStyle,...b==null?void 0:b.getExtraStyle(v,S,{get style(){let t=m.getStyles();return(typeof(e==null?void 0:e.s)==`string`?t.get(e==null?void 0:e.s):e==null?void 0:e.s)||{}}},l,u)},e.interceptorAutoHeight=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(f))==null||(t=t.with(g.SheetSkeletonManagerService).getSkeletonParam(p))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(l,u),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?l:n,(r=s==null?void 0:s.startColumn)==null?u:r),unitId:f,subUnitId:p,row:l,col:u,workbook:m,worksheet:h};return b==null||(i=b.canvasRender)==null||(a=i.calcCellAutoHeight)==null?void 0:a.call(i,c)},e.interceptorAutoWidth=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(f))==null||(t=t.with(g.SheetSkeletonManagerService).getSkeletonParam(p))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(l,u),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?l:n,(r=s==null?void 0:s.startColumn)==null?u:r),unitId:f,subUnitId:p,row:l,col:u,workbook:m,worksheet:h};return b==null||(i=b.canvasRender)==null||(a=i.calcCellAutoWidth)==null?void 0:a.call(i,c)},e.coverable=((s=e==null?void 0:e.coverable)==null?!0:s)&&!(v.type===c.DataValidationType.LIST||v.type===c.DataValidationType.LIST_MULTIPLE),n(e)}}))}_initAutoHeight(){this._sheetDataValidationModel.ruleChange$.pipe((0,m.filter)(e=>e.source===`command`),(0,m.bufferTime)(16)).subscribe(e=>{let t=[];e.forEach(e=>{if(e.rule.type===c.DataValidationType.LIST_MULTIPLE||e.rule.type===c.DataValidationType.LIST){var n;(n=e.rule)!=null&&n.ranges&&t.push(...e.rule.ranges)}}),t.length&&(0,c.sequenceExecute)(this._autoHeightController.getUndoRedoParamsOfAutoHeight(t).redos,this._commandService)})}};ae=A([k(0,c.ICommandService),k(1,l.IRenderManagerService),k(2,(0,c.Inject)(g.AutoHeightController)),k(3,(0,c.Inject)(f.DataValidatorRegistryService)),k(4,(0,c.Inject)(u.SheetInterceptorService)),k(5,(0,c.Inject)(d.SheetDataValidationModel)),k(6,(0,c.Inject)(d.DataValidationCacheService))],ae);let oe=class extends c.Disposable{constructor(e,t,n){super(),this._context=e,this._sheetDataValidationModel=t,this._sheetSkeletonManagerService=n,this._initSkeletonChange()}_initSkeletonChange(){this.disposeWithMe(this._sheetDataValidationModel.validStatusChange$.pipe((0,c.bufferDebounceTime)(16)).subscribe(e=>{var t;if(!e.length)return;let n=new Set;e.forEach(e=>{n.add(e.subUnitId)}),n.forEach(e=>{var t;(t=this._sheetSkeletonManagerService.getSkeletonParam(e))==null||t.skeleton.makeDirty(!0)}),(t=this._context.mainComponent)==null||t.makeForceDirty()}))}};oe=A([k(1,(0,c.Inject)(d.SheetDataValidationModel)),k(2,(0,c.Inject)(g.SheetSkeletonManagerService))],oe);function se(e){var t;let n=(0,p.useDependency)(c.LocaleService),r=(0,p.useDependency)(p.ComponentManager),{value:i,onChange:a,extraComponent:o}=e,[s,l]=(0,v.useState)(!1),u=o?r.get(o):null;return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`@univerjs/core`),l=require(`@univerjs/engine-render`),u=require(`@univerjs/sheets`),d=require(`@univerjs/sheets-data-validation`),f=require(`@univerjs/data-validation`),p=require(`@univerjs/ui`),m=require(`rxjs`),h=require(`@univerjs/sheets-numfmt`),g=require(`@univerjs/sheets-ui`),_=require(`@univerjs/design`),v=require(`react`);v=s(v);let y=require(`@univerjs/icons`),b=require(`@univerjs/engine-formula`),x=require(`@univerjs/sheets-formula-ui`),S=require(`react/jsx-runtime`);var C=`@univerjs/sheets-data-validation-ui`,w=`0.18.0`;function T(e){"@babel/helpers - typeof";return T=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},T(e)}function E(e,t){if(T(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(T(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function D(e){var t=E(e,`string`);return T(t)==`symbol`?t:t+``}function O(e,t,n){return(t=D(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function k(e,t){return function(n,r){t(n,r,e)}}function A(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let j=class extends c.Disposable{get activeRule(){return this._activeRule}get isOpen(){return this._open$.getValue()}constructor(e,t){super(),this._univerInstanceService=e,this._sidebarService=t,O(this,`_open$`,new m.BehaviorSubject(!1)),O(this,`open$`,this._open$.pipe((0,m.distinctUntilChanged)())),O(this,`_activeRule`,void 0),O(this,`_activeRule$`,new m.BehaviorSubject(void 0)),O(this,`activeRule$`,this._activeRule$.asObservable()),O(this,`_closeDisposable`,null),O(this,`_focusFormulaEditorActiveRuleSubUnitId`,null),this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET).pipe((0,m.filter)(e=>!e)).subscribe(()=>{this.close()})),this.disposeWithMe(this._sidebarService.sidebarOptions$.subscribe(e=>{e.id===`DataValidationPanel`&&(e.visible||setTimeout(()=>{this._sidebarService.sidebarOptions$.next({visible:!1})}))}))}dispose(){var e;super.dispose(),this._open$.next(!1),this._open$.complete(),this._activeRule$.complete(),(e=this._closeDisposable)==null||e.dispose()}open(){this._open$.next(!0)}close(){var e;this._open$.next(!1),(e=this._closeDisposable)==null||e.dispose()}setCloseDisposable(e){this._closeDisposable=(0,c.toDisposable)(()=>{e.dispose(),this._closeDisposable=null})}setActiveRule(e){this._activeRule=e,this._activeRule$.next(e)}setFocusFormulaEditorActiveRuleSubUnitId(e){this._focusFormulaEditorActiveRuleSubUnitId=e}getFocusFormulaEditorActiveRuleSubUnitId(){return this._focusFormulaEditorActiveRuleSubUnitId}};j=A([k(0,c.IUniverInstanceService),k(1,p.ISidebarService)],j);const M=`sheets-data-validation-ui.config`;Symbol(M);const N={};let P=class extends c.Disposable{constructor(e,t,n,r,i,a){super(),this._sheetInterceptorService=e,this._dataValidationModel=t,this._dataValidatorRegistryService=n,this._dialogService=r,this._localeService=i,this._sheetsDataValidationValidatorService=a,this._initEditorBridgeInterceptor()}_initEditorBridgeInterceptor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(u.VALIDATE_CELL,{handler:async(e,t,n)=>{let r=await e,{row:i,col:a,unitId:o,subUnitId:s}=t,l=this._dataValidationModel.getRuleIdByLocation(o,s,i,a),u=l?this._dataValidationModel.getRuleById(o,s,l):void 0;if(r===!1)return n(Promise.resolve(!1));if(!u||u.errorStyle!==c.DataValidationErrorStyle.STOP)return n(Promise.resolve(!0));let d=this._dataValidatorRegistryService.getValidatorItem(u.type);return!d||await this._sheetsDataValidationValidatorService.validatorCell(o,s,i,a)===c.DataValidationStatus.VALID?n(Promise.resolve(!0)):(this._dialogService.open({width:368,title:{title:this._localeService.t(`dataValidation.alert.title`)},id:`reject-input-dialog`,children:{title:d.getRuleFinalError(u,{row:i,col:a,unitId:o,subUnitId:s})},footer:{title:(0,v.createElement)(_.Button,{variant:`primary`,onClick:()=>this._dialogService.close(`reject-input-dialog`)},this._localeService.t(`dataValidation.alert.ok`))},onClose:()=>{this._dialogService.close(`reject-input-dialog`)}}),n(Promise.resolve(!1)))}}))}showReject(e){this._dialogService.open({width:368,title:{title:this._localeService.t(`dataValidation.alert.title`)},id:`reject-input-dialog`,children:{title:e},footer:{title:(0,v.createElement)(_.Button,{variant:`primary`,onClick:()=>this._dialogService.close(`reject-input-dialog`)},this._localeService.t(`dataValidation.alert.ok`))},onClose:()=>{this._dialogService.close(`reject-input-dialog`)}})}};P=A([k(0,(0,c.Inject)(u.SheetInterceptorService)),k(1,(0,c.Inject)(d.SheetDataValidationModel)),k(2,(0,c.Inject)(f.DataValidatorRegistryService)),k(3,p.IDialogService),k(4,(0,c.Inject)(c.LocaleService)),k(5,(0,c.Inject)(d.SheetsDataValidationValidatorService))],P);const F=e=>{if(e==null||typeof e==`boolean`)return;if(e===``)return(0,c.dayjs)();if(typeof e==`number`||!Number.isNaN(+e))return(0,c.dayjs)(c.numfmt.format(`yyyy-MM-dd HH:mm:ss`,Number(e)));let t=(0,c.dayjs)(e);if(t.isValid())return t};function I(e,t){if(e===(0,h.getPatternType)(t))return t;switch(e){case`datetime`:return`yyyy-MM-dd hh:mm:ss`;case`date`:return`yyyy-MM-dd`;case`time`:return`HH:mm:ss`}}let L=class extends c.Disposable{get activeDropdown(){return this._activeDropdown}constructor(e,t,n,r,i,a,o,s,c,l,u){super(),this._univerInstanceService=e,this._dataValidatorRegistryService=t,this._zenZoneService=n,this._dataValidationModel=r,this._sheetsSelectionsService=i,this._cellDropdownManagerService=a,this._sheetDataValidationModel=o,this._commandService=s,this._editorBridgeService=c,this._injector=l,this._configService=u,O(this,`_activeDropdown`,void 0),O(this,`_activeDropdown$`,new m.Subject),O(this,`_currentPopup`,null),O(this,`activeDropdown$`,this._activeDropdown$.asObservable()),O(this,`_zenVisible`,!1),this._init(),this._initSelectionChange(),this.disposeWithMe(()=>{this._activeDropdown$.complete()})}_init(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{this._zenVisible=e,e&&this.hideDropdown()}))}_getDropdownByCell(e,t,n,r){let i=e?this._univerInstanceService.getUnit(e,c.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET);if(!i)return;let a=t?i.getSheetBySheetId(t):i.getActiveSheet();if(!a)return;let o=this._dataValidationModel.getRuleByLocation(i.getUnitId(),a.getSheetId(),n,r);if(!o)return;let s=this._dataValidatorRegistryService.getValidatorItem(o.type);return s==null?void 0:s.dropdownType}_initSelectionChange(){this.disposeWithMe(this._sheetsSelectionsService.selectionMoveEnd$.subscribe(e=>{e&&e.every(e=>!(e.primary&&this._getDropdownByCell(e.primary.unitId,e.primary.sheetId,e.primary.actualRow,e.primary.actualColumn)))&&this.hideDropdown()}))}showDropdown(e){let{location:t}=e,{row:n,col:r,unitId:i,subUnitId:a,workbook:o,worksheet:s}=t;if(this._currentPopup&&this._currentPopup.dispose(),this._zenVisible)return;this._activeDropdown=e,this._activeDropdown$.next(this._activeDropdown);let m=this._sheetDataValidationModel.getRuleByLocation(i,a,n,r);if(!m)return;let h=this._dataValidatorRegistryService.getValidatorItem(m.type);if(!(h!=null&&h.dropdownType))return;let _,v=async(e,t)=>{var d,f,_;if(!e)return!0;let v=e,y=s.getCell(n,r),b=v.format(t===`date`?`YYYY-MM-DD 00:00:00`:`YYYY-MM-DD HH:mm:ss`),x=(d=c.numfmt.parseDate(b))==null?void 0:d.v,S=t===`time`?x%1:x,C=o.getStyles().getStyleByCell(y),w=(f=C==null||(_=C.n)==null?void 0:_.pattern)==null?``:f;return m.errorStyle!==c.DataValidationErrorStyle.STOP||await h.validator({value:S,unitId:i,subUnitId:a,row:n,column:r,worksheet:s,workbook:o,interceptValue:b.replace(`Z`,``).replace(`T`,` `),t:c.CellValueType.NUMBER},m)?(await this._commandService.executeCommand(u.SetRangeValuesCommand.id,{unitId:i,subUnitId:a,range:{startColumn:r,endColumn:r,startRow:n,endRow:n},value:{v:S,t:2,p:null,f:null,si:null,s:{n:{pattern:I(t,w)}}}}),await this._commandService.executeCommand(g.SetCellEditVisibleOperation.id,{visible:!1,eventType:l.DeviceInputEventType.Keyboard,unitId:i,keycode:p.KeyCode.ESC}),!0):(this._injector.has(P)&&this._injector.get(P).showReject(h.getRuleFinalError(m,{row:n,col:r,unitId:i,subUnitId:a})),!1)},y;switch(h.dropdownType){case f.DataValidatorDropdownType.DATE:{var b;let e=F((0,d.getCellValueOrigin)(s.getCellRaw(n,r))),i=!!((b=m.bizInfo)!=null&&b.showTime);y={location:t,type:`datepicker`,props:{showTime:i,onChange:e=>v(e,i?`datetime`:`date`),defaultValue:e,patternType:`date`}};break}case f.DataValidatorDropdownType.TIME:y={location:t,type:`datepicker`,props:{onChange:e=>v(e,`time`),defaultValue:F((0,d.getCellValueOrigin)(s.getCellRaw(n,r))),patternType:`time`}};break;case f.DataValidatorDropdownType.DATETIME:y={location:t,type:`datepicker`,props:{onChange:e=>v(e,`datetime`),defaultValue:F((0,d.getCellValueOrigin)(s.getCellRaw(n,r))),patternType:`datetime`}};break;case f.DataValidatorDropdownType.LIST:case f.DataValidatorDropdownType.MULTIPLE_LIST:{var x,S,C,w;let e=h.dropdownType===f.DataValidatorDropdownType.MULTIPLE_LIST,o=async t=>{let o=(0,d.serializeListOptions)(t),s={unitId:i,subUnitId:a,range:{startColumn:r,endColumn:r,startRow:n,endRow:n},value:{v:o,p:null,f:null,si:null}};return this._commandService.executeCommand(u.SetRangeValuesCommand.id,s),this._editorBridgeService.isVisible().visible&&await this._commandService.executeCommand(g.SetCellEditVisibleOperation.id,{visible:!1,eventType:l.DeviceInputEventType.Keyboard,unitId:i,keycode:p.KeyCode.ESC}),!e},v=(m==null?void 0:m.renderMode)===c.DataValidationRenderMode.CUSTOM||(m==null?void 0:m.renderMode)===void 0,b=h.getListWithColor(m,i,a),T=(0,d.getDataValidationCellValue)(s.getCellRaw(n,r));y={location:t,type:`list`,props:{onChange:e=>o(e),options:b.map(e=>({label:e.label,value:e.label,color:v||e.color?e.color||`#ECECEC`:`transparent`})),onEdit:()=>{this._commandService.executeCommand(z.id,{ruleId:m.uid}),_==null||_.dispose()},defaultValue:T,multiple:e,showEdit:(x=(S=this._configService.getConfig(`sheets-data-validation-ui.config`))==null?void 0:S.showEditOnDropdown)==null?!0:x,showSearch:(C=(w=this._configService.getConfig(`sheets-data-validation-ui.config`))==null?void 0:w.showSearchOnDropdown)==null?!0:C}};break}case f.DataValidatorDropdownType.CASCADE:var T;y={type:`cascader`,props:{onChange:e=>{let t={unitId:i,subUnitId:a,range:{startColumn:r,endColumn:r,startRow:n,endRow:n},value:{v:e.join(`/`),p:null,f:null,si:null}};return this._commandService.syncExecuteCommand(u.SetRangeValuesCommand.id,t),this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(g.SetCellEditVisibleOperation.id,{visible:!1,eventType:l.DeviceInputEventType.Keyboard,unitId:i,keycode:p.KeyCode.ESC}),!0},defaultValue:(0,d.getDataValidationCellValue)(s.getCellRaw(n,r)).split(`/`),options:JSON.parse((T=m.formula1)==null?`[]`:T)},location:t};break;case f.DataValidatorDropdownType.COLOR:y={type:`color`,props:{onChange:e=>{let t={unitId:i,subUnitId:a,range:{startColumn:r,endColumn:r,startRow:n,endRow:n},value:{v:e,p:null,f:null,si:null}};return this._commandService.syncExecuteCommand(u.SetRangeValuesCommand.id,t),this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(g.SetCellEditVisibleOperation.id,{visible:!1,eventType:l.DeviceInputEventType.Keyboard,unitId:i,keycode:p.KeyCode.ESC}),!0},defaultValue:(0,d.getDataValidationCellValue)(s.getCellRaw(n,r))},location:t};break;default:throw Error(`[DataValidationDropdownManagerService]: unknown type!`)}if(_=this._cellDropdownManagerService.showDropdown({...y,onHide:()=>{this._activeDropdown=null,this._activeDropdown$.next(null)}}),!_)throw Error(`[DataValidationDropdownManagerService]: cannot show dropdown!`);let E=new c.DisposableCollection;E.add(_),E.add({dispose:()=>{var e,t;(e=this._activeDropdown)==null||(t=e.onHide)==null||t.call(e)}}),this._currentPopup=E}hideDropdown(){this._activeDropdown&&(this._currentPopup&&this._currentPopup.dispose(),this._currentPopup=null,this._activeDropdown=null,this._activeDropdown$.next(null))}showDataValidationDropdown(e,t,n,r,i){let a=this._univerInstanceService.getUnit(e,c.UniverInstanceType.UNIVER_SHEET);if(!a)return;let o=a.getSheetBySheetId(t);if(!o)return;let s=this._dataValidationModel.getRuleByLocation(a.getUnitId(),o.getSheetId(),n,r);if(!s)return;let l=this._dataValidatorRegistryService.getValidatorItem(s.type);if(!l||!l.dropdownType){this.hideDropdown();return}this.showDropdown({location:{workbook:a,worksheet:o,row:n,col:r,unitId:e,subUnitId:t},onHide:i})}};L=A([k(0,c.IUniverInstanceService),k(1,(0,c.Inject)(f.DataValidatorRegistryService)),k(2,p.IZenZoneService),k(3,(0,c.Inject)(d.SheetDataValidationModel)),k(4,(0,c.Inject)(u.SheetsSelectionsService)),k(5,(0,c.Inject)(g.ISheetCellDropdownManagerService)),k(6,(0,c.Inject)(d.SheetDataValidationModel)),k(7,c.ICommandService),k(8,g.IEditorBridgeService),k(9,(0,c.Inject)(c.Injector)),k(10,c.IConfigService)],L);const R=`DataValidationPanel`,z={id:`data-validation.operation.open-validation-panel`,type:c.CommandType.OPERATION,handler(e,t){if(!t)return!1;let{ruleId:n,isAdd:r}=t,i=e.get(j),a=e.get(f.DataValidationModel),o=e.get(c.IUniverInstanceService),s=e.get(p.ISidebarService),l=(0,u.getSheetCommandTarget)(o);if(!l)return!1;let{unitId:d,subUnitId:m}=l,h=n?a.getRuleById(d,m,n):void 0;i.open(),i.setActiveRule(h&&{unitId:d,subUnitId:m,rule:h});let g=s.open({id:R,header:{title:r?`dataValidation.panel.addTitle`:`dataValidation.panel.title`},children:{label:R},width:312,onClose:()=>i.close()});return i.setCloseDisposable(g),!0}},B={id:`data-validation.operation.close-validation-panel`,type:c.CommandType.OPERATION,handler(e){return e.get(j).close(),!0}},V={id:`data-validation.operation.toggle-validation-panel`,type:c.CommandType.OPERATION,handler(e){let t=e.get(c.ICommandService),n=e.get(j);return n.open(),n.isOpen?t.executeCommand(B.id):t.executeCommand(z.id),!0}},H={type:c.CommandType.OPERATION,id:`sheet.operation.show-data-validation-dropdown`,handler(e,t){if(!t)return!1;let n=e.get(L),{unitId:r,subUnitId:i,row:a,column:o}=t,s=n.activeDropdown,c=s==null?void 0:s.location;return c&&c.unitId===r&&c.subUnitId===i&&c.row===a&&c.col===o||n.showDataValidationDropdown(r,i,a,o),!0}},U={type:c.CommandType.OPERATION,id:`sheet.operation.hide-data-validation-dropdown`,handler(e,t){return t?(e.get(L).hideDropdown(),!0):!1}},W={type:c.CommandType.COMMAND,id:`data-validation.command.addRuleAndOpen`,handler(e){let t=(0,u.getSheetCommandTarget)(e.get(c.IUniverInstanceService));if(!t)return!1;let{workbook:n,worksheet:r}=t,i=(0,d.createDefaultNewRule)(e),a=e.get(c.ICommandService),o={rule:i,unitId:n.getUnitId(),subUnitId:r.getSheetId()};return a.syncExecuteCommand(d.AddSheetDataValidationCommand.id,o)?(a.syncExecuteCommand(z.id,{ruleId:i.uid,isAdd:!0}),!0):!1}},G=`SHEET_DATA_VALIDATION_ALERT`;let K=class extends c.Disposable{constructor(e,t,n,r,i,a){super(),this._hoverManagerService=e,this._cellAlertManagerService=t,this._univerInstanceService=n,this._localeService=r,this._zenZoneService=i,this._dataValidationModel=a,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe((0,m.debounceTime)(100)).subscribe(e=>{if(e){let n=this._univerInstanceService.getUnit(e.location.unitId,c.UniverInstanceType.UNIVER_SHEET),r=n.getSheetBySheetId(e.location.subUnitId);if(!r)return;let i=this._dataValidationModel.getRuleByLocation(e.location.unitId,e.location.subUnitId,e.location.row,e.location.col);if(!i){this._cellAlertManagerService.removeAlert(G);return}if(this._dataValidationModel.validator(i,{...e.location,workbook:n,worksheet:r})===c.DataValidationStatus.INVALID){var t;let n=this._cellAlertManagerService.currentAlert.get(G),r=n==null||(t=n.alert)==null?void 0:t.location;if(r&&r.row===e.location.row&&r.col===e.location.col&&r.subUnitId===e.location.subUnitId&&r.unitId===e.location.unitId){this._cellAlertManagerService.removeAlert(G);return}let a=this._dataValidationModel.getValidator(i.type);if(!a){this._cellAlertManagerService.removeAlert(G);return}this._cellAlertManagerService.showAlert({type:g.CellAlertType.ERROR,title:this._localeService.t(`dataValidation.error.title`),message:a==null?void 0:a.getRuleFinalError(i,e.location),location:e.location,width:200,height:74,key:G});return}}this._cellAlertManagerService.removeAlert(G)}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._cellAlertManagerService.removeAlert(G)}))}};K=A([k(0,(0,c.Inject)(g.HoverManagerService)),k(1,(0,c.Inject)(g.CellAlertManagerService)),k(2,c.IUniverInstanceService),k(3,(0,c.Inject)(c.LocaleService)),k(4,p.IZenZoneService),k(5,(0,c.Inject)(d.SheetDataValidationModel))],K);let q=class extends c.Disposable{constructor(e,t,n){super(),this._autoFillService=e,this._sheetDataValidationModel=t,this._injector=n,this._initAutoFill()}_initAutoFill(){let e=()=>({redos:[],undos:[]}),t=(e,t)=>{let{source:n,target:r,unitId:i,subUnitId:a}=e,o=this._sheetDataValidationModel.getRuleObjectMatrix(i,a).clone(),s=(0,g.virtualizeDiscreteRanges)([n,r]),[l,f]=s.ranges,{mapFunc:p}=s,m={row:l.startRow,col:l.startColumn},h=u.AutoFillTools.getAutoFillRepeatRange(l,f),_=new c.ObjectMatrix,v=new Set;h.forEach(e=>{let t=e.repeatStartCell,n=e.relativeRange,r={startRow:m.row,startColumn:m.col,endColumn:m.col,endRow:m.row},o={startRow:t.row,startColumn:t.col,endColumn:t.col,endRow:t.row};c.Range.foreach(n,(e,t)=>{let n=c.Rectangle.getPositionRange({startRow:e,startColumn:t,endColumn:t,endRow:e},r),{row:s,col:l}=p(n.startRow,n.startColumn),u=this._sheetDataValidationModel.getRuleIdByLocation(i,a,s,l)||``,d=c.Rectangle.getPositionRange({startRow:e,startColumn:t,endColumn:t,endRow:e},o),{row:f,col:m}=p(d.startRow,d.startColumn);_.setValue(f,m,u),v.add(u)})});let y=Array.from(v).map(e=>({id:e,ranges:(0,c.queryObjectMatrix)(_,t=>t===e)}));o.addRangeRules(y);let{redoMutations:b,undoMutations:x}=(0,d.getDataValidationDiffMutations)(i,a,o.diff(this._sheetDataValidationModel.getRules(i,a)),this._injector,`patched`,t===u.AUTO_FILL_APPLY_TYPE.ONLY_FORMAT);return{undos:x,redos:b}},n={id:d.DATA_VALIDATION_PLUGIN_NAME,onBeforeFillData:e=>{let{source:t,unitId:n,subUnitId:r}=e;for(let e of t.rows)for(let i of t.cols){let t=this._sheetDataValidationModel.getRuleByLocation(n,r,e,i);if(t&&t.type===c.DataValidationType.CHECKBOX){this._autoFillService.setDisableApplyType(u.AUTO_FILL_APPLY_TYPE.SERIES,!0);return}}},onFillData:(n,r,i)=>i===u.AUTO_FILL_APPLY_TYPE.COPY||i===u.AUTO_FILL_APPLY_TYPE.ONLY_FORMAT||i===u.AUTO_FILL_APPLY_TYPE.SERIES?t(n,i):e(),onAfterFillData:()=>{}};this.disposeWithMe(this._autoFillService.addHook(n))}};q=A([k(0,u.IAutoFillService),k(1,(0,c.Inject)(d.SheetDataValidationModel)),k(2,(0,c.Inject)(c.Injector))],q);let J=class extends c.Disposable{constructor(e,t,n){super(),this._sheetClipboardService=e,this._sheetDataValidationModel=t,this._injector=n,O(this,`_copyInfo`,void 0),this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:d.DATA_VALIDATION_PLUGIN_NAME,onBeforeCopy:(e,t,n)=>this._collect(e,t,n),onPasteCells:(e,t,n,r)=>{let{copyType:i=g.COPY_TYPE.COPY,pasteType:a}=r,{range:o}=e||{},{range:s,unitId:c,subUnitId:l}=t;return this._generateMutations(s,{copyType:i,pasteType:a,copyRange:o,unitId:c,subUnitId:l})}})}_collect(e,t,n){let r=new c.ObjectMatrix;this._copyInfo={unitId:e,subUnitId:t,matrix:r};let i=this._injector.invoke(r=>(0,u.rangeToDiscreteRange)(n,r,e,t));if(!i)return;let{rows:a,cols:o}=i;a.forEach((n,i)=>{o.forEach((a,o)=>{let s=this._sheetDataValidationModel.getRuleIdByLocation(e,t,n,a);r.setValue(i,o,s==null?``:s)})})}_generateMutations(e,t){if(!this._copyInfo)return{redos:[],undos:[]};if(t.copyType===g.COPY_TYPE.CUT)return this._copyInfo=null,{redos:[],undos:[]};if(!this._copyInfo||!this._copyInfo.matrix.getSizeOf()||!t.copyRange||[g.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_COL_WIDTH,g.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_VALUE,g.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMAT,g.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMULA].includes(t.pasteType))return{redos:[],undos:[]};let{unitId:n,subUnitId:r}=this._copyInfo;if(t.unitId!==n||r!==t.subUnitId){let i=this._sheetDataValidationModel.getRuleObjectMatrix(t.unitId,t.subUnitId).clone(),a=new c.ObjectMatrix,o=new Set,{ranges:[s,l],mapFunc:u}=(0,g.virtualizeDiscreteRanges)([t.copyRange,e]),f=(0,g.getRepeatRange)(s,l,!0),p=new Map;f.forEach(({startRange:e})=>{var i;(i=this._copyInfo)==null||i.matrix.forValue((i,s,l)=>{let d=c.Rectangle.getPositionRange({startRow:i,endRow:i,startColumn:s,endColumn:s},e),f=`${r}-${l}`,m=this._sheetDataValidationModel.getRuleById(n,r,l);!this._sheetDataValidationModel.getRuleById(t.unitId,t.subUnitId,f)&&m&&p.set(f,{...m,uid:f});let{row:h,col:g}=u(d.startRow,d.startColumn);o.add(f),a.setValue(h,g,f)})});let m=Array.from(o).map(e=>({id:e,ranges:(0,c.queryObjectMatrix)(a,t=>t===e)}));i.addRangeRules(m);let{redoMutations:h,undoMutations:_}=(0,d.getDataValidationDiffMutations)(t.unitId,t.subUnitId,i.diffWithAddition(this._sheetDataValidationModel.getRules(t.unitId,t.subUnitId),p.values()),this._injector,`patched`,!1);return{redos:h,undos:_}}else{let i=this._sheetDataValidationModel.getRuleObjectMatrix(n,r).clone(),a=new c.ObjectMatrix,o=new Set,{ranges:[s,l],mapFunc:u}=(0,g.virtualizeDiscreteRanges)([t.copyRange,e]);(0,g.getRepeatRange)(s,l,!0).forEach(({startRange:e})=>{var t;(t=this._copyInfo)==null||t.matrix.forValue((t,n,r)=>{let i=c.Rectangle.getPositionRange({startRow:t,endRow:t,startColumn:n,endColumn:n},e),{row:s,col:l}=u(i.startRow,i.startColumn);a.setValue(s,l,r),o.add(r)})});let f=Array.from(o).map(e=>({id:e,ranges:(0,c.queryObjectMatrix)(a,t=>t===e)}));i.addRangeRules(f);let{redoMutations:p,undoMutations:m}=(0,d.getDataValidationDiffMutations)(n,r,i.diff(this._sheetDataValidationModel.getRules(n,r)),this._injector,`patched`,!1);return{redos:p,undos:m}}}};J=A([k(0,g.ISheetClipboardService),k(1,(0,c.Inject)(d.SheetDataValidationModel)),k(2,(0,c.Inject)(c.Injector))],J);let Y=class extends c.Disposable{constructor(e,t,n){super(),this._localeService=e,this._commandService=t,this._sheetPermissionCheckController=n,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===d.AddSheetDataValidationCommand.id){let{unitId:t,subUnitId:n,rule:{ranges:r}}=e.params;this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[u.WorkbookEditablePermission],rangeTypes:[u.RangeProtectionPermissionEditPoint],worksheetTypes:[u.WorksheetEditPermission,u.WorksheetSetCellStylePermission]},r,t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.setStyleErr`))}if(e.id===d.UpdateSheetDataValidationRangeCommand.id){let{unitId:t,subUnitId:n,ranges:r}=e.params;this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[u.WorkbookEditablePermission],rangeTypes:[u.RangeProtectionPermissionEditPoint],worksheetTypes:[u.WorksheetEditPermission,u.WorksheetSetCellStylePermission]},r,t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.setStyleErr`))}}))}};Y=A([k(0,(0,c.Inject)(c.LocaleService)),k(1,c.ICommandService),k(2,(0,c.Inject)(u.SheetPermissionCheckController))],Y);const ee=`sheet.menu.data-validation`;function te(e){return{id:ee,type:p.MenuItemType.SUBITEMS,icon:`DataValidationIcon`,tooltip:`dataValidation.title`,hidden$:(0,p.getMenuHiddenObservable)(e,c.UniverInstanceType.UNIVER_SHEET),disabled$:(0,g.getCurrentRangeDisable$)(e,{workbookTypes:[u.WorkbookEditablePermission],worksheetTypes:[u.WorksheetSetCellStylePermission,u.WorksheetEditPermission],rangeTypes:[u.RangeProtectionPermissionEditPoint]})}}function X(e){return{id:z.id,title:`dataValidation.panel.title`,type:p.MenuItemType.BUTTON}}function ne(e){return{id:W.id,title:`dataValidation.panel.add`,type:p.MenuItemType.BUTTON}}const re={[p.RibbonDataGroup.RULES]:{[ee]:{order:0,menuItemFactory:te,[z.id]:{order:0,menuItemFactory:X},[W.id]:{order:1,menuItemFactory:ne}}}},ie={tr:{size:6,color:`#fe4b4b`}};let Z=class extends c.RxDisposable{constructor(e,t,n,r,i,a,o,s,c,l,u){super(),this._commandService=e,this._menuManagerService=t,this._renderManagerService=n,this._univerInstanceService=r,this._autoHeightController=i,this._dropdownManagerService=a,this._sheetDataValidationModel=o,this._dataValidatorRegistryService=s,this._sheetInterceptorService=c,this._dataValidationCacheService=l,this._editorBridgeService=u,this._initMenu(),this._initDropdown(),this._initViewModelIntercept(),this._initAutoHeight()}_initMenu(){this._menuManagerService.mergeMenu(re)}_initDropdown(){this._editorBridgeService&&this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{if(!e.visible){var t;((t=this._dropdownManagerService.activeDropdown)==null?void 0:t.trigger)===`editor-bridge`&&this._dropdownManagerService.hideDropdown();return}let n=this._editorBridgeService.getEditCellState();if(n){let{unitId:e,sheetId:t,row:r,column:i}=n,a=this._univerInstanceService.getUniverSheetInstance(e);if(!a)return;let o=this._sheetDataValidationModel.getRuleByLocation(e,t,r,i);if(!o)return;let s=this._dataValidatorRegistryService.getValidatorItem(o.type);if(!(s!=null&&s.dropdownType))return;let c=a.getActiveSheet();if(!c)return;let l=this._dropdownManagerService.activeDropdown,u=l==null?void 0:l.location;if(u&&u.unitId===e&&u.subUnitId===t&&u.row===r&&u.col===i)return;this._dropdownManagerService.showDropdown({location:{unitId:e,subUnitId:t,row:r,col:i,workbook:a,worksheet:c},trigger:`editor-bridge`,closeOnOutSide:!1})}}))}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(u.INTERCEPTOR_POINT.CELL_CONTENT,{effect:c.InterceptorEffectEnum.Style,priority:u.InterceptCellContentPriority.DATA_VALIDATION,handler:(e,t,n)=>{var r,i,a,o,s;let{row:l,col:u,unitId:f,subUnitId:p,workbook:m,worksheet:h}=t,_=this._sheetDataValidationModel.getRuleIdByLocation(f,p,l,u);if(!_)return n(e);let v=this._sheetDataValidationModel.getRuleById(f,p,_);if(!v)return n(e);let y=(r=this._dataValidationCacheService.getValue(f,p,l,u))==null?c.DataValidationStatus.VALID:r,b=this._dataValidatorRegistryService.getValidatorItem(v.type),x=t.rawData,S,C={get value(){var e;return S===void 0&&(S=(e=(0,d.getCellValueOrigin)(x))==null?null:e),S}},w={get value(){var e;return`${(e=C.value)==null?``:e}`}};return(!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,...y===c.DataValidationStatus.INVALID?ie:null},e.customRender=[...(i=e==null?void 0:e.customRender)==null?[]:i,...b!=null&&b.canvasRender?[b.canvasRender]:[]],e.fontRenderExtension={...e==null?void 0:e.fontRenderExtension,isSkip:(e==null||(a=e.fontRenderExtension)==null?void 0:a.isSkip)||(b==null||(o=b.skipDefaultFontRender)==null?void 0:o.call(b,v,C.value,t))},e.interceptorStyle={...e==null?void 0:e.interceptorStyle,...b==null?void 0:b.getExtraStyle(v,w.value,{get style(){let t=m.getStyles();return(typeof(e==null?void 0:e.s)==`string`?t.get(e==null?void 0:e.s):e==null?void 0:e.s)||{}}},l,u)},e.interceptorAutoHeight=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(f))==null||(t=t.with(g.SheetSkeletonManagerService).getSkeletonParam(p))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(l,u),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?l:n,(r=s==null?void 0:s.startColumn)==null?u:r),unitId:f,subUnitId:p,row:l,col:u,workbook:m,worksheet:h};return b==null||(i=b.canvasRender)==null||(a=i.calcCellAutoHeight)==null?void 0:a.call(i,c)},e.interceptorAutoWidth=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(f))==null||(t=t.with(g.SheetSkeletonManagerService).getSkeletonParam(p))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(l,u),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?l:n,(r=s==null?void 0:s.startColumn)==null?u:r),unitId:f,subUnitId:p,row:l,col:u,workbook:m,worksheet:h};return b==null||(i=b.canvasRender)==null||(a=i.calcCellAutoWidth)==null?void 0:a.call(i,c)},e.coverable=((s=e==null?void 0:e.coverable)==null?!0:s)&&!(v.type===c.DataValidationType.LIST||v.type===c.DataValidationType.LIST_MULTIPLE),n(e)}}))}_initAutoHeight(){this._sheetDataValidationModel.ruleChange$.pipe((0,m.filter)(e=>e.source===`command`),(0,m.bufferTime)(100)).subscribe(e=>{if(e.length===0)return;let t=[];e.forEach(e=>{if(e.rule.type===c.DataValidationType.LIST_MULTIPLE||e.rule.type===c.DataValidationType.LIST){var n;(n=e.rule)!=null&&n.ranges&&t.push(...e.rule.ranges)}}),t.length&&(0,c.sequenceExecute)(this._autoHeightController.getUndoRedoParamsOfAutoHeight(t).redos,this._commandService)})}};Z=A([k(0,c.ICommandService),k(1,p.IMenuManagerService),k(2,l.IRenderManagerService),k(3,c.IUniverInstanceService),k(4,(0,c.Inject)(g.AutoHeightController)),k(5,(0,c.Inject)(L)),k(6,(0,c.Inject)(d.SheetDataValidationModel)),k(7,(0,c.Inject)(f.DataValidatorRegistryService)),k(8,(0,c.Inject)(u.SheetInterceptorService)),k(9,(0,c.Inject)(d.DataValidationCacheService)),k(10,(0,c.Optional)(g.IEditorBridgeService))],Z);let ae=class extends c.RxDisposable{constructor(e,t,n,r,i,a,o){super(),this._commandService=e,this._renderManagerService=t,this._autoHeightController=n,this._dataValidatorRegistryService=r,this._sheetInterceptorService=i,this._sheetDataValidationModel=a,this._dataValidationCacheService=o,this._initViewModelIntercept(),this._initAutoHeight()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(u.INTERCEPTOR_POINT.CELL_CONTENT,{effect:c.InterceptorEffectEnum.Style,priority:u.InterceptCellContentPriority.DATA_VALIDATION,handler:(e,t,n)=>{var r,i,a,o,s;let{row:l,col:u,unitId:f,subUnitId:p,workbook:m,worksheet:h}=t,_=this._sheetDataValidationModel.getRuleIdByLocation(f,p,l,u);if(!_)return n(e);let v=this._sheetDataValidationModel.getRuleById(f,p,_);if(!v)return n(e);let y=(r=this._dataValidationCacheService.getValue(f,p,l,u))==null?c.DataValidationStatus.VALID:r,b=this._dataValidatorRegistryService.getValidatorItem(v.type),x=(0,d.getCellValueOrigin)(h.getCellRaw(l,u)),S=`${x==null?``:x}`;return(!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,...y===c.DataValidationStatus.INVALID?ie:null},e.customRender=[...(i=e==null?void 0:e.customRender)==null?[]:i,...b!=null&&b.canvasRender?[b.canvasRender]:[]],e.fontRenderExtension={...e==null?void 0:e.fontRenderExtension,isSkip:(e==null||(a=e.fontRenderExtension)==null?void 0:a.isSkip)||(b==null||(o=b.skipDefaultFontRender)==null?void 0:o.call(b,v,x,t))},e.interceptorStyle={...e==null?void 0:e.interceptorStyle,...b==null?void 0:b.getExtraStyle(v,S,{get style(){let t=m.getStyles();return(typeof(e==null?void 0:e.s)==`string`?t.get(e==null?void 0:e.s):e==null?void 0:e.s)||{}}},l,u)},e.interceptorAutoHeight=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(f))==null||(t=t.with(g.SheetSkeletonManagerService).getSkeletonParam(p))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(l,u),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?l:n,(r=s==null?void 0:s.startColumn)==null?u:r),unitId:f,subUnitId:p,row:l,col:u,workbook:m,worksheet:h};return b==null||(i=b.canvasRender)==null||(a=i.calcCellAutoHeight)==null?void 0:a.call(i,c)},e.interceptorAutoWidth=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(f))==null||(t=t.with(g.SheetSkeletonManagerService).getSkeletonParam(p))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(l,u),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?l:n,(r=s==null?void 0:s.startColumn)==null?u:r),unitId:f,subUnitId:p,row:l,col:u,workbook:m,worksheet:h};return b==null||(i=b.canvasRender)==null||(a=i.calcCellAutoWidth)==null?void 0:a.call(i,c)},e.coverable=((s=e==null?void 0:e.coverable)==null?!0:s)&&!(v.type===c.DataValidationType.LIST||v.type===c.DataValidationType.LIST_MULTIPLE),n(e)}}))}_initAutoHeight(){this._sheetDataValidationModel.ruleChange$.pipe((0,m.filter)(e=>e.source===`command`),(0,m.bufferTime)(16)).subscribe(e=>{let t=[];e.forEach(e=>{if(e.rule.type===c.DataValidationType.LIST_MULTIPLE||e.rule.type===c.DataValidationType.LIST){var n;(n=e.rule)!=null&&n.ranges&&t.push(...e.rule.ranges)}}),t.length&&(0,c.sequenceExecute)(this._autoHeightController.getUndoRedoParamsOfAutoHeight(t).redos,this._commandService)})}};ae=A([k(0,c.ICommandService),k(1,l.IRenderManagerService),k(2,(0,c.Inject)(g.AutoHeightController)),k(3,(0,c.Inject)(f.DataValidatorRegistryService)),k(4,(0,c.Inject)(u.SheetInterceptorService)),k(5,(0,c.Inject)(d.SheetDataValidationModel)),k(6,(0,c.Inject)(d.DataValidationCacheService))],ae);let oe=class extends c.Disposable{constructor(e,t,n){super(),this._context=e,this._sheetDataValidationModel=t,this._sheetSkeletonManagerService=n,this._initSkeletonChange()}_initSkeletonChange(){this.disposeWithMe(this._sheetDataValidationModel.validStatusChange$.pipe((0,c.bufferDebounceTime)(16)).subscribe(e=>{var t;if(!e.length)return;let n=new Set;e.forEach(e=>{n.add(e.subUnitId)}),n.forEach(e=>{var t;(t=this._sheetSkeletonManagerService.getSkeletonParam(e))==null||t.skeleton.makeDirty(!0)}),(t=this._context.mainComponent)==null||t.makeForceDirty()}))}};oe=A([k(1,(0,c.Inject)(d.SheetDataValidationModel)),k(2,(0,c.Inject)(g.SheetSkeletonManagerService))],oe);function se(e){var t;let n=(0,p.useDependency)(c.LocaleService),r=(0,p.useDependency)(p.ComponentManager),{value:i,onChange:a,extraComponent:o}=e,[s,l]=(0,v.useState)(!1),u=o?r.get(o):null;return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`
|
|
2
2
|
univer-mb-3 univer-flex univer-cursor-pointer univer-items-center univer-text-sm univer-text-gray-900
|
|
3
3
|
dark:!univer-text-white
|
|
4
4
|
`,onClick:()=>l(!s),children:[n.t(`dataValidation.panel.options`),s?(0,S.jsx)(y.MoreUpIcon,{className:`univer-ml-1`}):(0,S.jsx)(y.MoreDownIcon,{className:`univer-ml-1`})]}),s&&(0,S.jsxs)(S.Fragment,{children:[u?(0,S.jsx)(u,{value:i,onChange:a}):null,(0,S.jsx)(_.FormLayout,{label:n.t(`dataValidation.panel.invalid`),children:(0,S.jsxs)(_.RadioGroup,{value:`${(t=i.errorStyle)==null?c.DataValidationErrorStyle.WARNING:t}`,onChange:e=>a({...i,errorStyle:+e}),children:[(0,S.jsx)(_.Radio,{value:`${c.DataValidationErrorStyle.WARNING}`,children:n.t(`dataValidation.panel.showWarning`)}),(0,S.jsx)(_.Radio,{value:`${c.DataValidationErrorStyle.STOP}`,children:n.t(`dataValidation.panel.rejectInput`)})]})}),(0,S.jsx)(_.FormLayout,{label:n.t(`dataValidation.panel.messageInfo`),children:(0,S.jsx)(_.Checkbox,{checked:i.showErrorMessage,onChange:()=>a({...i,showErrorMessage:!i.showErrorMessage}),children:n.t(`dataValidation.panel.showInfo`)})}),i.showErrorMessage?(0,S.jsx)(_.FormLayout,{children:(0,S.jsx)(_.Input,{value:i.error,onChange:e=>a({...i,error:e})})}):null]})]})}const ce=e=>(0,c.debounce)(async(t,n,r,i)=>{let a=await e.executeCommand(t,n,r);i==null||i(a)},1e3);function le(e,t,n){var r;if(t){var i;return((i=e.getUnit(t))==null||(i=i.getSheetBySheetName(n))==null?void 0:i.getSheetId())||``}return((r=e.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET))==null||(r=r.getSheetBySheetName(n))==null?void 0:r.getSheetId())||``}function ue(){var e,t;let[n,r]=(0,v.useState)(0),i=(0,p.useDependency)(j),{unitId:a,subUnitId:o,rule:s}=(0,p.useObservable)(i.activeRule$,i.activeRule)||{},l=s.uid,h=(0,p.useDependency)(f.DataValidatorRegistryService),g=(0,p.useDependency)(c.IUniverInstanceService),y=(0,p.useDependency)(p.ComponentManager),C=(0,p.useDependency)(c.ICommandService),w=(0,p.useDependency)(f.DataValidationModel),T=(0,p.useDependency)(c.LocaleService),E=(0,p.useObservable)(()=>g.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET),void 0,void 0,[]),D=(0,p.useObservable)(()=>{var e;return(e=E==null?void 0:E.activeSheet$)==null?(0,m.of)(null):e},void 0,void 0,[]),[O,k]=(0,v.useState)(s),A=h.getValidatorItem(O.type),[M,N]=(0,v.useState)(!1),P=h.getValidatorsByScope(f.DataValidatorRegistryScope.SHEET),[F,I]=(0,v.useState)(()=>O.ranges.map(e=>({unitId:``,sheetId:``,range:e}))),L=(0,v.useMemo)(()=>ce(C),[C]),[R,z]=(0,v.useState)(!1),[B,V]=(0,v.useState)(!1),H=(0,v.useRef)(null),U=(0,p.useDependency)(u.SheetsSelectionsService);if((0,v.useEffect)(()=>()=>{let e=U.getCurrentLastSelection();e&&U.setSelections([e])},[U]),(0,v.useEffect)(()=>{C.onCommandExecuted(e=>{(e.id===c.UndoCommand.id||e.id===c.RedoCommand.id)&&setTimeout(()=>{let e=w.getRuleById(a,o,l);r(e=>e+1),e&&(k(e),I(e.ranges.map(e=>({unitId:``,sheetId:``,range:e}))))},20)})},[C,w,l,o,a]),!A)return null;let W=A.operators,G=A.operatorNames,K=O.operator?f.TWO_FORMULA_OPERATOR_COUNT.includes(O.operator):!1,q=()=>{(D==null?void 0:D.getSheetId())!==o&&C.syncExecuteCommand(u.SetWorksheetActiveOperation.id,{unitId:a,subUnitId:o})},J=()=>{var e;if(!((e=H.current)==null||(e=e.editor)==null)&&e.isFocus()){var t;Y((t=H.current)==null?void 0:t.getValue())}!O.ranges.length||R||(A.validatorFormula(O,a,o).success?i.setActiveRule(null):N(!0),q())},Y=(0,p.useEvent)(e=>{let t=e.split(`,`).filter(Boolean).map(b.deserializeRangeWithSheet).map(e=>{let t=e.sheetName;if(t){let n=le(g,e.unitId,t);return{...e,sheetId:n}}return{...e,sheetId:``}});if((0,c.isUnitRangesEqual)(t,F))return;I(t);let n=t.filter(e=>(!e.unitId||e.unitId===a)&&(!e.sheetId||e.sheetId===o)).map(e=>e.range);if(k({...O,ranges:n}),n.length===0)return;let r={unitId:a,subUnitId:o,ruleId:l,ranges:n};L(d.UpdateSheetDataValidationRangeCommand.id,r)}),ee=e=>{if((0,c.shallowEqual)(e,(0,f.getRuleSetting)(O)))return;k({...O,...e});let t={unitId:a,subUnitId:o,ruleId:l,setting:e};L(d.UpdateSheetDataValidationSettingCommand.id,t,void 0)},te=async()=>{await C.executeCommand(d.RemoveSheetDataValidationCommand.id,{ruleId:l,unitId:a,subUnitId:o}),i.setActiveRule(null),q()},X={type:O.type,operator:O.operator,formula1:O.formula1,formula2:O.formula2,allowBlank:O.allowBlank},ne=e=>{let t=h.getValidatorItem(e);if(!t)return;let n=t.operators,r=w.getRuleById(a,o,l),i=e===(r==null?void 0:r.type)||e.includes(`list`)&&r!=null&&r.type.includes(`list`)?{...r,type:e}:{...O,type:e,operator:n[0],formula1:void 0,formula2:void 0};k(i),C.executeCommand(d.UpdateSheetDataValidationSettingCommand.id,{unitId:a,subUnitId:o,ruleId:O.uid,setting:(0,f.getRuleSetting)(i)})},re=y.get(A.formulaInput),ie=(0,v.useMemo)(()=>F.map(e=>(0,b.serializeRange)(e.range)).join(`,`),[]),Z=(0,f.getRuleOptions)(O),ae=e=>{(0,c.shallowEqual)(e,(0,f.getRuleOptions)(O))||(k({...O,...e}),L(d.UpdateSheetDataValidationOptionsCommand.id,{unitId:a,subUnitId:o,ruleId:l,options:e}))},oe=W.length&&!O.operator;return(0,S.jsxs)(`div`,{"data-u-comp":`data-validation-detail`,className:`univer-py-2`,children:[(0,S.jsx)(_.FormLayout,{label:T.t(`dataValidation.panel.range`),error:!O.ranges.length||R?T.t(`dataValidation.panel.rangeError`):``,children:(0,S.jsx)(x.RangeSelector,{selectorRef:H,unitId:a,subUnitId:o,initialValue:ie,onChange:(e,t)=>{var n;!B&&(n=H.current)!=null&&n.verify()&&Y(t)},onFocusChange:(e,t)=>{var n;V(e),!e&&t&&(n=H.current)!=null&&n.verify()&&Y(t)},onVerify:e=>z(!e)})}),(0,S.jsx)(_.FormLayout,{label:T.t(`dataValidation.panel.type`),children:(0,S.jsx)(_.Select,{className:`univer-w-full`,value:O.type,options:P==null||(e=P.sort((e,t)=>e.order-t.order))==null?void 0:e.map(e=>({label:T.t(e.title),value:e.id})),onChange:ne})}),W!=null&&W.length?(0,S.jsx)(_.FormLayout,{label:T.t(`dataValidation.panel.operator`),children:(0,S.jsx)(_.Select,{className:`univer-w-full`,value:`${O.operator}`,options:[{value:``,label:T.t(`dataValidation.operators.legal`)},...W.map((e,t)=>({value:`${e}`,label:G[t]}))],onChange:e=>{ee({...X,operator:e})}})}):null,re&&!oe?(0,S.jsx)(re,{isTwoFormula:K,value:{formula1:O.formula1,formula2:O.formula2},onChange:e=>{ee({...X,...e})},showError:M,validResult:A.validatorFormula(O,a,o),unitId:a,subUnitId:o,ruleId:l},n+O.type):null,(0,S.jsx)(_.FormLayout,{children:(0,S.jsx)(_.Checkbox,{checked:(t=O.allowBlank)==null?!0:t,onChange:()=>{var e;return ee({...X,allowBlank:!((e=O.allowBlank)==null||e)})},children:T.t(`dataValidation.panel.allowBlank`)})}),(0,S.jsx)(se,{value:Z,onChange:ae,extraComponent:A.optionsInput}),(0,S.jsxs)(`div`,{className:`univer-mt-5 univer-flex univer-flex-row univer-justify-end`,children:[(0,S.jsx)(_.Button,{className:`univer-ml-3`,onClick:te,children:T.t(`dataValidation.panel.removeRule`)}),(0,S.jsx)(_.Button,{className:`univer-ml-3`,variant:`primary`,onClick:J,children:T.t(`dataValidation.panel.done`)})]})]})}const de=e=>{let{rule:t,onClick:n,unitId:r,subUnitId:i,disable:a}=e,o=(0,p.useDependency)(f.DataValidatorRegistryService),s=(0,p.useDependency)(c.ICommandService),l=(0,p.useDependency)(g.IMarkSelectionService),u=o.getValidatorItem(t.type),m=(0,v.useRef)(void 0),[h,x]=(0,v.useState)(!1),C=(0,p.useDependency)(c.ThemeService),w=(0,v.useMemo)(()=>{var e;let t=C.getColorFromTheme(`primary.600`),n=C.getColorFromTheme(`loop-color.2`),r=(e=C.getColorFromTheme(n))==null?t:e,i=new c.ColorKit(r).toRgb();return{fill:`rgba(${i.r}, ${i.g}, ${i.b}, 0.1)`,stroke:r}},[(0,p.useObservable)(C.currentTheme$)]),T=e=>{s.executeCommand(d.RemoveSheetDataValidationCommand.id,{ruleId:t.uid,unitId:r,subUnitId:i}),e.stopPropagation()};return(0,v.useEffect)(()=>()=>{if(m.current){var e;(e=m.current)==null||e.forEach(e=>{e&&l.removeShape(e)})}},[l]),(0,S.jsxs)(`div`,{className:(0,_.clsx)(`
|
package/lib/es/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{CellValueType as e,ColorKit as t,CommandType as n,DEFAULT_STYLES as r,DataValidationErrorStyle as i,DataValidationRenderMode as a,DataValidationStatus as o,DataValidationType as s,DependentOn as c,Disposable as l,DisposableCollection as u,HorizontalAlign as d,ICommandService as f,IConfigService as p,IUniverInstanceService as m,Inject as h,Injector as g,InterceptorEffectEnum as _,LocaleService as v,ObjectMatrix as y,Optional as b,Plugin as x,Range as S,Rectangle as C,RedoCommand as w,RxDisposable as T,ThemeService as E,UndoCommand as D,UniverInstanceType as O,VerticalAlign as k,WrapStrategy as A,bufferDebounceTime as ee,dayjs as j,debounce as M,generateRandomId as te,isFormulaString as N,isUnitRangesEqual as ne,merge as P,numfmt as F,queryObjectMatrix as I,sequenceExecute as re,shallowEqual as ie,toDisposable as ae}from"@univerjs/core";import{CURSOR_TYPE as L,CheckboxShape as oe,DeviceInputEventType as R,DocSimpleSkeleton as z,FontCache as se,IRenderManagerService as B,Rect as ce,Shape as le,Text as ue,Transform as de,fixLineWidthByScale as fe,getCurrentTypeOfRenderer as pe,getFontStyleString as me}from"@univerjs/engine-render";import{AUTO_FILL_APPLY_TYPE as he,AutoFillTools as ge,IAutoFillService as _e,INTERCEPTOR_POINT as ve,InterceptCellContentPriority as ye,RangeProtectionPermissionEditPoint as be,SetRangeValuesCommand as xe,SetWorksheetActiveOperation as Se,SheetInterceptorService as Ce,SheetPermissionCheckController as we,SheetsSelectionsService as Te,VALIDATE_CELL as Ee,WorkbookEditablePermission as De,WorksheetEditPermission as Oe,WorksheetSetCellStylePermission as ke,checkRangesEditablePermission as Ae,getSheetCommandTarget as je,rangeToDiscreteRange as Me}from"@univerjs/sheets";import{AddSheetDataValidationCommand as Ne,BASE_FORMULA_INPUT_NAME as Pe,CHECKBOX_FORMULA_1 as Fe,CHECKBOX_FORMULA_2 as Ie,CHECKBOX_FORMULA_INPUT_NAME as Le,CUSTOM_FORMULA_INPUT_NAME as Re,DATA_VALIDATION_PLUGIN_NAME as ze,DataValidationCacheService as Be,DataValidationFormulaController as Ve,DataValidationFormulaService as He,LIST_FORMULA_INPUT_NAME as Ue,RemoveSheetAllDataValidationCommand as We,RemoveSheetDataValidationCommand as Ge,SheetDataValidationModel as V,SheetsDataValidationValidatorService as Ke,UniverSheetsDataValidationPlugin as qe,UpdateSheetDataValidationOptionsCommand as Je,UpdateSheetDataValidationRangeCommand as Ye,UpdateSheetDataValidationSettingCommand as Xe,createDefaultNewRule as Ze,deserializeListOptions as Qe,getCellValueOrigin as H,getDataValidationCellValue as $e,getDataValidationDiffMutations as et,getFormulaResult as tt,isLegalFormulaResult as nt,serializeListOptions as rt,transformCheckboxValue as it}from"@univerjs/sheets-data-validation";import{DataValidationModel as at,DataValidatorDropdownType as U,DataValidatorRegistryScope as ot,DataValidatorRegistryService as st,TWO_FORMULA_OPERATOR_COUNT as ct,getRuleOptions as lt,getRuleSetting as ut}from"@univerjs/data-validation";import{ComponentManager as dt,IDialogService as ft,IMenuManagerService as pt,ISidebarService as mt,IZenZoneService as ht,KeyCode as gt,MenuItemType as _t,RibbonDataGroup as vt,getMenuHiddenObservable as yt,useDependency as W,useEvent as bt,useObservable as xt,useSidebarClick as St}from"@univerjs/ui";import{BehaviorSubject as Ct,Subject as wt,bufferTime as Tt,debounceTime as Et,distinctUntilChanged as Dt,filter as Ot,of as kt}from"rxjs";import{getPatternType as At}from"@univerjs/sheets-numfmt";import{AutoHeightController as jt,COPY_TYPE as Mt,CellAlertManagerService as Nt,CellAlertType as Pt,HoverManagerService as Ft,IEditorBridgeService as It,IMarkSelectionService as Lt,ISheetCellDropdownManagerService as Rt,ISheetClipboardService as zt,PREDEFINED_HOOK_NAME_PASTE as Bt,SetCellEditVisibleOperation as Vt,SheetSkeletonManagerService as Ht,getCurrentRangeDisable$ as Ut,getRepeatRange as Wt,virtualizeDiscreteRanges as Gt}from"@univerjs/sheets-ui";import{Button as Kt,Checkbox as qt,DraggableList as Jt,Dropdown as Yt,FormLayout as G,Input as Xt,Radio as Zt,RadioGroup as Qt,Select as $t,borderClassName as en,clsx as tn}from"@univerjs/design";import{createElement as nn,useEffect as rn,useMemo as an,useRef as on,useState as K}from"react";import{DataValidationIcon as sn,DeleteIcon as cn,IncreaseIcon as ln,MoreDownIcon as un,MoreUpIcon as dn,SequenceIcon as fn}from"@univerjs/icons";import{deserializeRangeWithSheet as pn,serializeRange as mn}from"@univerjs/engine-formula";import{FormulaEditor as hn,RangeSelector as gn}from"@univerjs/sheets-formula-ui";import{Fragment as _n,jsx as q,jsxs as J}from"react/jsx-runtime";var vn=`@univerjs/sheets-data-validation-ui`,yn=`0.17.0-insiders.20260318-5bef180`;function bn(e){"@babel/helpers - typeof";return bn=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},bn(e)}function xn(e,t){if(bn(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(bn(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Sn(e){var t=xn(e,`string`);return bn(t)==`symbol`?t:t+``}function Y(e,t,n){return(t=Sn(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function X(e,t){return function(n,r){t(n,r,e)}}function Z(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let Q=class extends l{get activeRule(){return this._activeRule}get isOpen(){return this._open$.getValue()}constructor(e,t){super(),this._univerInstanceService=e,this._sidebarService=t,Y(this,`_open$`,new Ct(!1)),Y(this,`open$`,this._open$.pipe(Dt())),Y(this,`_activeRule`,void 0),Y(this,`_activeRule$`,new Ct(void 0)),Y(this,`activeRule$`,this._activeRule$.asObservable()),Y(this,`_closeDisposable`,null),Y(this,`_focusFormulaEditorActiveRuleSubUnitId`,null),this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(O.UNIVER_SHEET).pipe(Ot(e=>!e)).subscribe(()=>{this.close()})),this.disposeWithMe(this._sidebarService.sidebarOptions$.subscribe(e=>{e.id===`DataValidationPanel`&&(e.visible||setTimeout(()=>{this._sidebarService.sidebarOptions$.next({visible:!1})}))}))}dispose(){var e;super.dispose(),this._open$.next(!1),this._open$.complete(),this._activeRule$.complete(),(e=this._closeDisposable)==null||e.dispose()}open(){this._open$.next(!0)}close(){var e;this._open$.next(!1),(e=this._closeDisposable)==null||e.dispose()}setCloseDisposable(e){this._closeDisposable=ae(()=>{e.dispose(),this._closeDisposable=null})}setActiveRule(e){this._activeRule=e,this._activeRule$.next(e)}setFocusFormulaEditorActiveRuleSubUnitId(e){this._focusFormulaEditorActiveRuleSubUnitId=e}getFocusFormulaEditorActiveRuleSubUnitId(){return this._focusFormulaEditorActiveRuleSubUnitId}};Q=Z([X(0,m),X(1,mt)],Q);const Cn=`sheets-data-validation-ui.config`;Symbol(Cn);const wn={};let Tn=class extends l{constructor(e,t,n,r,i,a){super(),this._sheetInterceptorService=e,this._dataValidationModel=t,this._dataValidatorRegistryService=n,this._dialogService=r,this._localeService=i,this._sheetsDataValidationValidatorService=a,this._initEditorBridgeInterceptor()}_initEditorBridgeInterceptor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(Ee,{handler:async(e,t,n)=>{let r=await e,{row:a,col:s,unitId:c,subUnitId:l}=t,u=this._dataValidationModel.getRuleIdByLocation(c,l,a,s),d=u?this._dataValidationModel.getRuleById(c,l,u):void 0;if(r===!1)return n(Promise.resolve(!1));if(!d||d.errorStyle!==i.STOP)return n(Promise.resolve(!0));let f=this._dataValidatorRegistryService.getValidatorItem(d.type);return!f||await this._sheetsDataValidationValidatorService.validatorCell(c,l,a,s)===o.VALID?n(Promise.resolve(!0)):(this._dialogService.open({width:368,title:{title:this._localeService.t(`dataValidation.alert.title`)},id:`reject-input-dialog`,children:{title:f.getRuleFinalError(d,{row:a,col:s,unitId:c,subUnitId:l})},footer:{title:nn(Kt,{variant:`primary`,onClick:()=>this._dialogService.close(`reject-input-dialog`)},this._localeService.t(`dataValidation.alert.ok`))},onClose:()=>{this._dialogService.close(`reject-input-dialog`)}}),n(Promise.resolve(!1)))}}))}showReject(e){this._dialogService.open({width:368,title:{title:this._localeService.t(`dataValidation.alert.title`)},id:`reject-input-dialog`,children:{title:e},footer:{title:nn(Kt,{variant:`primary`,onClick:()=>this._dialogService.close(`reject-input-dialog`)},this._localeService.t(`dataValidation.alert.ok`))},onClose:()=>{this._dialogService.close(`reject-input-dialog`)}})}};Tn=Z([X(0,h(Ce)),X(1,h(V)),X(2,h(st)),X(3,ft),X(4,h(v)),X(5,h(Ke))],Tn);const En=e=>{if(e==null||typeof e==`boolean`)return;if(e===``)return j();if(typeof e==`number`||!Number.isNaN(+e))return j(F.format(`yyyy-MM-dd HH:mm:ss`,Number(e)));let t=j(e);if(t.isValid())return t};function Dn(e,t){if(e===At(t))return t;switch(e){case`datetime`:return`yyyy-MM-dd hh:mm:ss`;case`date`:return`yyyy-MM-dd`;case`time`:return`HH:mm:ss`}}let On=class extends l{get activeDropdown(){return this._activeDropdown}constructor(e,t,n,r,i,a,o,s,c,l,u){super(),this._univerInstanceService=e,this._dataValidatorRegistryService=t,this._zenZoneService=n,this._dataValidationModel=r,this._sheetsSelectionsService=i,this._cellDropdownManagerService=a,this._sheetDataValidationModel=o,this._commandService=s,this._editorBridgeService=c,this._injector=l,this._configService=u,Y(this,`_activeDropdown`,void 0),Y(this,`_activeDropdown$`,new wt),Y(this,`_currentPopup`,null),Y(this,`activeDropdown$`,this._activeDropdown$.asObservable()),Y(this,`_zenVisible`,!1),this._init(),this._initSelectionChange(),this.disposeWithMe(()=>{this._activeDropdown$.complete()})}_init(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{this._zenVisible=e,e&&this.hideDropdown()}))}_getDropdownByCell(e,t,n,r){let i=e?this._univerInstanceService.getUnit(e,O.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(O.UNIVER_SHEET);if(!i)return;let a=t?i.getSheetBySheetId(t):i.getActiveSheet();if(!a)return;let o=this._dataValidationModel.getRuleByLocation(i.getUnitId(),a.getSheetId(),n,r);if(!o)return;let s=this._dataValidatorRegistryService.getValidatorItem(o.type);return s==null?void 0:s.dropdownType}_initSelectionChange(){this.disposeWithMe(this._sheetsSelectionsService.selectionMoveEnd$.subscribe(e=>{e&&e.every(e=>!(e.primary&&this._getDropdownByCell(e.primary.unitId,e.primary.sheetId,e.primary.actualRow,e.primary.actualColumn)))&&this.hideDropdown()}))}showDropdown(t){let{location:n}=t,{row:r,col:o,unitId:s,subUnitId:c,workbook:l,worksheet:d}=n;if(this._currentPopup&&this._currentPopup.dispose(),this._zenVisible)return;this._activeDropdown=t,this._activeDropdown$.next(this._activeDropdown);let f=this._sheetDataValidationModel.getRuleByLocation(s,c,r,o);if(!f)return;let p=this._dataValidatorRegistryService.getValidatorItem(f.type);if(!(p!=null&&p.dropdownType))return;let m,h=async(t,n)=>{var a,u,m;if(!t)return!0;let h=t,g=d.getCell(r,o),_=h.format(n===`date`?`YYYY-MM-DD 00:00:00`:`YYYY-MM-DD HH:mm:ss`),v=(a=F.parseDate(_))==null?void 0:a.v,y=n===`time`?v%1:v,b=l.getStyles().getStyleByCell(g),x=(u=b==null||(m=b.n)==null?void 0:m.pattern)==null?``:u;return f.errorStyle!==i.STOP||await p.validator({value:y,unitId:s,subUnitId:c,row:r,column:o,worksheet:d,workbook:l,interceptValue:_.replace(`Z`,``).replace(`T`,` `),t:e.NUMBER},f)?(await this._commandService.executeCommand(xe.id,{unitId:s,subUnitId:c,range:{startColumn:o,endColumn:o,startRow:r,endRow:r},value:{v:y,t:2,p:null,f:null,si:null,s:{n:{pattern:Dn(n,x)}}}}),await this._commandService.executeCommand(Vt.id,{visible:!1,eventType:R.Keyboard,unitId:s,keycode:gt.ESC}),!0):(this._injector.has(Tn)&&this._injector.get(Tn).showReject(p.getRuleFinalError(f,{row:r,col:o,unitId:s,subUnitId:c})),!1)},g;switch(p.dropdownType){case U.DATE:{var _;let e=En(H(d.getCellRaw(r,o))),t=!!((_=f.bizInfo)!=null&&_.showTime);g={location:n,type:`datepicker`,props:{showTime:t,onChange:e=>h(e,t?`datetime`:`date`),defaultValue:e,patternType:`date`}};break}case U.TIME:g={location:n,type:`datepicker`,props:{onChange:e=>h(e,`time`),defaultValue:En(H(d.getCellRaw(r,o))),patternType:`time`}};break;case U.DATETIME:g={location:n,type:`datepicker`,props:{onChange:e=>h(e,`datetime`),defaultValue:En(H(d.getCellRaw(r,o))),patternType:`datetime`}};break;case U.LIST:case U.MULTIPLE_LIST:{var v,y,b,x;let e=p.dropdownType===U.MULTIPLE_LIST,t=async t=>{let n=rt(t),i={unitId:s,subUnitId:c,range:{startColumn:o,endColumn:o,startRow:r,endRow:r},value:{v:n,p:null,f:null,si:null}};return this._commandService.executeCommand(xe.id,i),this._editorBridgeService.isVisible().visible&&await this._commandService.executeCommand(Vt.id,{visible:!1,eventType:R.Keyboard,unitId:s,keycode:gt.ESC}),!e},i=(f==null?void 0:f.renderMode)===a.CUSTOM||(f==null?void 0:f.renderMode)===void 0,l=p.getListWithColor(f,s,c),u=$e(d.getCellRaw(r,o));g={location:n,type:`list`,props:{onChange:e=>t(e),options:l.map(e=>({label:e.label,value:e.label,color:i||e.color?e.color||`#ECECEC`:`transparent`})),onEdit:()=>{this._commandService.executeCommand(An.id,{ruleId:f.uid}),m==null||m.dispose()},defaultValue:u,multiple:e,showEdit:(v=(y=this._configService.getConfig(`sheets-data-validation-ui.config`))==null?void 0:y.showEditOnDropdown)==null?!0:v,showSearch:(b=(x=this._configService.getConfig(`sheets-data-validation-ui.config`))==null?void 0:x.showSearchOnDropdown)==null?!0:b}};break}case U.CASCADE:var S;g={type:`cascader`,props:{onChange:e=>{let t={unitId:s,subUnitId:c,range:{startColumn:o,endColumn:o,startRow:r,endRow:r},value:{v:e.join(`/`),p:null,f:null,si:null}};return this._commandService.syncExecuteCommand(xe.id,t),this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(Vt.id,{visible:!1,eventType:R.Keyboard,unitId:s,keycode:gt.ESC}),!0},defaultValue:$e(d.getCellRaw(r,o)).split(`/`),options:JSON.parse((S=f.formula1)==null?`[]`:S)},location:n};break;case U.COLOR:g={type:`color`,props:{onChange:e=>{let t={unitId:s,subUnitId:c,range:{startColumn:o,endColumn:o,startRow:r,endRow:r},value:{v:e,p:null,f:null,si:null}};return this._commandService.syncExecuteCommand(xe.id,t),this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(Vt.id,{visible:!1,eventType:R.Keyboard,unitId:s,keycode:gt.ESC}),!0},defaultValue:$e(d.getCellRaw(r,o))},location:n};break;default:throw Error(`[DataValidationDropdownManagerService]: unknown type!`)}if(m=this._cellDropdownManagerService.showDropdown({...g,onHide:()=>{this._activeDropdown=null,this._activeDropdown$.next(null)}}),!m)throw Error(`[DataValidationDropdownManagerService]: cannot show dropdown!`);let C=new u;C.add(m),C.add({dispose:()=>{var e,t;(e=this._activeDropdown)==null||(t=e.onHide)==null||t.call(e)}}),this._currentPopup=C}hideDropdown(){this._activeDropdown&&(this._currentPopup&&this._currentPopup.dispose(),this._currentPopup=null,this._activeDropdown=null,this._activeDropdown$.next(null))}showDataValidationDropdown(e,t,n,r,i){let a=this._univerInstanceService.getUnit(e,O.UNIVER_SHEET);if(!a)return;let o=a.getSheetBySheetId(t);if(!o)return;let s=this._dataValidationModel.getRuleByLocation(a.getUnitId(),o.getSheetId(),n,r);if(!s)return;let c=this._dataValidatorRegistryService.getValidatorItem(s.type);if(!c||!c.dropdownType){this.hideDropdown();return}this.showDropdown({location:{workbook:a,worksheet:o,row:n,col:r,unitId:e,subUnitId:t},onHide:i})}};On=Z([X(0,m),X(1,h(st)),X(2,ht),X(3,h(V)),X(4,h(Te)),X(5,h(Rt)),X(6,h(V)),X(7,f),X(8,It),X(9,h(g)),X(10,p)],On);const kn=`DataValidationPanel`,An={id:`data-validation.operation.open-validation-panel`,type:n.OPERATION,handler(e,t){if(!t)return!1;let{ruleId:n,isAdd:r}=t,i=e.get(Q),a=e.get(at),o=e.get(m),s=e.get(mt),c=je(o);if(!c)return!1;let{unitId:l,subUnitId:u}=c,d=n?a.getRuleById(l,u,n):void 0;i.open(),i.setActiveRule(d&&{unitId:l,subUnitId:u,rule:d});let f=s.open({id:kn,header:{title:r?`dataValidation.panel.addTitle`:`dataValidation.panel.title`},children:{label:kn},width:312,onClose:()=>i.close()});return i.setCloseDisposable(f),!0}},jn={id:`data-validation.operation.close-validation-panel`,type:n.OPERATION,handler(e){return e.get(Q).close(),!0}},Mn={id:`data-validation.operation.toggle-validation-panel`,type:n.OPERATION,handler(e){let t=e.get(f),n=e.get(Q);return n.open(),n.isOpen?t.executeCommand(jn.id):t.executeCommand(An.id),!0}},Nn={type:n.OPERATION,id:`sheet.operation.show-data-validation-dropdown`,handler(e,t){if(!t)return!1;let n=e.get(On),{unitId:r,subUnitId:i,row:a,column:o}=t,s=n.activeDropdown,c=s==null?void 0:s.location;return c&&c.unitId===r&&c.subUnitId===i&&c.row===a&&c.col===o||n.showDataValidationDropdown(r,i,a,o),!0}},Pn={type:n.OPERATION,id:`sheet.operation.hide-data-validation-dropdown`,handler(e,t){return t?(e.get(On).hideDropdown(),!0):!1}},Fn={type:n.COMMAND,id:`data-validation.command.addRuleAndOpen`,handler(e){let t=je(e.get(m));if(!t)return!1;let{workbook:n,worksheet:r}=t,i=Ze(e),a=e.get(f),o={rule:i,unitId:n.getUnitId(),subUnitId:r.getSheetId()};return a.syncExecuteCommand(Ne.id,o)?(a.syncExecuteCommand(An.id,{ruleId:i.uid,isAdd:!0}),!0):!1}},In=`SHEET_DATA_VALIDATION_ALERT`;let Ln=class extends l{constructor(e,t,n,r,i,a){super(),this._hoverManagerService=e,this._cellAlertManagerService=t,this._univerInstanceService=n,this._localeService=r,this._zenZoneService=i,this._dataValidationModel=a,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(Et(100)).subscribe(e=>{if(e){let n=this._univerInstanceService.getUnit(e.location.unitId,O.UNIVER_SHEET),r=n.getSheetBySheetId(e.location.subUnitId);if(!r)return;let i=this._dataValidationModel.getRuleByLocation(e.location.unitId,e.location.subUnitId,e.location.row,e.location.col);if(!i){this._cellAlertManagerService.removeAlert(In);return}if(this._dataValidationModel.validator(i,{...e.location,workbook:n,worksheet:r})===o.INVALID){var t;let n=this._cellAlertManagerService.currentAlert.get(In),r=n==null||(t=n.alert)==null?void 0:t.location;if(r&&r.row===e.location.row&&r.col===e.location.col&&r.subUnitId===e.location.subUnitId&&r.unitId===e.location.unitId){this._cellAlertManagerService.removeAlert(In);return}let a=this._dataValidationModel.getValidator(i.type);if(!a){this._cellAlertManagerService.removeAlert(In);return}this._cellAlertManagerService.showAlert({type:Pt.ERROR,title:this._localeService.t(`dataValidation.error.title`),message:a==null?void 0:a.getRuleFinalError(i,e.location),location:e.location,width:200,height:74,key:In});return}}this._cellAlertManagerService.removeAlert(In)}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._cellAlertManagerService.removeAlert(In)}))}};Ln=Z([X(0,h(Ft)),X(1,h(Nt)),X(2,m),X(3,h(v)),X(4,ht),X(5,h(V))],Ln);let Rn=class extends l{constructor(e,t,n){super(),this._autoFillService=e,this._sheetDataValidationModel=t,this._injector=n,this._initAutoFill()}_initAutoFill(){let e=()=>({redos:[],undos:[]}),t=(e,t)=>{let{source:n,target:r,unitId:i,subUnitId:a}=e,o=this._sheetDataValidationModel.getRuleObjectMatrix(i,a).clone(),s=Gt([n,r]),[c,l]=s.ranges,{mapFunc:u}=s,d={row:c.startRow,col:c.startColumn},f=ge.getAutoFillRepeatRange(c,l),p=new y,m=new Set;f.forEach(e=>{let t=e.repeatStartCell,n=e.relativeRange,r={startRow:d.row,startColumn:d.col,endColumn:d.col,endRow:d.row},o={startRow:t.row,startColumn:t.col,endColumn:t.col,endRow:t.row};S.foreach(n,(e,t)=>{let n=C.getPositionRange({startRow:e,startColumn:t,endColumn:t,endRow:e},r),{row:s,col:c}=u(n.startRow,n.startColumn),l=this._sheetDataValidationModel.getRuleIdByLocation(i,a,s,c)||``,d=C.getPositionRange({startRow:e,startColumn:t,endColumn:t,endRow:e},o),{row:f,col:h}=u(d.startRow,d.startColumn);p.setValue(f,h,l),m.add(l)})});let h=Array.from(m).map(e=>({id:e,ranges:I(p,t=>t===e)}));o.addRangeRules(h);let{redoMutations:g,undoMutations:_}=et(i,a,o.diff(this._sheetDataValidationModel.getRules(i,a)),this._injector,`patched`,t===he.ONLY_FORMAT);return{undos:_,redos:g}},n={id:ze,onBeforeFillData:e=>{let{source:t,unitId:n,subUnitId:r}=e;for(let e of t.rows)for(let i of t.cols){let t=this._sheetDataValidationModel.getRuleByLocation(n,r,e,i);if(t&&t.type===s.CHECKBOX){this._autoFillService.setDisableApplyType(he.SERIES,!0);return}}},onFillData:(n,r,i)=>i===he.COPY||i===he.ONLY_FORMAT||i===he.SERIES?t(n,i):e(),onAfterFillData:()=>{}};this.disposeWithMe(this._autoFillService.addHook(n))}};Rn=Z([X(0,_e),X(1,h(V)),X(2,h(g))],Rn);let zn=class extends l{constructor(e,t,n){super(),this._sheetClipboardService=e,this._sheetDataValidationModel=t,this._injector=n,Y(this,`_copyInfo`,void 0),this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:ze,onBeforeCopy:(e,t,n)=>this._collect(e,t,n),onPasteCells:(e,t,n,r)=>{let{copyType:i=Mt.COPY,pasteType:a}=r,{range:o}=e||{},{range:s,unitId:c,subUnitId:l}=t;return this._generateMutations(s,{copyType:i,pasteType:a,copyRange:o,unitId:c,subUnitId:l})}})}_collect(e,t,n){let r=new y;this._copyInfo={unitId:e,subUnitId:t,matrix:r};let i=this._injector.invoke(r=>Me(n,r,e,t));if(!i)return;let{rows:a,cols:o}=i;a.forEach((n,i)=>{o.forEach((a,o)=>{let s=this._sheetDataValidationModel.getRuleIdByLocation(e,t,n,a);r.setValue(i,o,s==null?``:s)})})}_generateMutations(e,t){if(!this._copyInfo)return{redos:[],undos:[]};if(t.copyType===Mt.CUT)return this._copyInfo=null,{redos:[],undos:[]};if(!this._copyInfo||!this._copyInfo.matrix.getSizeOf()||!t.copyRange||[Bt.SPECIAL_PASTE_COL_WIDTH,Bt.SPECIAL_PASTE_VALUE,Bt.SPECIAL_PASTE_FORMAT,Bt.SPECIAL_PASTE_FORMULA].includes(t.pasteType))return{redos:[],undos:[]};let{unitId:n,subUnitId:r}=this._copyInfo;if(t.unitId!==n||r!==t.subUnitId){let i=this._sheetDataValidationModel.getRuleObjectMatrix(t.unitId,t.subUnitId).clone(),a=new y,o=new Set,{ranges:[s,c],mapFunc:l}=Gt([t.copyRange,e]),u=Wt(s,c,!0),d=new Map;u.forEach(({startRange:e})=>{var i;(i=this._copyInfo)==null||i.matrix.forValue((i,s,c)=>{let u=C.getPositionRange({startRow:i,endRow:i,startColumn:s,endColumn:s},e),f=`${r}-${c}`,p=this._sheetDataValidationModel.getRuleById(n,r,c);!this._sheetDataValidationModel.getRuleById(t.unitId,t.subUnitId,f)&&p&&d.set(f,{...p,uid:f});let{row:m,col:h}=l(u.startRow,u.startColumn);o.add(f),a.setValue(m,h,f)})});let f=Array.from(o).map(e=>({id:e,ranges:I(a,t=>t===e)}));i.addRangeRules(f);let{redoMutations:p,undoMutations:m}=et(t.unitId,t.subUnitId,i.diffWithAddition(this._sheetDataValidationModel.getRules(t.unitId,t.subUnitId),d.values()),this._injector,`patched`,!1);return{redos:p,undos:m}}else{let i=this._sheetDataValidationModel.getRuleObjectMatrix(n,r).clone(),a=new y,o=new Set,{ranges:[s,c],mapFunc:l}=Gt([t.copyRange,e]);Wt(s,c,!0).forEach(({startRange:e})=>{var t;(t=this._copyInfo)==null||t.matrix.forValue((t,n,r)=>{let i=C.getPositionRange({startRow:t,endRow:t,startColumn:n,endColumn:n},e),{row:s,col:c}=l(i.startRow,i.startColumn);a.setValue(s,c,r),o.add(r)})});let u=Array.from(o).map(e=>({id:e,ranges:I(a,t=>t===e)}));i.addRangeRules(u);let{redoMutations:d,undoMutations:f}=et(n,r,i.diff(this._sheetDataValidationModel.getRules(n,r)),this._injector,`patched`,!1);return{redos:d,undos:f}}}};zn=Z([X(0,zt),X(1,h(V)),X(2,h(g))],zn);let Bn=class extends l{constructor(e,t,n){super(),this._localeService=e,this._commandService=t,this._sheetPermissionCheckController=n,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===Ne.id){let{unitId:t,subUnitId:n,rule:{ranges:r}}=e.params;this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[De],rangeTypes:[be],worksheetTypes:[Oe,ke]},r,t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.setStyleErr`))}if(e.id===Ye.id){let{unitId:t,subUnitId:n,ranges:r}=e.params;this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[De],rangeTypes:[be],worksheetTypes:[Oe,ke]},r,t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.setStyleErr`))}}))}};Bn=Z([X(0,h(v)),X(1,f),X(2,h(we))],Bn);const Vn=`sheet.menu.data-validation`;function Hn(e){return{id:Vn,type:_t.SUBITEMS,icon:`DataValidationIcon`,tooltip:`dataValidation.title`,hidden$:yt(e,O.UNIVER_SHEET),disabled$:Ut(e,{workbookTypes:[De],worksheetTypes:[ke,Oe],rangeTypes:[be]})}}function Un(e){return{id:An.id,title:`dataValidation.panel.title`,type:_t.BUTTON}}function Wn(e){return{id:Fn.id,title:`dataValidation.panel.add`,type:_t.BUTTON}}const Gn={[vt.RULES]:{[Vn]:{order:0,menuItemFactory:Hn,[An.id]:{order:0,menuItemFactory:Un},[Fn.id]:{order:1,menuItemFactory:Wn}}}},Kn={tr:{size:6,color:`#fe4b4b`}};let qn=class extends T{constructor(e,t,n,r,i,a,o,s,c,l,u){super(),this._commandService=e,this._menuManagerService=t,this._renderManagerService=n,this._univerInstanceService=r,this._autoHeightController=i,this._dropdownManagerService=a,this._sheetDataValidationModel=o,this._dataValidatorRegistryService=s,this._sheetInterceptorService=c,this._dataValidationCacheService=l,this._editorBridgeService=u,this._initMenu(),this._initDropdown(),this._initViewModelIntercept(),this._initAutoHeight()}_initMenu(){this._menuManagerService.mergeMenu(Gn)}_initDropdown(){this._editorBridgeService&&this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{if(!e.visible){var t;((t=this._dropdownManagerService.activeDropdown)==null?void 0:t.trigger)===`editor-bridge`&&this._dropdownManagerService.hideDropdown();return}let n=this._editorBridgeService.getEditCellState();if(n){let{unitId:e,sheetId:t,row:r,column:i}=n,a=this._univerInstanceService.getUniverSheetInstance(e);if(!a)return;let o=this._sheetDataValidationModel.getRuleByLocation(e,t,r,i);if(!o)return;let s=this._dataValidatorRegistryService.getValidatorItem(o.type);if(!(s!=null&&s.dropdownType))return;let c=a.getActiveSheet();if(!c)return;let l=this._dropdownManagerService.activeDropdown,u=l==null?void 0:l.location;if(u&&u.unitId===e&&u.subUnitId===t&&u.row===r&&u.col===i)return;this._dropdownManagerService.showDropdown({location:{unitId:e,subUnitId:t,row:r,col:i,workbook:a,worksheet:c},trigger:`editor-bridge`,closeOnOutSide:!1})}}))}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(ve.CELL_CONTENT,{effect:_.Style,priority:ye.DATA_VALIDATION,handler:(e,t,n)=>{var r,i,a,c,l;let{row:u,col:d,unitId:f,subUnitId:p,workbook:m,worksheet:h}=t,g=this._sheetDataValidationModel.getRuleIdByLocation(f,p,u,d);if(!g)return n(e);let _=this._sheetDataValidationModel.getRuleById(f,p,g);if(!_)return n(e);let v=(r=this._dataValidationCacheService.getValue(f,p,u,d))==null?o.VALID:r,y=this._dataValidatorRegistryService.getValidatorItem(_.type),b=t.rawData,x,S={get value(){var e;return x===void 0&&(x=(e=H(b))==null?null:e),x}},C={get value(){var e;return`${(e=S.value)==null?``:e}`}};return(!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,...v===o.INVALID?Kn:null},e.customRender=[...(i=e==null?void 0:e.customRender)==null?[]:i,...y!=null&&y.canvasRender?[y.canvasRender]:[]],e.fontRenderExtension={...e==null?void 0:e.fontRenderExtension,isSkip:(e==null||(a=e.fontRenderExtension)==null?void 0:a.isSkip)||(y==null||(c=y.skipDefaultFontRender)==null?void 0:c.call(y,_,S.value,t))},e.interceptorStyle={...e==null?void 0:e.interceptorStyle,...y==null?void 0:y.getExtraStyle(_,C.value,{get style(){let t=m.getStyles();return(typeof(e==null?void 0:e.s)==`string`?t.get(e==null?void 0:e.s):e==null?void 0:e.s)||{}}},u,d)},e.interceptorAutoHeight=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(f))==null||(t=t.with(Ht).getSkeletonParam(p))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(u,d),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?u:n,(r=s==null?void 0:s.startColumn)==null?d:r),unitId:f,subUnitId:p,row:u,col:d,workbook:m,worksheet:h};return y==null||(i=y.canvasRender)==null||(a=i.calcCellAutoHeight)==null?void 0:a.call(i,c)},e.interceptorAutoWidth=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(f))==null||(t=t.with(Ht).getSkeletonParam(p))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(u,d),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?u:n,(r=s==null?void 0:s.startColumn)==null?d:r),unitId:f,subUnitId:p,row:u,col:d,workbook:m,worksheet:h};return y==null||(i=y.canvasRender)==null||(a=i.calcCellAutoWidth)==null?void 0:a.call(i,c)},e.coverable=((l=e==null?void 0:e.coverable)==null?!0:l)&&!(_.type===s.LIST||_.type===s.LIST_MULTIPLE),n(e)}}))}_initAutoHeight(){this._sheetDataValidationModel.ruleChange$.pipe(Ot(e=>e.source===`command`),Tt(100)).subscribe(e=>{if(e.length===0)return;let t=[];e.forEach(e=>{if(e.rule.type===s.LIST_MULTIPLE||e.rule.type===s.LIST){var n;(n=e.rule)!=null&&n.ranges&&t.push(...e.rule.ranges)}}),t.length&&re(this._autoHeightController.getUndoRedoParamsOfAutoHeight(t).redos,this._commandService)})}};qn=Z([X(0,f),X(1,pt),X(2,B),X(3,m),X(4,h(jt)),X(5,h(On)),X(6,h(V)),X(7,h(st)),X(8,h(Ce)),X(9,h(Be)),X(10,b(It))],qn);let Jn=class extends T{constructor(e,t,n,r,i,a,o){super(),this._commandService=e,this._renderManagerService=t,this._autoHeightController=n,this._dataValidatorRegistryService=r,this._sheetInterceptorService=i,this._sheetDataValidationModel=a,this._dataValidationCacheService=o,this._initViewModelIntercept(),this._initAutoHeight()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(ve.CELL_CONTENT,{effect:_.Style,priority:ye.DATA_VALIDATION,handler:(e,t,n)=>{var r,i,a,c,l;let{row:u,col:d,unitId:f,subUnitId:p,workbook:m,worksheet:h}=t,g=this._sheetDataValidationModel.getRuleIdByLocation(f,p,u,d);if(!g)return n(e);let _=this._sheetDataValidationModel.getRuleById(f,p,g);if(!_)return n(e);let v=(r=this._dataValidationCacheService.getValue(f,p,u,d))==null?o.VALID:r,y=this._dataValidatorRegistryService.getValidatorItem(_.type),b=H(h.getCellRaw(u,d)),x=`${b==null?``:b}`;return(!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,...v===o.INVALID?Kn:null},e.customRender=[...(i=e==null?void 0:e.customRender)==null?[]:i,...y!=null&&y.canvasRender?[y.canvasRender]:[]],e.fontRenderExtension={...e==null?void 0:e.fontRenderExtension,isSkip:(e==null||(a=e.fontRenderExtension)==null?void 0:a.isSkip)||(y==null||(c=y.skipDefaultFontRender)==null?void 0:c.call(y,_,b,t))},e.interceptorStyle={...e==null?void 0:e.interceptorStyle,...y==null?void 0:y.getExtraStyle(_,x,{get style(){let t=m.getStyles();return(typeof(e==null?void 0:e.s)==`string`?t.get(e==null?void 0:e.s):e==null?void 0:e.s)||{}}},u,d)},e.interceptorAutoHeight=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(f))==null||(t=t.with(Ht).getSkeletonParam(p))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(u,d),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?u:n,(r=s==null?void 0:s.startColumn)==null?d:r),unitId:f,subUnitId:p,row:u,col:d,workbook:m,worksheet:h};return y==null||(i=y.canvasRender)==null||(a=i.calcCellAutoHeight)==null?void 0:a.call(i,c)},e.interceptorAutoWidth=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(f))==null||(t=t.with(Ht).getSkeletonParam(p))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(u,d),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?u:n,(r=s==null?void 0:s.startColumn)==null?d:r),unitId:f,subUnitId:p,row:u,col:d,workbook:m,worksheet:h};return y==null||(i=y.canvasRender)==null||(a=i.calcCellAutoWidth)==null?void 0:a.call(i,c)},e.coverable=((l=e==null?void 0:e.coverable)==null?!0:l)&&!(_.type===s.LIST||_.type===s.LIST_MULTIPLE),n(e)}}))}_initAutoHeight(){this._sheetDataValidationModel.ruleChange$.pipe(Ot(e=>e.source===`command`),Tt(16)).subscribe(e=>{let t=[];e.forEach(e=>{if(e.rule.type===s.LIST_MULTIPLE||e.rule.type===s.LIST){var n;(n=e.rule)!=null&&n.ranges&&t.push(...e.rule.ranges)}}),t.length&&re(this._autoHeightController.getUndoRedoParamsOfAutoHeight(t).redos,this._commandService)})}};Jn=Z([X(0,f),X(1,B),X(2,h(jt)),X(3,h(st)),X(4,h(Ce)),X(5,h(V)),X(6,h(Be))],Jn);let Yn=class extends l{constructor(e,t,n){super(),this._context=e,this._sheetDataValidationModel=t,this._sheetSkeletonManagerService=n,this._initSkeletonChange()}_initSkeletonChange(){this.disposeWithMe(this._sheetDataValidationModel.validStatusChange$.pipe(ee(16)).subscribe(e=>{var t;if(!e.length)return;let n=new Set;e.forEach(e=>{n.add(e.subUnitId)}),n.forEach(e=>{var t;(t=this._sheetSkeletonManagerService.getSkeletonParam(e))==null||t.skeleton.makeDirty(!0)}),(t=this._context.mainComponent)==null||t.makeForceDirty()}))}};Yn=Z([X(1,h(V)),X(2,h(Ht))],Yn);function Xn(e){var t;let n=W(v),r=W(dt),{value:a,onChange:o,extraComponent:s}=e,[c,l]=K(!1),u=s?r.get(s):null;return J(_n,{children:[J(`div`,{className:`
|
|
1
|
+
import{CellValueType as e,ColorKit as t,CommandType as n,DEFAULT_STYLES as r,DataValidationErrorStyle as i,DataValidationRenderMode as a,DataValidationStatus as o,DataValidationType as s,DependentOn as c,Disposable as l,DisposableCollection as u,HorizontalAlign as d,ICommandService as f,IConfigService as p,IUniverInstanceService as m,Inject as h,Injector as g,InterceptorEffectEnum as _,LocaleService as v,ObjectMatrix as y,Optional as b,Plugin as x,Range as S,Rectangle as C,RedoCommand as w,RxDisposable as T,ThemeService as E,UndoCommand as D,UniverInstanceType as O,VerticalAlign as k,WrapStrategy as A,bufferDebounceTime as ee,dayjs as j,debounce as M,generateRandomId as te,isFormulaString as N,isUnitRangesEqual as ne,merge as P,numfmt as F,queryObjectMatrix as I,sequenceExecute as re,shallowEqual as ie,toDisposable as ae}from"@univerjs/core";import{CURSOR_TYPE as L,CheckboxShape as oe,DeviceInputEventType as R,DocSimpleSkeleton as z,FontCache as se,IRenderManagerService as B,Rect as ce,Shape as le,Text as ue,Transform as de,fixLineWidthByScale as fe,getCurrentTypeOfRenderer as pe,getFontStyleString as me}from"@univerjs/engine-render";import{AUTO_FILL_APPLY_TYPE as he,AutoFillTools as ge,IAutoFillService as _e,INTERCEPTOR_POINT as ve,InterceptCellContentPriority as ye,RangeProtectionPermissionEditPoint as be,SetRangeValuesCommand as xe,SetWorksheetActiveOperation as Se,SheetInterceptorService as Ce,SheetPermissionCheckController as we,SheetsSelectionsService as Te,VALIDATE_CELL as Ee,WorkbookEditablePermission as De,WorksheetEditPermission as Oe,WorksheetSetCellStylePermission as ke,checkRangesEditablePermission as Ae,getSheetCommandTarget as je,rangeToDiscreteRange as Me}from"@univerjs/sheets";import{AddSheetDataValidationCommand as Ne,BASE_FORMULA_INPUT_NAME as Pe,CHECKBOX_FORMULA_1 as Fe,CHECKBOX_FORMULA_2 as Ie,CHECKBOX_FORMULA_INPUT_NAME as Le,CUSTOM_FORMULA_INPUT_NAME as Re,DATA_VALIDATION_PLUGIN_NAME as ze,DataValidationCacheService as Be,DataValidationFormulaController as Ve,DataValidationFormulaService as He,LIST_FORMULA_INPUT_NAME as Ue,RemoveSheetAllDataValidationCommand as We,RemoveSheetDataValidationCommand as Ge,SheetDataValidationModel as V,SheetsDataValidationValidatorService as Ke,UniverSheetsDataValidationPlugin as qe,UpdateSheetDataValidationOptionsCommand as Je,UpdateSheetDataValidationRangeCommand as Ye,UpdateSheetDataValidationSettingCommand as Xe,createDefaultNewRule as Ze,deserializeListOptions as Qe,getCellValueOrigin as H,getDataValidationCellValue as $e,getDataValidationDiffMutations as et,getFormulaResult as tt,isLegalFormulaResult as nt,serializeListOptions as rt,transformCheckboxValue as it}from"@univerjs/sheets-data-validation";import{DataValidationModel as at,DataValidatorDropdownType as U,DataValidatorRegistryScope as ot,DataValidatorRegistryService as st,TWO_FORMULA_OPERATOR_COUNT as ct,getRuleOptions as lt,getRuleSetting as ut}from"@univerjs/data-validation";import{ComponentManager as dt,IDialogService as ft,IMenuManagerService as pt,ISidebarService as mt,IZenZoneService as ht,KeyCode as gt,MenuItemType as _t,RibbonDataGroup as vt,getMenuHiddenObservable as yt,useDependency as W,useEvent as bt,useObservable as xt,useSidebarClick as St}from"@univerjs/ui";import{BehaviorSubject as Ct,Subject as wt,bufferTime as Tt,debounceTime as Et,distinctUntilChanged as Dt,filter as Ot,of as kt}from"rxjs";import{getPatternType as At}from"@univerjs/sheets-numfmt";import{AutoHeightController as jt,COPY_TYPE as Mt,CellAlertManagerService as Nt,CellAlertType as Pt,HoverManagerService as Ft,IEditorBridgeService as It,IMarkSelectionService as Lt,ISheetCellDropdownManagerService as Rt,ISheetClipboardService as zt,PREDEFINED_HOOK_NAME_PASTE as Bt,SetCellEditVisibleOperation as Vt,SheetSkeletonManagerService as Ht,getCurrentRangeDisable$ as Ut,getRepeatRange as Wt,virtualizeDiscreteRanges as Gt}from"@univerjs/sheets-ui";import{Button as Kt,Checkbox as qt,DraggableList as Jt,Dropdown as Yt,FormLayout as G,Input as Xt,Radio as Zt,RadioGroup as Qt,Select as $t,borderClassName as en,clsx as tn}from"@univerjs/design";import{createElement as nn,useEffect as rn,useMemo as an,useRef as on,useState as K}from"react";import{DataValidationIcon as sn,DeleteIcon as cn,IncreaseIcon as ln,MoreDownIcon as un,MoreUpIcon as dn,SequenceIcon as fn}from"@univerjs/icons";import{deserializeRangeWithSheet as pn,serializeRange as mn}from"@univerjs/engine-formula";import{FormulaEditor as hn,RangeSelector as gn}from"@univerjs/sheets-formula-ui";import{Fragment as _n,jsx as q,jsxs as J}from"react/jsx-runtime";var vn=`@univerjs/sheets-data-validation-ui`,yn=`0.18.0`;function bn(e){"@babel/helpers - typeof";return bn=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},bn(e)}function xn(e,t){if(bn(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(bn(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Sn(e){var t=xn(e,`string`);return bn(t)==`symbol`?t:t+``}function Y(e,t,n){return(t=Sn(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function X(e,t){return function(n,r){t(n,r,e)}}function Z(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let Q=class extends l{get activeRule(){return this._activeRule}get isOpen(){return this._open$.getValue()}constructor(e,t){super(),this._univerInstanceService=e,this._sidebarService=t,Y(this,`_open$`,new Ct(!1)),Y(this,`open$`,this._open$.pipe(Dt())),Y(this,`_activeRule`,void 0),Y(this,`_activeRule$`,new Ct(void 0)),Y(this,`activeRule$`,this._activeRule$.asObservable()),Y(this,`_closeDisposable`,null),Y(this,`_focusFormulaEditorActiveRuleSubUnitId`,null),this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(O.UNIVER_SHEET).pipe(Ot(e=>!e)).subscribe(()=>{this.close()})),this.disposeWithMe(this._sidebarService.sidebarOptions$.subscribe(e=>{e.id===`DataValidationPanel`&&(e.visible||setTimeout(()=>{this._sidebarService.sidebarOptions$.next({visible:!1})}))}))}dispose(){var e;super.dispose(),this._open$.next(!1),this._open$.complete(),this._activeRule$.complete(),(e=this._closeDisposable)==null||e.dispose()}open(){this._open$.next(!0)}close(){var e;this._open$.next(!1),(e=this._closeDisposable)==null||e.dispose()}setCloseDisposable(e){this._closeDisposable=ae(()=>{e.dispose(),this._closeDisposable=null})}setActiveRule(e){this._activeRule=e,this._activeRule$.next(e)}setFocusFormulaEditorActiveRuleSubUnitId(e){this._focusFormulaEditorActiveRuleSubUnitId=e}getFocusFormulaEditorActiveRuleSubUnitId(){return this._focusFormulaEditorActiveRuleSubUnitId}};Q=Z([X(0,m),X(1,mt)],Q);const Cn=`sheets-data-validation-ui.config`;Symbol(Cn);const wn={};let Tn=class extends l{constructor(e,t,n,r,i,a){super(),this._sheetInterceptorService=e,this._dataValidationModel=t,this._dataValidatorRegistryService=n,this._dialogService=r,this._localeService=i,this._sheetsDataValidationValidatorService=a,this._initEditorBridgeInterceptor()}_initEditorBridgeInterceptor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(Ee,{handler:async(e,t,n)=>{let r=await e,{row:a,col:s,unitId:c,subUnitId:l}=t,u=this._dataValidationModel.getRuleIdByLocation(c,l,a,s),d=u?this._dataValidationModel.getRuleById(c,l,u):void 0;if(r===!1)return n(Promise.resolve(!1));if(!d||d.errorStyle!==i.STOP)return n(Promise.resolve(!0));let f=this._dataValidatorRegistryService.getValidatorItem(d.type);return!f||await this._sheetsDataValidationValidatorService.validatorCell(c,l,a,s)===o.VALID?n(Promise.resolve(!0)):(this._dialogService.open({width:368,title:{title:this._localeService.t(`dataValidation.alert.title`)},id:`reject-input-dialog`,children:{title:f.getRuleFinalError(d,{row:a,col:s,unitId:c,subUnitId:l})},footer:{title:nn(Kt,{variant:`primary`,onClick:()=>this._dialogService.close(`reject-input-dialog`)},this._localeService.t(`dataValidation.alert.ok`))},onClose:()=>{this._dialogService.close(`reject-input-dialog`)}}),n(Promise.resolve(!1)))}}))}showReject(e){this._dialogService.open({width:368,title:{title:this._localeService.t(`dataValidation.alert.title`)},id:`reject-input-dialog`,children:{title:e},footer:{title:nn(Kt,{variant:`primary`,onClick:()=>this._dialogService.close(`reject-input-dialog`)},this._localeService.t(`dataValidation.alert.ok`))},onClose:()=>{this._dialogService.close(`reject-input-dialog`)}})}};Tn=Z([X(0,h(Ce)),X(1,h(V)),X(2,h(st)),X(3,ft),X(4,h(v)),X(5,h(Ke))],Tn);const En=e=>{if(e==null||typeof e==`boolean`)return;if(e===``)return j();if(typeof e==`number`||!Number.isNaN(+e))return j(F.format(`yyyy-MM-dd HH:mm:ss`,Number(e)));let t=j(e);if(t.isValid())return t};function Dn(e,t){if(e===At(t))return t;switch(e){case`datetime`:return`yyyy-MM-dd hh:mm:ss`;case`date`:return`yyyy-MM-dd`;case`time`:return`HH:mm:ss`}}let On=class extends l{get activeDropdown(){return this._activeDropdown}constructor(e,t,n,r,i,a,o,s,c,l,u){super(),this._univerInstanceService=e,this._dataValidatorRegistryService=t,this._zenZoneService=n,this._dataValidationModel=r,this._sheetsSelectionsService=i,this._cellDropdownManagerService=a,this._sheetDataValidationModel=o,this._commandService=s,this._editorBridgeService=c,this._injector=l,this._configService=u,Y(this,`_activeDropdown`,void 0),Y(this,`_activeDropdown$`,new wt),Y(this,`_currentPopup`,null),Y(this,`activeDropdown$`,this._activeDropdown$.asObservable()),Y(this,`_zenVisible`,!1),this._init(),this._initSelectionChange(),this.disposeWithMe(()=>{this._activeDropdown$.complete()})}_init(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{this._zenVisible=e,e&&this.hideDropdown()}))}_getDropdownByCell(e,t,n,r){let i=e?this._univerInstanceService.getUnit(e,O.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(O.UNIVER_SHEET);if(!i)return;let a=t?i.getSheetBySheetId(t):i.getActiveSheet();if(!a)return;let o=this._dataValidationModel.getRuleByLocation(i.getUnitId(),a.getSheetId(),n,r);if(!o)return;let s=this._dataValidatorRegistryService.getValidatorItem(o.type);return s==null?void 0:s.dropdownType}_initSelectionChange(){this.disposeWithMe(this._sheetsSelectionsService.selectionMoveEnd$.subscribe(e=>{e&&e.every(e=>!(e.primary&&this._getDropdownByCell(e.primary.unitId,e.primary.sheetId,e.primary.actualRow,e.primary.actualColumn)))&&this.hideDropdown()}))}showDropdown(t){let{location:n}=t,{row:r,col:o,unitId:s,subUnitId:c,workbook:l,worksheet:d}=n;if(this._currentPopup&&this._currentPopup.dispose(),this._zenVisible)return;this._activeDropdown=t,this._activeDropdown$.next(this._activeDropdown);let f=this._sheetDataValidationModel.getRuleByLocation(s,c,r,o);if(!f)return;let p=this._dataValidatorRegistryService.getValidatorItem(f.type);if(!(p!=null&&p.dropdownType))return;let m,h=async(t,n)=>{var a,u,m;if(!t)return!0;let h=t,g=d.getCell(r,o),_=h.format(n===`date`?`YYYY-MM-DD 00:00:00`:`YYYY-MM-DD HH:mm:ss`),v=(a=F.parseDate(_))==null?void 0:a.v,y=n===`time`?v%1:v,b=l.getStyles().getStyleByCell(g),x=(u=b==null||(m=b.n)==null?void 0:m.pattern)==null?``:u;return f.errorStyle!==i.STOP||await p.validator({value:y,unitId:s,subUnitId:c,row:r,column:o,worksheet:d,workbook:l,interceptValue:_.replace(`Z`,``).replace(`T`,` `),t:e.NUMBER},f)?(await this._commandService.executeCommand(xe.id,{unitId:s,subUnitId:c,range:{startColumn:o,endColumn:o,startRow:r,endRow:r},value:{v:y,t:2,p:null,f:null,si:null,s:{n:{pattern:Dn(n,x)}}}}),await this._commandService.executeCommand(Vt.id,{visible:!1,eventType:R.Keyboard,unitId:s,keycode:gt.ESC}),!0):(this._injector.has(Tn)&&this._injector.get(Tn).showReject(p.getRuleFinalError(f,{row:r,col:o,unitId:s,subUnitId:c})),!1)},g;switch(p.dropdownType){case U.DATE:{var _;let e=En(H(d.getCellRaw(r,o))),t=!!((_=f.bizInfo)!=null&&_.showTime);g={location:n,type:`datepicker`,props:{showTime:t,onChange:e=>h(e,t?`datetime`:`date`),defaultValue:e,patternType:`date`}};break}case U.TIME:g={location:n,type:`datepicker`,props:{onChange:e=>h(e,`time`),defaultValue:En(H(d.getCellRaw(r,o))),patternType:`time`}};break;case U.DATETIME:g={location:n,type:`datepicker`,props:{onChange:e=>h(e,`datetime`),defaultValue:En(H(d.getCellRaw(r,o))),patternType:`datetime`}};break;case U.LIST:case U.MULTIPLE_LIST:{var v,y,b,x;let e=p.dropdownType===U.MULTIPLE_LIST,t=async t=>{let n=rt(t),i={unitId:s,subUnitId:c,range:{startColumn:o,endColumn:o,startRow:r,endRow:r},value:{v:n,p:null,f:null,si:null}};return this._commandService.executeCommand(xe.id,i),this._editorBridgeService.isVisible().visible&&await this._commandService.executeCommand(Vt.id,{visible:!1,eventType:R.Keyboard,unitId:s,keycode:gt.ESC}),!e},i=(f==null?void 0:f.renderMode)===a.CUSTOM||(f==null?void 0:f.renderMode)===void 0,l=p.getListWithColor(f,s,c),u=$e(d.getCellRaw(r,o));g={location:n,type:`list`,props:{onChange:e=>t(e),options:l.map(e=>({label:e.label,value:e.label,color:i||e.color?e.color||`#ECECEC`:`transparent`})),onEdit:()=>{this._commandService.executeCommand(An.id,{ruleId:f.uid}),m==null||m.dispose()},defaultValue:u,multiple:e,showEdit:(v=(y=this._configService.getConfig(`sheets-data-validation-ui.config`))==null?void 0:y.showEditOnDropdown)==null?!0:v,showSearch:(b=(x=this._configService.getConfig(`sheets-data-validation-ui.config`))==null?void 0:x.showSearchOnDropdown)==null?!0:b}};break}case U.CASCADE:var S;g={type:`cascader`,props:{onChange:e=>{let t={unitId:s,subUnitId:c,range:{startColumn:o,endColumn:o,startRow:r,endRow:r},value:{v:e.join(`/`),p:null,f:null,si:null}};return this._commandService.syncExecuteCommand(xe.id,t),this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(Vt.id,{visible:!1,eventType:R.Keyboard,unitId:s,keycode:gt.ESC}),!0},defaultValue:$e(d.getCellRaw(r,o)).split(`/`),options:JSON.parse((S=f.formula1)==null?`[]`:S)},location:n};break;case U.COLOR:g={type:`color`,props:{onChange:e=>{let t={unitId:s,subUnitId:c,range:{startColumn:o,endColumn:o,startRow:r,endRow:r},value:{v:e,p:null,f:null,si:null}};return this._commandService.syncExecuteCommand(xe.id,t),this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(Vt.id,{visible:!1,eventType:R.Keyboard,unitId:s,keycode:gt.ESC}),!0},defaultValue:$e(d.getCellRaw(r,o))},location:n};break;default:throw Error(`[DataValidationDropdownManagerService]: unknown type!`)}if(m=this._cellDropdownManagerService.showDropdown({...g,onHide:()=>{this._activeDropdown=null,this._activeDropdown$.next(null)}}),!m)throw Error(`[DataValidationDropdownManagerService]: cannot show dropdown!`);let C=new u;C.add(m),C.add({dispose:()=>{var e,t;(e=this._activeDropdown)==null||(t=e.onHide)==null||t.call(e)}}),this._currentPopup=C}hideDropdown(){this._activeDropdown&&(this._currentPopup&&this._currentPopup.dispose(),this._currentPopup=null,this._activeDropdown=null,this._activeDropdown$.next(null))}showDataValidationDropdown(e,t,n,r,i){let a=this._univerInstanceService.getUnit(e,O.UNIVER_SHEET);if(!a)return;let o=a.getSheetBySheetId(t);if(!o)return;let s=this._dataValidationModel.getRuleByLocation(a.getUnitId(),o.getSheetId(),n,r);if(!s)return;let c=this._dataValidatorRegistryService.getValidatorItem(s.type);if(!c||!c.dropdownType){this.hideDropdown();return}this.showDropdown({location:{workbook:a,worksheet:o,row:n,col:r,unitId:e,subUnitId:t},onHide:i})}};On=Z([X(0,m),X(1,h(st)),X(2,ht),X(3,h(V)),X(4,h(Te)),X(5,h(Rt)),X(6,h(V)),X(7,f),X(8,It),X(9,h(g)),X(10,p)],On);const kn=`DataValidationPanel`,An={id:`data-validation.operation.open-validation-panel`,type:n.OPERATION,handler(e,t){if(!t)return!1;let{ruleId:n,isAdd:r}=t,i=e.get(Q),a=e.get(at),o=e.get(m),s=e.get(mt),c=je(o);if(!c)return!1;let{unitId:l,subUnitId:u}=c,d=n?a.getRuleById(l,u,n):void 0;i.open(),i.setActiveRule(d&&{unitId:l,subUnitId:u,rule:d});let f=s.open({id:kn,header:{title:r?`dataValidation.panel.addTitle`:`dataValidation.panel.title`},children:{label:kn},width:312,onClose:()=>i.close()});return i.setCloseDisposable(f),!0}},jn={id:`data-validation.operation.close-validation-panel`,type:n.OPERATION,handler(e){return e.get(Q).close(),!0}},Mn={id:`data-validation.operation.toggle-validation-panel`,type:n.OPERATION,handler(e){let t=e.get(f),n=e.get(Q);return n.open(),n.isOpen?t.executeCommand(jn.id):t.executeCommand(An.id),!0}},Nn={type:n.OPERATION,id:`sheet.operation.show-data-validation-dropdown`,handler(e,t){if(!t)return!1;let n=e.get(On),{unitId:r,subUnitId:i,row:a,column:o}=t,s=n.activeDropdown,c=s==null?void 0:s.location;return c&&c.unitId===r&&c.subUnitId===i&&c.row===a&&c.col===o||n.showDataValidationDropdown(r,i,a,o),!0}},Pn={type:n.OPERATION,id:`sheet.operation.hide-data-validation-dropdown`,handler(e,t){return t?(e.get(On).hideDropdown(),!0):!1}},Fn={type:n.COMMAND,id:`data-validation.command.addRuleAndOpen`,handler(e){let t=je(e.get(m));if(!t)return!1;let{workbook:n,worksheet:r}=t,i=Ze(e),a=e.get(f),o={rule:i,unitId:n.getUnitId(),subUnitId:r.getSheetId()};return a.syncExecuteCommand(Ne.id,o)?(a.syncExecuteCommand(An.id,{ruleId:i.uid,isAdd:!0}),!0):!1}},In=`SHEET_DATA_VALIDATION_ALERT`;let Ln=class extends l{constructor(e,t,n,r,i,a){super(),this._hoverManagerService=e,this._cellAlertManagerService=t,this._univerInstanceService=n,this._localeService=r,this._zenZoneService=i,this._dataValidationModel=a,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(Et(100)).subscribe(e=>{if(e){let n=this._univerInstanceService.getUnit(e.location.unitId,O.UNIVER_SHEET),r=n.getSheetBySheetId(e.location.subUnitId);if(!r)return;let i=this._dataValidationModel.getRuleByLocation(e.location.unitId,e.location.subUnitId,e.location.row,e.location.col);if(!i){this._cellAlertManagerService.removeAlert(In);return}if(this._dataValidationModel.validator(i,{...e.location,workbook:n,worksheet:r})===o.INVALID){var t;let n=this._cellAlertManagerService.currentAlert.get(In),r=n==null||(t=n.alert)==null?void 0:t.location;if(r&&r.row===e.location.row&&r.col===e.location.col&&r.subUnitId===e.location.subUnitId&&r.unitId===e.location.unitId){this._cellAlertManagerService.removeAlert(In);return}let a=this._dataValidationModel.getValidator(i.type);if(!a){this._cellAlertManagerService.removeAlert(In);return}this._cellAlertManagerService.showAlert({type:Pt.ERROR,title:this._localeService.t(`dataValidation.error.title`),message:a==null?void 0:a.getRuleFinalError(i,e.location),location:e.location,width:200,height:74,key:In});return}}this._cellAlertManagerService.removeAlert(In)}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._cellAlertManagerService.removeAlert(In)}))}};Ln=Z([X(0,h(Ft)),X(1,h(Nt)),X(2,m),X(3,h(v)),X(4,ht),X(5,h(V))],Ln);let Rn=class extends l{constructor(e,t,n){super(),this._autoFillService=e,this._sheetDataValidationModel=t,this._injector=n,this._initAutoFill()}_initAutoFill(){let e=()=>({redos:[],undos:[]}),t=(e,t)=>{let{source:n,target:r,unitId:i,subUnitId:a}=e,o=this._sheetDataValidationModel.getRuleObjectMatrix(i,a).clone(),s=Gt([n,r]),[c,l]=s.ranges,{mapFunc:u}=s,d={row:c.startRow,col:c.startColumn},f=ge.getAutoFillRepeatRange(c,l),p=new y,m=new Set;f.forEach(e=>{let t=e.repeatStartCell,n=e.relativeRange,r={startRow:d.row,startColumn:d.col,endColumn:d.col,endRow:d.row},o={startRow:t.row,startColumn:t.col,endColumn:t.col,endRow:t.row};S.foreach(n,(e,t)=>{let n=C.getPositionRange({startRow:e,startColumn:t,endColumn:t,endRow:e},r),{row:s,col:c}=u(n.startRow,n.startColumn),l=this._sheetDataValidationModel.getRuleIdByLocation(i,a,s,c)||``,d=C.getPositionRange({startRow:e,startColumn:t,endColumn:t,endRow:e},o),{row:f,col:h}=u(d.startRow,d.startColumn);p.setValue(f,h,l),m.add(l)})});let h=Array.from(m).map(e=>({id:e,ranges:I(p,t=>t===e)}));o.addRangeRules(h);let{redoMutations:g,undoMutations:_}=et(i,a,o.diff(this._sheetDataValidationModel.getRules(i,a)),this._injector,`patched`,t===he.ONLY_FORMAT);return{undos:_,redos:g}},n={id:ze,onBeforeFillData:e=>{let{source:t,unitId:n,subUnitId:r}=e;for(let e of t.rows)for(let i of t.cols){let t=this._sheetDataValidationModel.getRuleByLocation(n,r,e,i);if(t&&t.type===s.CHECKBOX){this._autoFillService.setDisableApplyType(he.SERIES,!0);return}}},onFillData:(n,r,i)=>i===he.COPY||i===he.ONLY_FORMAT||i===he.SERIES?t(n,i):e(),onAfterFillData:()=>{}};this.disposeWithMe(this._autoFillService.addHook(n))}};Rn=Z([X(0,_e),X(1,h(V)),X(2,h(g))],Rn);let zn=class extends l{constructor(e,t,n){super(),this._sheetClipboardService=e,this._sheetDataValidationModel=t,this._injector=n,Y(this,`_copyInfo`,void 0),this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:ze,onBeforeCopy:(e,t,n)=>this._collect(e,t,n),onPasteCells:(e,t,n,r)=>{let{copyType:i=Mt.COPY,pasteType:a}=r,{range:o}=e||{},{range:s,unitId:c,subUnitId:l}=t;return this._generateMutations(s,{copyType:i,pasteType:a,copyRange:o,unitId:c,subUnitId:l})}})}_collect(e,t,n){let r=new y;this._copyInfo={unitId:e,subUnitId:t,matrix:r};let i=this._injector.invoke(r=>Me(n,r,e,t));if(!i)return;let{rows:a,cols:o}=i;a.forEach((n,i)=>{o.forEach((a,o)=>{let s=this._sheetDataValidationModel.getRuleIdByLocation(e,t,n,a);r.setValue(i,o,s==null?``:s)})})}_generateMutations(e,t){if(!this._copyInfo)return{redos:[],undos:[]};if(t.copyType===Mt.CUT)return this._copyInfo=null,{redos:[],undos:[]};if(!this._copyInfo||!this._copyInfo.matrix.getSizeOf()||!t.copyRange||[Bt.SPECIAL_PASTE_COL_WIDTH,Bt.SPECIAL_PASTE_VALUE,Bt.SPECIAL_PASTE_FORMAT,Bt.SPECIAL_PASTE_FORMULA].includes(t.pasteType))return{redos:[],undos:[]};let{unitId:n,subUnitId:r}=this._copyInfo;if(t.unitId!==n||r!==t.subUnitId){let i=this._sheetDataValidationModel.getRuleObjectMatrix(t.unitId,t.subUnitId).clone(),a=new y,o=new Set,{ranges:[s,c],mapFunc:l}=Gt([t.copyRange,e]),u=Wt(s,c,!0),d=new Map;u.forEach(({startRange:e})=>{var i;(i=this._copyInfo)==null||i.matrix.forValue((i,s,c)=>{let u=C.getPositionRange({startRow:i,endRow:i,startColumn:s,endColumn:s},e),f=`${r}-${c}`,p=this._sheetDataValidationModel.getRuleById(n,r,c);!this._sheetDataValidationModel.getRuleById(t.unitId,t.subUnitId,f)&&p&&d.set(f,{...p,uid:f});let{row:m,col:h}=l(u.startRow,u.startColumn);o.add(f),a.setValue(m,h,f)})});let f=Array.from(o).map(e=>({id:e,ranges:I(a,t=>t===e)}));i.addRangeRules(f);let{redoMutations:p,undoMutations:m}=et(t.unitId,t.subUnitId,i.diffWithAddition(this._sheetDataValidationModel.getRules(t.unitId,t.subUnitId),d.values()),this._injector,`patched`,!1);return{redos:p,undos:m}}else{let i=this._sheetDataValidationModel.getRuleObjectMatrix(n,r).clone(),a=new y,o=new Set,{ranges:[s,c],mapFunc:l}=Gt([t.copyRange,e]);Wt(s,c,!0).forEach(({startRange:e})=>{var t;(t=this._copyInfo)==null||t.matrix.forValue((t,n,r)=>{let i=C.getPositionRange({startRow:t,endRow:t,startColumn:n,endColumn:n},e),{row:s,col:c}=l(i.startRow,i.startColumn);a.setValue(s,c,r),o.add(r)})});let u=Array.from(o).map(e=>({id:e,ranges:I(a,t=>t===e)}));i.addRangeRules(u);let{redoMutations:d,undoMutations:f}=et(n,r,i.diff(this._sheetDataValidationModel.getRules(n,r)),this._injector,`patched`,!1);return{redos:d,undos:f}}}};zn=Z([X(0,zt),X(1,h(V)),X(2,h(g))],zn);let Bn=class extends l{constructor(e,t,n){super(),this._localeService=e,this._commandService=t,this._sheetPermissionCheckController=n,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===Ne.id){let{unitId:t,subUnitId:n,rule:{ranges:r}}=e.params;this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[De],rangeTypes:[be],worksheetTypes:[Oe,ke]},r,t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.setStyleErr`))}if(e.id===Ye.id){let{unitId:t,subUnitId:n,ranges:r}=e.params;this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[De],rangeTypes:[be],worksheetTypes:[Oe,ke]},r,t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.setStyleErr`))}}))}};Bn=Z([X(0,h(v)),X(1,f),X(2,h(we))],Bn);const Vn=`sheet.menu.data-validation`;function Hn(e){return{id:Vn,type:_t.SUBITEMS,icon:`DataValidationIcon`,tooltip:`dataValidation.title`,hidden$:yt(e,O.UNIVER_SHEET),disabled$:Ut(e,{workbookTypes:[De],worksheetTypes:[ke,Oe],rangeTypes:[be]})}}function Un(e){return{id:An.id,title:`dataValidation.panel.title`,type:_t.BUTTON}}function Wn(e){return{id:Fn.id,title:`dataValidation.panel.add`,type:_t.BUTTON}}const Gn={[vt.RULES]:{[Vn]:{order:0,menuItemFactory:Hn,[An.id]:{order:0,menuItemFactory:Un},[Fn.id]:{order:1,menuItemFactory:Wn}}}},Kn={tr:{size:6,color:`#fe4b4b`}};let qn=class extends T{constructor(e,t,n,r,i,a,o,s,c,l,u){super(),this._commandService=e,this._menuManagerService=t,this._renderManagerService=n,this._univerInstanceService=r,this._autoHeightController=i,this._dropdownManagerService=a,this._sheetDataValidationModel=o,this._dataValidatorRegistryService=s,this._sheetInterceptorService=c,this._dataValidationCacheService=l,this._editorBridgeService=u,this._initMenu(),this._initDropdown(),this._initViewModelIntercept(),this._initAutoHeight()}_initMenu(){this._menuManagerService.mergeMenu(Gn)}_initDropdown(){this._editorBridgeService&&this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{if(!e.visible){var t;((t=this._dropdownManagerService.activeDropdown)==null?void 0:t.trigger)===`editor-bridge`&&this._dropdownManagerService.hideDropdown();return}let n=this._editorBridgeService.getEditCellState();if(n){let{unitId:e,sheetId:t,row:r,column:i}=n,a=this._univerInstanceService.getUniverSheetInstance(e);if(!a)return;let o=this._sheetDataValidationModel.getRuleByLocation(e,t,r,i);if(!o)return;let s=this._dataValidatorRegistryService.getValidatorItem(o.type);if(!(s!=null&&s.dropdownType))return;let c=a.getActiveSheet();if(!c)return;let l=this._dropdownManagerService.activeDropdown,u=l==null?void 0:l.location;if(u&&u.unitId===e&&u.subUnitId===t&&u.row===r&&u.col===i)return;this._dropdownManagerService.showDropdown({location:{unitId:e,subUnitId:t,row:r,col:i,workbook:a,worksheet:c},trigger:`editor-bridge`,closeOnOutSide:!1})}}))}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(ve.CELL_CONTENT,{effect:_.Style,priority:ye.DATA_VALIDATION,handler:(e,t,n)=>{var r,i,a,c,l;let{row:u,col:d,unitId:f,subUnitId:p,workbook:m,worksheet:h}=t,g=this._sheetDataValidationModel.getRuleIdByLocation(f,p,u,d);if(!g)return n(e);let _=this._sheetDataValidationModel.getRuleById(f,p,g);if(!_)return n(e);let v=(r=this._dataValidationCacheService.getValue(f,p,u,d))==null?o.VALID:r,y=this._dataValidatorRegistryService.getValidatorItem(_.type),b=t.rawData,x,S={get value(){var e;return x===void 0&&(x=(e=H(b))==null?null:e),x}},C={get value(){var e;return`${(e=S.value)==null?``:e}`}};return(!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,...v===o.INVALID?Kn:null},e.customRender=[...(i=e==null?void 0:e.customRender)==null?[]:i,...y!=null&&y.canvasRender?[y.canvasRender]:[]],e.fontRenderExtension={...e==null?void 0:e.fontRenderExtension,isSkip:(e==null||(a=e.fontRenderExtension)==null?void 0:a.isSkip)||(y==null||(c=y.skipDefaultFontRender)==null?void 0:c.call(y,_,S.value,t))},e.interceptorStyle={...e==null?void 0:e.interceptorStyle,...y==null?void 0:y.getExtraStyle(_,C.value,{get style(){let t=m.getStyles();return(typeof(e==null?void 0:e.s)==`string`?t.get(e==null?void 0:e.s):e==null?void 0:e.s)||{}}},u,d)},e.interceptorAutoHeight=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(f))==null||(t=t.with(Ht).getSkeletonParam(p))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(u,d),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?u:n,(r=s==null?void 0:s.startColumn)==null?d:r),unitId:f,subUnitId:p,row:u,col:d,workbook:m,worksheet:h};return y==null||(i=y.canvasRender)==null||(a=i.calcCellAutoHeight)==null?void 0:a.call(i,c)},e.interceptorAutoWidth=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(f))==null||(t=t.with(Ht).getSkeletonParam(p))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(u,d),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?u:n,(r=s==null?void 0:s.startColumn)==null?d:r),unitId:f,subUnitId:p,row:u,col:d,workbook:m,worksheet:h};return y==null||(i=y.canvasRender)==null||(a=i.calcCellAutoWidth)==null?void 0:a.call(i,c)},e.coverable=((l=e==null?void 0:e.coverable)==null?!0:l)&&!(_.type===s.LIST||_.type===s.LIST_MULTIPLE),n(e)}}))}_initAutoHeight(){this._sheetDataValidationModel.ruleChange$.pipe(Ot(e=>e.source===`command`),Tt(100)).subscribe(e=>{if(e.length===0)return;let t=[];e.forEach(e=>{if(e.rule.type===s.LIST_MULTIPLE||e.rule.type===s.LIST){var n;(n=e.rule)!=null&&n.ranges&&t.push(...e.rule.ranges)}}),t.length&&re(this._autoHeightController.getUndoRedoParamsOfAutoHeight(t).redos,this._commandService)})}};qn=Z([X(0,f),X(1,pt),X(2,B),X(3,m),X(4,h(jt)),X(5,h(On)),X(6,h(V)),X(7,h(st)),X(8,h(Ce)),X(9,h(Be)),X(10,b(It))],qn);let Jn=class extends T{constructor(e,t,n,r,i,a,o){super(),this._commandService=e,this._renderManagerService=t,this._autoHeightController=n,this._dataValidatorRegistryService=r,this._sheetInterceptorService=i,this._sheetDataValidationModel=a,this._dataValidationCacheService=o,this._initViewModelIntercept(),this._initAutoHeight()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(ve.CELL_CONTENT,{effect:_.Style,priority:ye.DATA_VALIDATION,handler:(e,t,n)=>{var r,i,a,c,l;let{row:u,col:d,unitId:f,subUnitId:p,workbook:m,worksheet:h}=t,g=this._sheetDataValidationModel.getRuleIdByLocation(f,p,u,d);if(!g)return n(e);let _=this._sheetDataValidationModel.getRuleById(f,p,g);if(!_)return n(e);let v=(r=this._dataValidationCacheService.getValue(f,p,u,d))==null?o.VALID:r,y=this._dataValidatorRegistryService.getValidatorItem(_.type),b=H(h.getCellRaw(u,d)),x=`${b==null?``:b}`;return(!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,...v===o.INVALID?Kn:null},e.customRender=[...(i=e==null?void 0:e.customRender)==null?[]:i,...y!=null&&y.canvasRender?[y.canvasRender]:[]],e.fontRenderExtension={...e==null?void 0:e.fontRenderExtension,isSkip:(e==null||(a=e.fontRenderExtension)==null?void 0:a.isSkip)||(y==null||(c=y.skipDefaultFontRender)==null?void 0:c.call(y,_,b,t))},e.interceptorStyle={...e==null?void 0:e.interceptorStyle,...y==null?void 0:y.getExtraStyle(_,x,{get style(){let t=m.getStyles();return(typeof(e==null?void 0:e.s)==`string`?t.get(e==null?void 0:e.s):e==null?void 0:e.s)||{}}},u,d)},e.interceptorAutoHeight=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(f))==null||(t=t.with(Ht).getSkeletonParam(p))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(u,d),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?u:n,(r=s==null?void 0:s.startColumn)==null?d:r),unitId:f,subUnitId:p,row:u,col:d,workbook:m,worksheet:h};return y==null||(i=y.canvasRender)==null||(a=i.calcCellAutoHeight)==null?void 0:a.call(i,c)},e.interceptorAutoWidth=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(f))==null||(t=t.with(Ht).getSkeletonParam(p))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(u,d),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?u:n,(r=s==null?void 0:s.startColumn)==null?d:r),unitId:f,subUnitId:p,row:u,col:d,workbook:m,worksheet:h};return y==null||(i=y.canvasRender)==null||(a=i.calcCellAutoWidth)==null?void 0:a.call(i,c)},e.coverable=((l=e==null?void 0:e.coverable)==null?!0:l)&&!(_.type===s.LIST||_.type===s.LIST_MULTIPLE),n(e)}}))}_initAutoHeight(){this._sheetDataValidationModel.ruleChange$.pipe(Ot(e=>e.source===`command`),Tt(16)).subscribe(e=>{let t=[];e.forEach(e=>{if(e.rule.type===s.LIST_MULTIPLE||e.rule.type===s.LIST){var n;(n=e.rule)!=null&&n.ranges&&t.push(...e.rule.ranges)}}),t.length&&re(this._autoHeightController.getUndoRedoParamsOfAutoHeight(t).redos,this._commandService)})}};Jn=Z([X(0,f),X(1,B),X(2,h(jt)),X(3,h(st)),X(4,h(Ce)),X(5,h(V)),X(6,h(Be))],Jn);let Yn=class extends l{constructor(e,t,n){super(),this._context=e,this._sheetDataValidationModel=t,this._sheetSkeletonManagerService=n,this._initSkeletonChange()}_initSkeletonChange(){this.disposeWithMe(this._sheetDataValidationModel.validStatusChange$.pipe(ee(16)).subscribe(e=>{var t;if(!e.length)return;let n=new Set;e.forEach(e=>{n.add(e.subUnitId)}),n.forEach(e=>{var t;(t=this._sheetSkeletonManagerService.getSkeletonParam(e))==null||t.skeleton.makeDirty(!0)}),(t=this._context.mainComponent)==null||t.makeForceDirty()}))}};Yn=Z([X(1,h(V)),X(2,h(Ht))],Yn);function Xn(e){var t;let n=W(v),r=W(dt),{value:a,onChange:o,extraComponent:s}=e,[c,l]=K(!1),u=s?r.get(s):null;return J(_n,{children:[J(`div`,{className:`
|
|
2
2
|
univer-mb-3 univer-flex univer-cursor-pointer univer-items-center univer-text-sm univer-text-gray-900
|
|
3
3
|
dark:!univer-text-white
|
|
4
4
|
`,onClick:()=>l(!c),children:[n.t(`dataValidation.panel.options`),q(c?dn:un,{className:`univer-ml-1`})]}),c&&J(_n,{children:[u?q(u,{value:a,onChange:o}):null,q(G,{label:n.t(`dataValidation.panel.invalid`),children:J(Qt,{value:`${(t=a.errorStyle)==null?i.WARNING:t}`,onChange:e=>o({...a,errorStyle:+e}),children:[q(Zt,{value:`${i.WARNING}`,children:n.t(`dataValidation.panel.showWarning`)}),q(Zt,{value:`${i.STOP}`,children:n.t(`dataValidation.panel.rejectInput`)})]})}),q(G,{label:n.t(`dataValidation.panel.messageInfo`),children:q(qt,{checked:a.showErrorMessage,onChange:()=>o({...a,showErrorMessage:!a.showErrorMessage}),children:n.t(`dataValidation.panel.showInfo`)})}),a.showErrorMessage?q(G,{children:q(Xt,{value:a.error,onChange:e=>o({...a,error:e})})}):null]})]})}const Zn=e=>M(async(t,n,r,i)=>{let a=await e.executeCommand(t,n,r);i==null||i(a)},1e3);function Qn(e,t,n){var r;if(t){var i;return((i=e.getUnit(t))==null||(i=i.getSheetBySheetName(n))==null?void 0:i.getSheetId())||``}return((r=e.getCurrentUnitForType(O.UNIVER_SHEET))==null||(r=r.getSheetBySheetName(n))==null?void 0:r.getSheetId())||``}function $n(){var e,t;let[n,r]=K(0),i=W(Q),{unitId:a,subUnitId:o,rule:s}=xt(i.activeRule$,i.activeRule)||{},c=s.uid,l=W(st),u=W(m),d=W(dt),p=W(f),h=W(at),g=W(v),_=xt(()=>u.getCurrentTypeOfUnit$(O.UNIVER_SHEET),void 0,void 0,[]),y=xt(()=>{var e;return(e=_==null?void 0:_.activeSheet$)==null?kt(null):e},void 0,void 0,[]),[b,x]=K(s),S=l.getValidatorItem(b.type),[C,T]=K(!1),E=l.getValidatorsByScope(ot.SHEET),[k,A]=K(()=>b.ranges.map(e=>({unitId:``,sheetId:``,range:e}))),ee=an(()=>Zn(p),[p]),[j,M]=K(!1),[te,N]=K(!1),P=on(null),F=W(Te);if(rn(()=>()=>{let e=F.getCurrentLastSelection();e&&F.setSelections([e])},[F]),rn(()=>{p.onCommandExecuted(e=>{(e.id===D.id||e.id===w.id)&&setTimeout(()=>{let e=h.getRuleById(a,o,c);r(e=>e+1),e&&(x(e),A(e.ranges.map(e=>({unitId:``,sheetId:``,range:e}))))},20)})},[p,h,c,o,a]),!S)return null;let I=S.operators,re=S.operatorNames,ae=b.operator?ct.includes(b.operator):!1,L=()=>{(y==null?void 0:y.getSheetId())!==o&&p.syncExecuteCommand(Se.id,{unitId:a,subUnitId:o})},oe=()=>{var e;if(!((e=P.current)==null||(e=e.editor)==null)&&e.isFocus()){var t;R((t=P.current)==null?void 0:t.getValue())}!b.ranges.length||j||(S.validatorFormula(b,a,o).success?i.setActiveRule(null):T(!0),L())},R=bt(e=>{let t=e.split(`,`).filter(Boolean).map(pn).map(e=>{let t=e.sheetName;if(t){let n=Qn(u,e.unitId,t);return{...e,sheetId:n}}return{...e,sheetId:``}});if(ne(t,k))return;A(t);let n=t.filter(e=>(!e.unitId||e.unitId===a)&&(!e.sheetId||e.sheetId===o)).map(e=>e.range);if(x({...b,ranges:n}),n.length===0)return;let r={unitId:a,subUnitId:o,ruleId:c,ranges:n};ee(Ye.id,r)}),z=e=>{if(ie(e,ut(b)))return;x({...b,...e});let t={unitId:a,subUnitId:o,ruleId:c,setting:e};ee(Xe.id,t,void 0)},se=async()=>{await p.executeCommand(Ge.id,{ruleId:c,unitId:a,subUnitId:o}),i.setActiveRule(null),L()},B={type:b.type,operator:b.operator,formula1:b.formula1,formula2:b.formula2,allowBlank:b.allowBlank},ce=e=>{let t=l.getValidatorItem(e);if(!t)return;let n=t.operators,r=h.getRuleById(a,o,c),i=e===(r==null?void 0:r.type)||e.includes(`list`)&&r!=null&&r.type.includes(`list`)?{...r,type:e}:{...b,type:e,operator:n[0],formula1:void 0,formula2:void 0};x(i),p.executeCommand(Xe.id,{unitId:a,subUnitId:o,ruleId:b.uid,setting:ut(i)})},le=d.get(S.formulaInput),ue=an(()=>k.map(e=>mn(e.range)).join(`,`),[]),de=lt(b),fe=e=>{ie(e,lt(b))||(x({...b,...e}),ee(Je.id,{unitId:a,subUnitId:o,ruleId:c,options:e}))},pe=I.length&&!b.operator;return J(`div`,{"data-u-comp":`data-validation-detail`,className:`univer-py-2`,children:[q(G,{label:g.t(`dataValidation.panel.range`),error:!b.ranges.length||j?g.t(`dataValidation.panel.rangeError`):``,children:q(gn,{selectorRef:P,unitId:a,subUnitId:o,initialValue:ue,onChange:(e,t)=>{var n;!te&&(n=P.current)!=null&&n.verify()&&R(t)},onFocusChange:(e,t)=>{var n;N(e),!e&&t&&(n=P.current)!=null&&n.verify()&&R(t)},onVerify:e=>M(!e)})}),q(G,{label:g.t(`dataValidation.panel.type`),children:q($t,{className:`univer-w-full`,value:b.type,options:E==null||(e=E.sort((e,t)=>e.order-t.order))==null?void 0:e.map(e=>({label:g.t(e.title),value:e.id})),onChange:ce})}),I!=null&&I.length?q(G,{label:g.t(`dataValidation.panel.operator`),children:q($t,{className:`univer-w-full`,value:`${b.operator}`,options:[{value:``,label:g.t(`dataValidation.operators.legal`)},...I.map((e,t)=>({value:`${e}`,label:re[t]}))],onChange:e=>{z({...B,operator:e})}})}):null,le&&!pe?q(le,{isTwoFormula:ae,value:{formula1:b.formula1,formula2:b.formula2},onChange:e=>{z({...B,...e})},showError:C,validResult:S.validatorFormula(b,a,o),unitId:a,subUnitId:o,ruleId:c},n+b.type):null,q(G,{children:q(qt,{checked:(t=b.allowBlank)==null?!0:t,onChange:()=>{var e;return z({...B,allowBlank:!((e=b.allowBlank)==null||e)})},children:g.t(`dataValidation.panel.allowBlank`)})}),q(Xn,{value:de,onChange:fe,extraComponent:S.optionsInput}),J(`div`,{className:`univer-mt-5 univer-flex univer-flex-row univer-justify-end`,children:[q(Kt,{className:`univer-ml-3`,onClick:se,children:g.t(`dataValidation.panel.removeRule`)}),q(Kt,{className:`univer-ml-3`,variant:`primary`,onClick:oe,children:g.t(`dataValidation.panel.done`)})]})]})}const er=e=>{let{rule:n,onClick:r,unitId:i,subUnitId:a,disable:o}=e,s=W(st),c=W(f),l=W(Lt),u=s.getValidatorItem(n.type),d=on(void 0),[p,m]=K(!1),h=W(E),g=an(()=>{var e;let n=h.getColorFromTheme(`primary.600`),r=h.getColorFromTheme(`loop-color.2`),i=(e=h.getColorFromTheme(r))==null?n:e,a=new t(i).toRgb();return{fill:`rgba(${a.r}, ${a.g}, ${a.b}, 0.1)`,stroke:i}},[xt(h.currentTheme$)]),_=e=>{c.executeCommand(Ge.id,{ruleId:n.uid,unitId:i,subUnitId:a}),e.stopPropagation()};return rn(()=>()=>{if(d.current){var e;(e=d.current)==null||e.forEach(e=>{e&&l.removeShape(e)})}},[l]),J(`div`,{className:tn(`
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{CellValueType as e,ColorKit as t,CommandType as n,DEFAULT_STYLES as r,DataValidationErrorStyle as i,DataValidationRenderMode as a,DataValidationStatus as o,DataValidationType as s,DependentOn as c,Disposable as l,DisposableCollection as u,HorizontalAlign as d,ICommandService as f,IConfigService as p,IUniverInstanceService as m,Inject as h,Injector as g,InterceptorEffectEnum as _,LocaleService as v,ObjectMatrix as y,Optional as b,Plugin as x,Range as S,Rectangle as C,RedoCommand as w,RxDisposable as T,ThemeService as E,UndoCommand as D,UniverInstanceType as O,VerticalAlign as k,WrapStrategy as A,bufferDebounceTime as ee,dayjs as j,debounce as M,generateRandomId as te,isFormulaString as N,isUnitRangesEqual as ne,merge as P,numfmt as F,queryObjectMatrix as I,sequenceExecute as re,shallowEqual as ie,toDisposable as ae}from"@univerjs/core";import{CURSOR_TYPE as L,CheckboxShape as oe,DeviceInputEventType as R,DocSimpleSkeleton as z,FontCache as se,IRenderManagerService as B,Rect as ce,Shape as le,Text as ue,Transform as de,fixLineWidthByScale as fe,getCurrentTypeOfRenderer as pe,getFontStyleString as me}from"@univerjs/engine-render";import{AUTO_FILL_APPLY_TYPE as he,AutoFillTools as ge,IAutoFillService as _e,INTERCEPTOR_POINT as ve,InterceptCellContentPriority as ye,RangeProtectionPermissionEditPoint as be,SetRangeValuesCommand as xe,SetWorksheetActiveOperation as Se,SheetInterceptorService as Ce,SheetPermissionCheckController as we,SheetsSelectionsService as Te,VALIDATE_CELL as Ee,WorkbookEditablePermission as De,WorksheetEditPermission as Oe,WorksheetSetCellStylePermission as ke,checkRangesEditablePermission as Ae,getSheetCommandTarget as je,rangeToDiscreteRange as Me}from"@univerjs/sheets";import{AddSheetDataValidationCommand as Ne,BASE_FORMULA_INPUT_NAME as Pe,CHECKBOX_FORMULA_1 as Fe,CHECKBOX_FORMULA_2 as Ie,CHECKBOX_FORMULA_INPUT_NAME as Le,CUSTOM_FORMULA_INPUT_NAME as Re,DATA_VALIDATION_PLUGIN_NAME as ze,DataValidationCacheService as Be,DataValidationFormulaController as Ve,DataValidationFormulaService as He,LIST_FORMULA_INPUT_NAME as Ue,RemoveSheetAllDataValidationCommand as We,RemoveSheetDataValidationCommand as Ge,SheetDataValidationModel as V,SheetsDataValidationValidatorService as Ke,UniverSheetsDataValidationPlugin as qe,UpdateSheetDataValidationOptionsCommand as Je,UpdateSheetDataValidationRangeCommand as Ye,UpdateSheetDataValidationSettingCommand as Xe,createDefaultNewRule as Ze,deserializeListOptions as Qe,getCellValueOrigin as H,getDataValidationCellValue as $e,getDataValidationDiffMutations as et,getFormulaResult as tt,isLegalFormulaResult as nt,serializeListOptions as rt,transformCheckboxValue as it}from"@univerjs/sheets-data-validation";import{DataValidationModel as at,DataValidatorDropdownType as U,DataValidatorRegistryScope as ot,DataValidatorRegistryService as st,TWO_FORMULA_OPERATOR_COUNT as ct,getRuleOptions as lt,getRuleSetting as ut}from"@univerjs/data-validation";import{ComponentManager as dt,IDialogService as ft,IMenuManagerService as pt,ISidebarService as mt,IZenZoneService as ht,KeyCode as gt,MenuItemType as _t,RibbonDataGroup as vt,getMenuHiddenObservable as yt,useDependency as W,useEvent as bt,useObservable as xt,useSidebarClick as St}from"@univerjs/ui";import{BehaviorSubject as Ct,Subject as wt,bufferTime as Tt,debounceTime as Et,distinctUntilChanged as Dt,filter as Ot,of as kt}from"rxjs";import{getPatternType as At}from"@univerjs/sheets-numfmt";import{AutoHeightController as jt,COPY_TYPE as Mt,CellAlertManagerService as Nt,CellAlertType as Pt,HoverManagerService as Ft,IEditorBridgeService as It,IMarkSelectionService as Lt,ISheetCellDropdownManagerService as Rt,ISheetClipboardService as zt,PREDEFINED_HOOK_NAME_PASTE as Bt,SetCellEditVisibleOperation as Vt,SheetSkeletonManagerService as Ht,getCurrentRangeDisable$ as Ut,getRepeatRange as Wt,virtualizeDiscreteRanges as Gt}from"@univerjs/sheets-ui";import{Button as Kt,Checkbox as qt,DraggableList as Jt,Dropdown as Yt,FormLayout as G,Input as Xt,Radio as Zt,RadioGroup as Qt,Select as $t,borderClassName as en,clsx as tn}from"@univerjs/design";import{createElement as nn,useEffect as rn,useMemo as an,useRef as on,useState as K}from"react";import{DataValidationIcon as sn,DeleteIcon as cn,IncreaseIcon as ln,MoreDownIcon as un,MoreUpIcon as dn,SequenceIcon as fn}from"@univerjs/icons";import{deserializeRangeWithSheet as pn,serializeRange as mn}from"@univerjs/engine-formula";import{FormulaEditor as hn,RangeSelector as gn}from"@univerjs/sheets-formula-ui";import{Fragment as _n,jsx as q,jsxs as J}from"react/jsx-runtime";var vn=`@univerjs/sheets-data-validation-ui`,yn=`0.17.0-insiders.20260318-5bef180`;function bn(e){"@babel/helpers - typeof";return bn=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},bn(e)}function xn(e,t){if(bn(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(bn(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Sn(e){var t=xn(e,`string`);return bn(t)==`symbol`?t:t+``}function Y(e,t,n){return(t=Sn(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function X(e,t){return function(n,r){t(n,r,e)}}function Z(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let Q=class extends l{get activeRule(){return this._activeRule}get isOpen(){return this._open$.getValue()}constructor(e,t){super(),this._univerInstanceService=e,this._sidebarService=t,Y(this,`_open$`,new Ct(!1)),Y(this,`open$`,this._open$.pipe(Dt())),Y(this,`_activeRule`,void 0),Y(this,`_activeRule$`,new Ct(void 0)),Y(this,`activeRule$`,this._activeRule$.asObservable()),Y(this,`_closeDisposable`,null),Y(this,`_focusFormulaEditorActiveRuleSubUnitId`,null),this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(O.UNIVER_SHEET).pipe(Ot(e=>!e)).subscribe(()=>{this.close()})),this.disposeWithMe(this._sidebarService.sidebarOptions$.subscribe(e=>{e.id===`DataValidationPanel`&&(e.visible||setTimeout(()=>{this._sidebarService.sidebarOptions$.next({visible:!1})}))}))}dispose(){var e;super.dispose(),this._open$.next(!1),this._open$.complete(),this._activeRule$.complete(),(e=this._closeDisposable)==null||e.dispose()}open(){this._open$.next(!0)}close(){var e;this._open$.next(!1),(e=this._closeDisposable)==null||e.dispose()}setCloseDisposable(e){this._closeDisposable=ae(()=>{e.dispose(),this._closeDisposable=null})}setActiveRule(e){this._activeRule=e,this._activeRule$.next(e)}setFocusFormulaEditorActiveRuleSubUnitId(e){this._focusFormulaEditorActiveRuleSubUnitId=e}getFocusFormulaEditorActiveRuleSubUnitId(){return this._focusFormulaEditorActiveRuleSubUnitId}};Q=Z([X(0,m),X(1,mt)],Q);const Cn=`sheets-data-validation-ui.config`;Symbol(Cn);const wn={};let Tn=class extends l{constructor(e,t,n,r,i,a){super(),this._sheetInterceptorService=e,this._dataValidationModel=t,this._dataValidatorRegistryService=n,this._dialogService=r,this._localeService=i,this._sheetsDataValidationValidatorService=a,this._initEditorBridgeInterceptor()}_initEditorBridgeInterceptor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(Ee,{handler:async(e,t,n)=>{let r=await e,{row:a,col:s,unitId:c,subUnitId:l}=t,u=this._dataValidationModel.getRuleIdByLocation(c,l,a,s),d=u?this._dataValidationModel.getRuleById(c,l,u):void 0;if(r===!1)return n(Promise.resolve(!1));if(!d||d.errorStyle!==i.STOP)return n(Promise.resolve(!0));let f=this._dataValidatorRegistryService.getValidatorItem(d.type);return!f||await this._sheetsDataValidationValidatorService.validatorCell(c,l,a,s)===o.VALID?n(Promise.resolve(!0)):(this._dialogService.open({width:368,title:{title:this._localeService.t(`dataValidation.alert.title`)},id:`reject-input-dialog`,children:{title:f.getRuleFinalError(d,{row:a,col:s,unitId:c,subUnitId:l})},footer:{title:nn(Kt,{variant:`primary`,onClick:()=>this._dialogService.close(`reject-input-dialog`)},this._localeService.t(`dataValidation.alert.ok`))},onClose:()=>{this._dialogService.close(`reject-input-dialog`)}}),n(Promise.resolve(!1)))}}))}showReject(e){this._dialogService.open({width:368,title:{title:this._localeService.t(`dataValidation.alert.title`)},id:`reject-input-dialog`,children:{title:e},footer:{title:nn(Kt,{variant:`primary`,onClick:()=>this._dialogService.close(`reject-input-dialog`)},this._localeService.t(`dataValidation.alert.ok`))},onClose:()=>{this._dialogService.close(`reject-input-dialog`)}})}};Tn=Z([X(0,h(Ce)),X(1,h(V)),X(2,h(st)),X(3,ft),X(4,h(v)),X(5,h(Ke))],Tn);const En=e=>{if(e==null||typeof e==`boolean`)return;if(e===``)return j();if(typeof e==`number`||!Number.isNaN(+e))return j(F.format(`yyyy-MM-dd HH:mm:ss`,Number(e)));let t=j(e);if(t.isValid())return t};function Dn(e,t){if(e===At(t))return t;switch(e){case`datetime`:return`yyyy-MM-dd hh:mm:ss`;case`date`:return`yyyy-MM-dd`;case`time`:return`HH:mm:ss`}}let On=class extends l{get activeDropdown(){return this._activeDropdown}constructor(e,t,n,r,i,a,o,s,c,l,u){super(),this._univerInstanceService=e,this._dataValidatorRegistryService=t,this._zenZoneService=n,this._dataValidationModel=r,this._sheetsSelectionsService=i,this._cellDropdownManagerService=a,this._sheetDataValidationModel=o,this._commandService=s,this._editorBridgeService=c,this._injector=l,this._configService=u,Y(this,`_activeDropdown`,void 0),Y(this,`_activeDropdown$`,new wt),Y(this,`_currentPopup`,null),Y(this,`activeDropdown$`,this._activeDropdown$.asObservable()),Y(this,`_zenVisible`,!1),this._init(),this._initSelectionChange(),this.disposeWithMe(()=>{this._activeDropdown$.complete()})}_init(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{this._zenVisible=e,e&&this.hideDropdown()}))}_getDropdownByCell(e,t,n,r){let i=e?this._univerInstanceService.getUnit(e,O.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(O.UNIVER_SHEET);if(!i)return;let a=t?i.getSheetBySheetId(t):i.getActiveSheet();if(!a)return;let o=this._dataValidationModel.getRuleByLocation(i.getUnitId(),a.getSheetId(),n,r);if(!o)return;let s=this._dataValidatorRegistryService.getValidatorItem(o.type);return s==null?void 0:s.dropdownType}_initSelectionChange(){this.disposeWithMe(this._sheetsSelectionsService.selectionMoveEnd$.subscribe(e=>{e&&e.every(e=>!(e.primary&&this._getDropdownByCell(e.primary.unitId,e.primary.sheetId,e.primary.actualRow,e.primary.actualColumn)))&&this.hideDropdown()}))}showDropdown(t){let{location:n}=t,{row:r,col:o,unitId:s,subUnitId:c,workbook:l,worksheet:d}=n;if(this._currentPopup&&this._currentPopup.dispose(),this._zenVisible)return;this._activeDropdown=t,this._activeDropdown$.next(this._activeDropdown);let f=this._sheetDataValidationModel.getRuleByLocation(s,c,r,o);if(!f)return;let p=this._dataValidatorRegistryService.getValidatorItem(f.type);if(!(p!=null&&p.dropdownType))return;let m,h=async(t,n)=>{var a,u,m;if(!t)return!0;let h=t,g=d.getCell(r,o),_=h.format(n===`date`?`YYYY-MM-DD 00:00:00`:`YYYY-MM-DD HH:mm:ss`),v=(a=F.parseDate(_))==null?void 0:a.v,y=n===`time`?v%1:v,b=l.getStyles().getStyleByCell(g),x=(u=b==null||(m=b.n)==null?void 0:m.pattern)==null?``:u;return f.errorStyle!==i.STOP||await p.validator({value:y,unitId:s,subUnitId:c,row:r,column:o,worksheet:d,workbook:l,interceptValue:_.replace(`Z`,``).replace(`T`,` `),t:e.NUMBER},f)?(await this._commandService.executeCommand(xe.id,{unitId:s,subUnitId:c,range:{startColumn:o,endColumn:o,startRow:r,endRow:r},value:{v:y,t:2,p:null,f:null,si:null,s:{n:{pattern:Dn(n,x)}}}}),await this._commandService.executeCommand(Vt.id,{visible:!1,eventType:R.Keyboard,unitId:s,keycode:gt.ESC}),!0):(this._injector.has(Tn)&&this._injector.get(Tn).showReject(p.getRuleFinalError(f,{row:r,col:o,unitId:s,subUnitId:c})),!1)},g;switch(p.dropdownType){case U.DATE:{var _;let e=En(H(d.getCellRaw(r,o))),t=!!((_=f.bizInfo)!=null&&_.showTime);g={location:n,type:`datepicker`,props:{showTime:t,onChange:e=>h(e,t?`datetime`:`date`),defaultValue:e,patternType:`date`}};break}case U.TIME:g={location:n,type:`datepicker`,props:{onChange:e=>h(e,`time`),defaultValue:En(H(d.getCellRaw(r,o))),patternType:`time`}};break;case U.DATETIME:g={location:n,type:`datepicker`,props:{onChange:e=>h(e,`datetime`),defaultValue:En(H(d.getCellRaw(r,o))),patternType:`datetime`}};break;case U.LIST:case U.MULTIPLE_LIST:{var v,y,b,x;let e=p.dropdownType===U.MULTIPLE_LIST,t=async t=>{let n=rt(t),i={unitId:s,subUnitId:c,range:{startColumn:o,endColumn:o,startRow:r,endRow:r},value:{v:n,p:null,f:null,si:null}};return this._commandService.executeCommand(xe.id,i),this._editorBridgeService.isVisible().visible&&await this._commandService.executeCommand(Vt.id,{visible:!1,eventType:R.Keyboard,unitId:s,keycode:gt.ESC}),!e},i=(f==null?void 0:f.renderMode)===a.CUSTOM||(f==null?void 0:f.renderMode)===void 0,l=p.getListWithColor(f,s,c),u=$e(d.getCellRaw(r,o));g={location:n,type:`list`,props:{onChange:e=>t(e),options:l.map(e=>({label:e.label,value:e.label,color:i||e.color?e.color||`#ECECEC`:`transparent`})),onEdit:()=>{this._commandService.executeCommand(An.id,{ruleId:f.uid}),m==null||m.dispose()},defaultValue:u,multiple:e,showEdit:(v=(y=this._configService.getConfig(`sheets-data-validation-ui.config`))==null?void 0:y.showEditOnDropdown)==null?!0:v,showSearch:(b=(x=this._configService.getConfig(`sheets-data-validation-ui.config`))==null?void 0:x.showSearchOnDropdown)==null?!0:b}};break}case U.CASCADE:var S;g={type:`cascader`,props:{onChange:e=>{let t={unitId:s,subUnitId:c,range:{startColumn:o,endColumn:o,startRow:r,endRow:r},value:{v:e.join(`/`),p:null,f:null,si:null}};return this._commandService.syncExecuteCommand(xe.id,t),this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(Vt.id,{visible:!1,eventType:R.Keyboard,unitId:s,keycode:gt.ESC}),!0},defaultValue:$e(d.getCellRaw(r,o)).split(`/`),options:JSON.parse((S=f.formula1)==null?`[]`:S)},location:n};break;case U.COLOR:g={type:`color`,props:{onChange:e=>{let t={unitId:s,subUnitId:c,range:{startColumn:o,endColumn:o,startRow:r,endRow:r},value:{v:e,p:null,f:null,si:null}};return this._commandService.syncExecuteCommand(xe.id,t),this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(Vt.id,{visible:!1,eventType:R.Keyboard,unitId:s,keycode:gt.ESC}),!0},defaultValue:$e(d.getCellRaw(r,o))},location:n};break;default:throw Error(`[DataValidationDropdownManagerService]: unknown type!`)}if(m=this._cellDropdownManagerService.showDropdown({...g,onHide:()=>{this._activeDropdown=null,this._activeDropdown$.next(null)}}),!m)throw Error(`[DataValidationDropdownManagerService]: cannot show dropdown!`);let C=new u;C.add(m),C.add({dispose:()=>{var e,t;(e=this._activeDropdown)==null||(t=e.onHide)==null||t.call(e)}}),this._currentPopup=C}hideDropdown(){this._activeDropdown&&(this._currentPopup&&this._currentPopup.dispose(),this._currentPopup=null,this._activeDropdown=null,this._activeDropdown$.next(null))}showDataValidationDropdown(e,t,n,r,i){let a=this._univerInstanceService.getUnit(e,O.UNIVER_SHEET);if(!a)return;let o=a.getSheetBySheetId(t);if(!o)return;let s=this._dataValidationModel.getRuleByLocation(a.getUnitId(),o.getSheetId(),n,r);if(!s)return;let c=this._dataValidatorRegistryService.getValidatorItem(s.type);if(!c||!c.dropdownType){this.hideDropdown();return}this.showDropdown({location:{workbook:a,worksheet:o,row:n,col:r,unitId:e,subUnitId:t},onHide:i})}};On=Z([X(0,m),X(1,h(st)),X(2,ht),X(3,h(V)),X(4,h(Te)),X(5,h(Rt)),X(6,h(V)),X(7,f),X(8,It),X(9,h(g)),X(10,p)],On);const kn=`DataValidationPanel`,An={id:`data-validation.operation.open-validation-panel`,type:n.OPERATION,handler(e,t){if(!t)return!1;let{ruleId:n,isAdd:r}=t,i=e.get(Q),a=e.get(at),o=e.get(m),s=e.get(mt),c=je(o);if(!c)return!1;let{unitId:l,subUnitId:u}=c,d=n?a.getRuleById(l,u,n):void 0;i.open(),i.setActiveRule(d&&{unitId:l,subUnitId:u,rule:d});let f=s.open({id:kn,header:{title:r?`dataValidation.panel.addTitle`:`dataValidation.panel.title`},children:{label:kn},width:312,onClose:()=>i.close()});return i.setCloseDisposable(f),!0}},jn={id:`data-validation.operation.close-validation-panel`,type:n.OPERATION,handler(e){return e.get(Q).close(),!0}},Mn={id:`data-validation.operation.toggle-validation-panel`,type:n.OPERATION,handler(e){let t=e.get(f),n=e.get(Q);return n.open(),n.isOpen?t.executeCommand(jn.id):t.executeCommand(An.id),!0}},Nn={type:n.OPERATION,id:`sheet.operation.show-data-validation-dropdown`,handler(e,t){if(!t)return!1;let n=e.get(On),{unitId:r,subUnitId:i,row:a,column:o}=t,s=n.activeDropdown,c=s==null?void 0:s.location;return c&&c.unitId===r&&c.subUnitId===i&&c.row===a&&c.col===o||n.showDataValidationDropdown(r,i,a,o),!0}},Pn={type:n.OPERATION,id:`sheet.operation.hide-data-validation-dropdown`,handler(e,t){return t?(e.get(On).hideDropdown(),!0):!1}},Fn={type:n.COMMAND,id:`data-validation.command.addRuleAndOpen`,handler(e){let t=je(e.get(m));if(!t)return!1;let{workbook:n,worksheet:r}=t,i=Ze(e),a=e.get(f),o={rule:i,unitId:n.getUnitId(),subUnitId:r.getSheetId()};return a.syncExecuteCommand(Ne.id,o)?(a.syncExecuteCommand(An.id,{ruleId:i.uid,isAdd:!0}),!0):!1}},In=`SHEET_DATA_VALIDATION_ALERT`;let Ln=class extends l{constructor(e,t,n,r,i,a){super(),this._hoverManagerService=e,this._cellAlertManagerService=t,this._univerInstanceService=n,this._localeService=r,this._zenZoneService=i,this._dataValidationModel=a,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(Et(100)).subscribe(e=>{if(e){let n=this._univerInstanceService.getUnit(e.location.unitId,O.UNIVER_SHEET),r=n.getSheetBySheetId(e.location.subUnitId);if(!r)return;let i=this._dataValidationModel.getRuleByLocation(e.location.unitId,e.location.subUnitId,e.location.row,e.location.col);if(!i){this._cellAlertManagerService.removeAlert(In);return}if(this._dataValidationModel.validator(i,{...e.location,workbook:n,worksheet:r})===o.INVALID){var t;let n=this._cellAlertManagerService.currentAlert.get(In),r=n==null||(t=n.alert)==null?void 0:t.location;if(r&&r.row===e.location.row&&r.col===e.location.col&&r.subUnitId===e.location.subUnitId&&r.unitId===e.location.unitId){this._cellAlertManagerService.removeAlert(In);return}let a=this._dataValidationModel.getValidator(i.type);if(!a){this._cellAlertManagerService.removeAlert(In);return}this._cellAlertManagerService.showAlert({type:Pt.ERROR,title:this._localeService.t(`dataValidation.error.title`),message:a==null?void 0:a.getRuleFinalError(i,e.location),location:e.location,width:200,height:74,key:In});return}}this._cellAlertManagerService.removeAlert(In)}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._cellAlertManagerService.removeAlert(In)}))}};Ln=Z([X(0,h(Ft)),X(1,h(Nt)),X(2,m),X(3,h(v)),X(4,ht),X(5,h(V))],Ln);let Rn=class extends l{constructor(e,t,n){super(),this._autoFillService=e,this._sheetDataValidationModel=t,this._injector=n,this._initAutoFill()}_initAutoFill(){let e=()=>({redos:[],undos:[]}),t=(e,t)=>{let{source:n,target:r,unitId:i,subUnitId:a}=e,o=this._sheetDataValidationModel.getRuleObjectMatrix(i,a).clone(),s=Gt([n,r]),[c,l]=s.ranges,{mapFunc:u}=s,d={row:c.startRow,col:c.startColumn},f=ge.getAutoFillRepeatRange(c,l),p=new y,m=new Set;f.forEach(e=>{let t=e.repeatStartCell,n=e.relativeRange,r={startRow:d.row,startColumn:d.col,endColumn:d.col,endRow:d.row},o={startRow:t.row,startColumn:t.col,endColumn:t.col,endRow:t.row};S.foreach(n,(e,t)=>{let n=C.getPositionRange({startRow:e,startColumn:t,endColumn:t,endRow:e},r),{row:s,col:c}=u(n.startRow,n.startColumn),l=this._sheetDataValidationModel.getRuleIdByLocation(i,a,s,c)||``,d=C.getPositionRange({startRow:e,startColumn:t,endColumn:t,endRow:e},o),{row:f,col:h}=u(d.startRow,d.startColumn);p.setValue(f,h,l),m.add(l)})});let h=Array.from(m).map(e=>({id:e,ranges:I(p,t=>t===e)}));o.addRangeRules(h);let{redoMutations:g,undoMutations:_}=et(i,a,o.diff(this._sheetDataValidationModel.getRules(i,a)),this._injector,`patched`,t===he.ONLY_FORMAT);return{undos:_,redos:g}},n={id:ze,onBeforeFillData:e=>{let{source:t,unitId:n,subUnitId:r}=e;for(let e of t.rows)for(let i of t.cols){let t=this._sheetDataValidationModel.getRuleByLocation(n,r,e,i);if(t&&t.type===s.CHECKBOX){this._autoFillService.setDisableApplyType(he.SERIES,!0);return}}},onFillData:(n,r,i)=>i===he.COPY||i===he.ONLY_FORMAT||i===he.SERIES?t(n,i):e(),onAfterFillData:()=>{}};this.disposeWithMe(this._autoFillService.addHook(n))}};Rn=Z([X(0,_e),X(1,h(V)),X(2,h(g))],Rn);let zn=class extends l{constructor(e,t,n){super(),this._sheetClipboardService=e,this._sheetDataValidationModel=t,this._injector=n,Y(this,`_copyInfo`,void 0),this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:ze,onBeforeCopy:(e,t,n)=>this._collect(e,t,n),onPasteCells:(e,t,n,r)=>{let{copyType:i=Mt.COPY,pasteType:a}=r,{range:o}=e||{},{range:s,unitId:c,subUnitId:l}=t;return this._generateMutations(s,{copyType:i,pasteType:a,copyRange:o,unitId:c,subUnitId:l})}})}_collect(e,t,n){let r=new y;this._copyInfo={unitId:e,subUnitId:t,matrix:r};let i=this._injector.invoke(r=>Me(n,r,e,t));if(!i)return;let{rows:a,cols:o}=i;a.forEach((n,i)=>{o.forEach((a,o)=>{let s=this._sheetDataValidationModel.getRuleIdByLocation(e,t,n,a);r.setValue(i,o,s==null?``:s)})})}_generateMutations(e,t){if(!this._copyInfo)return{redos:[],undos:[]};if(t.copyType===Mt.CUT)return this._copyInfo=null,{redos:[],undos:[]};if(!this._copyInfo||!this._copyInfo.matrix.getSizeOf()||!t.copyRange||[Bt.SPECIAL_PASTE_COL_WIDTH,Bt.SPECIAL_PASTE_VALUE,Bt.SPECIAL_PASTE_FORMAT,Bt.SPECIAL_PASTE_FORMULA].includes(t.pasteType))return{redos:[],undos:[]};let{unitId:n,subUnitId:r}=this._copyInfo;if(t.unitId!==n||r!==t.subUnitId){let i=this._sheetDataValidationModel.getRuleObjectMatrix(t.unitId,t.subUnitId).clone(),a=new y,o=new Set,{ranges:[s,c],mapFunc:l}=Gt([t.copyRange,e]),u=Wt(s,c,!0),d=new Map;u.forEach(({startRange:e})=>{var i;(i=this._copyInfo)==null||i.matrix.forValue((i,s,c)=>{let u=C.getPositionRange({startRow:i,endRow:i,startColumn:s,endColumn:s},e),f=`${r}-${c}`,p=this._sheetDataValidationModel.getRuleById(n,r,c);!this._sheetDataValidationModel.getRuleById(t.unitId,t.subUnitId,f)&&p&&d.set(f,{...p,uid:f});let{row:m,col:h}=l(u.startRow,u.startColumn);o.add(f),a.setValue(m,h,f)})});let f=Array.from(o).map(e=>({id:e,ranges:I(a,t=>t===e)}));i.addRangeRules(f);let{redoMutations:p,undoMutations:m}=et(t.unitId,t.subUnitId,i.diffWithAddition(this._sheetDataValidationModel.getRules(t.unitId,t.subUnitId),d.values()),this._injector,`patched`,!1);return{redos:p,undos:m}}else{let i=this._sheetDataValidationModel.getRuleObjectMatrix(n,r).clone(),a=new y,o=new Set,{ranges:[s,c],mapFunc:l}=Gt([t.copyRange,e]);Wt(s,c,!0).forEach(({startRange:e})=>{var t;(t=this._copyInfo)==null||t.matrix.forValue((t,n,r)=>{let i=C.getPositionRange({startRow:t,endRow:t,startColumn:n,endColumn:n},e),{row:s,col:c}=l(i.startRow,i.startColumn);a.setValue(s,c,r),o.add(r)})});let u=Array.from(o).map(e=>({id:e,ranges:I(a,t=>t===e)}));i.addRangeRules(u);let{redoMutations:d,undoMutations:f}=et(n,r,i.diff(this._sheetDataValidationModel.getRules(n,r)),this._injector,`patched`,!1);return{redos:d,undos:f}}}};zn=Z([X(0,zt),X(1,h(V)),X(2,h(g))],zn);let Bn=class extends l{constructor(e,t,n){super(),this._localeService=e,this._commandService=t,this._sheetPermissionCheckController=n,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===Ne.id){let{unitId:t,subUnitId:n,rule:{ranges:r}}=e.params;this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[De],rangeTypes:[be],worksheetTypes:[Oe,ke]},r,t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.setStyleErr`))}if(e.id===Ye.id){let{unitId:t,subUnitId:n,ranges:r}=e.params;this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[De],rangeTypes:[be],worksheetTypes:[Oe,ke]},r,t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.setStyleErr`))}}))}};Bn=Z([X(0,h(v)),X(1,f),X(2,h(we))],Bn);const Vn=`sheet.menu.data-validation`;function Hn(e){return{id:Vn,type:_t.SUBITEMS,icon:`DataValidationIcon`,tooltip:`dataValidation.title`,hidden$:yt(e,O.UNIVER_SHEET),disabled$:Ut(e,{workbookTypes:[De],worksheetTypes:[ke,Oe],rangeTypes:[be]})}}function Un(e){return{id:An.id,title:`dataValidation.panel.title`,type:_t.BUTTON}}function Wn(e){return{id:Fn.id,title:`dataValidation.panel.add`,type:_t.BUTTON}}const Gn={[vt.RULES]:{[Vn]:{order:0,menuItemFactory:Hn,[An.id]:{order:0,menuItemFactory:Un},[Fn.id]:{order:1,menuItemFactory:Wn}}}},Kn={tr:{size:6,color:`#fe4b4b`}};let qn=class extends T{constructor(e,t,n,r,i,a,o,s,c,l,u){super(),this._commandService=e,this._menuManagerService=t,this._renderManagerService=n,this._univerInstanceService=r,this._autoHeightController=i,this._dropdownManagerService=a,this._sheetDataValidationModel=o,this._dataValidatorRegistryService=s,this._sheetInterceptorService=c,this._dataValidationCacheService=l,this._editorBridgeService=u,this._initMenu(),this._initDropdown(),this._initViewModelIntercept(),this._initAutoHeight()}_initMenu(){this._menuManagerService.mergeMenu(Gn)}_initDropdown(){this._editorBridgeService&&this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{if(!e.visible){var t;((t=this._dropdownManagerService.activeDropdown)==null?void 0:t.trigger)===`editor-bridge`&&this._dropdownManagerService.hideDropdown();return}let n=this._editorBridgeService.getEditCellState();if(n){let{unitId:e,sheetId:t,row:r,column:i}=n,a=this._univerInstanceService.getUniverSheetInstance(e);if(!a)return;let o=this._sheetDataValidationModel.getRuleByLocation(e,t,r,i);if(!o)return;let s=this._dataValidatorRegistryService.getValidatorItem(o.type);if(!(s!=null&&s.dropdownType))return;let c=a.getActiveSheet();if(!c)return;let l=this._dropdownManagerService.activeDropdown,u=l==null?void 0:l.location;if(u&&u.unitId===e&&u.subUnitId===t&&u.row===r&&u.col===i)return;this._dropdownManagerService.showDropdown({location:{unitId:e,subUnitId:t,row:r,col:i,workbook:a,worksheet:c},trigger:`editor-bridge`,closeOnOutSide:!1})}}))}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(ve.CELL_CONTENT,{effect:_.Style,priority:ye.DATA_VALIDATION,handler:(e,t,n)=>{var r,i,a,c,l;let{row:u,col:d,unitId:f,subUnitId:p,workbook:m,worksheet:h}=t,g=this._sheetDataValidationModel.getRuleIdByLocation(f,p,u,d);if(!g)return n(e);let _=this._sheetDataValidationModel.getRuleById(f,p,g);if(!_)return n(e);let v=(r=this._dataValidationCacheService.getValue(f,p,u,d))==null?o.VALID:r,y=this._dataValidatorRegistryService.getValidatorItem(_.type),b=t.rawData,x,S={get value(){var e;return x===void 0&&(x=(e=H(b))==null?null:e),x}},C={get value(){var e;return`${(e=S.value)==null?``:e}`}};return(!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,...v===o.INVALID?Kn:null},e.customRender=[...(i=e==null?void 0:e.customRender)==null?[]:i,...y!=null&&y.canvasRender?[y.canvasRender]:[]],e.fontRenderExtension={...e==null?void 0:e.fontRenderExtension,isSkip:(e==null||(a=e.fontRenderExtension)==null?void 0:a.isSkip)||(y==null||(c=y.skipDefaultFontRender)==null?void 0:c.call(y,_,S.value,t))},e.interceptorStyle={...e==null?void 0:e.interceptorStyle,...y==null?void 0:y.getExtraStyle(_,C.value,{get style(){let t=m.getStyles();return(typeof(e==null?void 0:e.s)==`string`?t.get(e==null?void 0:e.s):e==null?void 0:e.s)||{}}},u,d)},e.interceptorAutoHeight=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(f))==null||(t=t.with(Ht).getSkeletonParam(p))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(u,d),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?u:n,(r=s==null?void 0:s.startColumn)==null?d:r),unitId:f,subUnitId:p,row:u,col:d,workbook:m,worksheet:h};return y==null||(i=y.canvasRender)==null||(a=i.calcCellAutoHeight)==null?void 0:a.call(i,c)},e.interceptorAutoWidth=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(f))==null||(t=t.with(Ht).getSkeletonParam(p))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(u,d),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?u:n,(r=s==null?void 0:s.startColumn)==null?d:r),unitId:f,subUnitId:p,row:u,col:d,workbook:m,worksheet:h};return y==null||(i=y.canvasRender)==null||(a=i.calcCellAutoWidth)==null?void 0:a.call(i,c)},e.coverable=((l=e==null?void 0:e.coverable)==null?!0:l)&&!(_.type===s.LIST||_.type===s.LIST_MULTIPLE),n(e)}}))}_initAutoHeight(){this._sheetDataValidationModel.ruleChange$.pipe(Ot(e=>e.source===`command`),Tt(100)).subscribe(e=>{if(e.length===0)return;let t=[];e.forEach(e=>{if(e.rule.type===s.LIST_MULTIPLE||e.rule.type===s.LIST){var n;(n=e.rule)!=null&&n.ranges&&t.push(...e.rule.ranges)}}),t.length&&re(this._autoHeightController.getUndoRedoParamsOfAutoHeight(t).redos,this._commandService)})}};qn=Z([X(0,f),X(1,pt),X(2,B),X(3,m),X(4,h(jt)),X(5,h(On)),X(6,h(V)),X(7,h(st)),X(8,h(Ce)),X(9,h(Be)),X(10,b(It))],qn);let Jn=class extends T{constructor(e,t,n,r,i,a,o){super(),this._commandService=e,this._renderManagerService=t,this._autoHeightController=n,this._dataValidatorRegistryService=r,this._sheetInterceptorService=i,this._sheetDataValidationModel=a,this._dataValidationCacheService=o,this._initViewModelIntercept(),this._initAutoHeight()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(ve.CELL_CONTENT,{effect:_.Style,priority:ye.DATA_VALIDATION,handler:(e,t,n)=>{var r,i,a,c,l;let{row:u,col:d,unitId:f,subUnitId:p,workbook:m,worksheet:h}=t,g=this._sheetDataValidationModel.getRuleIdByLocation(f,p,u,d);if(!g)return n(e);let _=this._sheetDataValidationModel.getRuleById(f,p,g);if(!_)return n(e);let v=(r=this._dataValidationCacheService.getValue(f,p,u,d))==null?o.VALID:r,y=this._dataValidatorRegistryService.getValidatorItem(_.type),b=H(h.getCellRaw(u,d)),x=`${b==null?``:b}`;return(!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,...v===o.INVALID?Kn:null},e.customRender=[...(i=e==null?void 0:e.customRender)==null?[]:i,...y!=null&&y.canvasRender?[y.canvasRender]:[]],e.fontRenderExtension={...e==null?void 0:e.fontRenderExtension,isSkip:(e==null||(a=e.fontRenderExtension)==null?void 0:a.isSkip)||(y==null||(c=y.skipDefaultFontRender)==null?void 0:c.call(y,_,b,t))},e.interceptorStyle={...e==null?void 0:e.interceptorStyle,...y==null?void 0:y.getExtraStyle(_,x,{get style(){let t=m.getStyles();return(typeof(e==null?void 0:e.s)==`string`?t.get(e==null?void 0:e.s):e==null?void 0:e.s)||{}}},u,d)},e.interceptorAutoHeight=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(f))==null||(t=t.with(Ht).getSkeletonParam(p))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(u,d),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?u:n,(r=s==null?void 0:s.startColumn)==null?d:r),unitId:f,subUnitId:p,row:u,col:d,workbook:m,worksheet:h};return y==null||(i=y.canvasRender)==null||(a=i.calcCellAutoHeight)==null?void 0:a.call(i,c)},e.interceptorAutoWidth=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(f))==null||(t=t.with(Ht).getSkeletonParam(p))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(u,d),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?u:n,(r=s==null?void 0:s.startColumn)==null?d:r),unitId:f,subUnitId:p,row:u,col:d,workbook:m,worksheet:h};return y==null||(i=y.canvasRender)==null||(a=i.calcCellAutoWidth)==null?void 0:a.call(i,c)},e.coverable=((l=e==null?void 0:e.coverable)==null?!0:l)&&!(_.type===s.LIST||_.type===s.LIST_MULTIPLE),n(e)}}))}_initAutoHeight(){this._sheetDataValidationModel.ruleChange$.pipe(Ot(e=>e.source===`command`),Tt(16)).subscribe(e=>{let t=[];e.forEach(e=>{if(e.rule.type===s.LIST_MULTIPLE||e.rule.type===s.LIST){var n;(n=e.rule)!=null&&n.ranges&&t.push(...e.rule.ranges)}}),t.length&&re(this._autoHeightController.getUndoRedoParamsOfAutoHeight(t).redos,this._commandService)})}};Jn=Z([X(0,f),X(1,B),X(2,h(jt)),X(3,h(st)),X(4,h(Ce)),X(5,h(V)),X(6,h(Be))],Jn);let Yn=class extends l{constructor(e,t,n){super(),this._context=e,this._sheetDataValidationModel=t,this._sheetSkeletonManagerService=n,this._initSkeletonChange()}_initSkeletonChange(){this.disposeWithMe(this._sheetDataValidationModel.validStatusChange$.pipe(ee(16)).subscribe(e=>{var t;if(!e.length)return;let n=new Set;e.forEach(e=>{n.add(e.subUnitId)}),n.forEach(e=>{var t;(t=this._sheetSkeletonManagerService.getSkeletonParam(e))==null||t.skeleton.makeDirty(!0)}),(t=this._context.mainComponent)==null||t.makeForceDirty()}))}};Yn=Z([X(1,h(V)),X(2,h(Ht))],Yn);function Xn(e){var t;let n=W(v),r=W(dt),{value:a,onChange:o,extraComponent:s}=e,[c,l]=K(!1),u=s?r.get(s):null;return J(_n,{children:[J(`div`,{className:`
|
|
1
|
+
import{CellValueType as e,ColorKit as t,CommandType as n,DEFAULT_STYLES as r,DataValidationErrorStyle as i,DataValidationRenderMode as a,DataValidationStatus as o,DataValidationType as s,DependentOn as c,Disposable as l,DisposableCollection as u,HorizontalAlign as d,ICommandService as f,IConfigService as p,IUniverInstanceService as m,Inject as h,Injector as g,InterceptorEffectEnum as _,LocaleService as v,ObjectMatrix as y,Optional as b,Plugin as x,Range as S,Rectangle as C,RedoCommand as w,RxDisposable as T,ThemeService as E,UndoCommand as D,UniverInstanceType as O,VerticalAlign as k,WrapStrategy as A,bufferDebounceTime as ee,dayjs as j,debounce as M,generateRandomId as te,isFormulaString as N,isUnitRangesEqual as ne,merge as P,numfmt as F,queryObjectMatrix as I,sequenceExecute as re,shallowEqual as ie,toDisposable as ae}from"@univerjs/core";import{CURSOR_TYPE as L,CheckboxShape as oe,DeviceInputEventType as R,DocSimpleSkeleton as z,FontCache as se,IRenderManagerService as B,Rect as ce,Shape as le,Text as ue,Transform as de,fixLineWidthByScale as fe,getCurrentTypeOfRenderer as pe,getFontStyleString as me}from"@univerjs/engine-render";import{AUTO_FILL_APPLY_TYPE as he,AutoFillTools as ge,IAutoFillService as _e,INTERCEPTOR_POINT as ve,InterceptCellContentPriority as ye,RangeProtectionPermissionEditPoint as be,SetRangeValuesCommand as xe,SetWorksheetActiveOperation as Se,SheetInterceptorService as Ce,SheetPermissionCheckController as we,SheetsSelectionsService as Te,VALIDATE_CELL as Ee,WorkbookEditablePermission as De,WorksheetEditPermission as Oe,WorksheetSetCellStylePermission as ke,checkRangesEditablePermission as Ae,getSheetCommandTarget as je,rangeToDiscreteRange as Me}from"@univerjs/sheets";import{AddSheetDataValidationCommand as Ne,BASE_FORMULA_INPUT_NAME as Pe,CHECKBOX_FORMULA_1 as Fe,CHECKBOX_FORMULA_2 as Ie,CHECKBOX_FORMULA_INPUT_NAME as Le,CUSTOM_FORMULA_INPUT_NAME as Re,DATA_VALIDATION_PLUGIN_NAME as ze,DataValidationCacheService as Be,DataValidationFormulaController as Ve,DataValidationFormulaService as He,LIST_FORMULA_INPUT_NAME as Ue,RemoveSheetAllDataValidationCommand as We,RemoveSheetDataValidationCommand as Ge,SheetDataValidationModel as V,SheetsDataValidationValidatorService as Ke,UniverSheetsDataValidationPlugin as qe,UpdateSheetDataValidationOptionsCommand as Je,UpdateSheetDataValidationRangeCommand as Ye,UpdateSheetDataValidationSettingCommand as Xe,createDefaultNewRule as Ze,deserializeListOptions as Qe,getCellValueOrigin as H,getDataValidationCellValue as $e,getDataValidationDiffMutations as et,getFormulaResult as tt,isLegalFormulaResult as nt,serializeListOptions as rt,transformCheckboxValue as it}from"@univerjs/sheets-data-validation";import{DataValidationModel as at,DataValidatorDropdownType as U,DataValidatorRegistryScope as ot,DataValidatorRegistryService as st,TWO_FORMULA_OPERATOR_COUNT as ct,getRuleOptions as lt,getRuleSetting as ut}from"@univerjs/data-validation";import{ComponentManager as dt,IDialogService as ft,IMenuManagerService as pt,ISidebarService as mt,IZenZoneService as ht,KeyCode as gt,MenuItemType as _t,RibbonDataGroup as vt,getMenuHiddenObservable as yt,useDependency as W,useEvent as bt,useObservable as xt,useSidebarClick as St}from"@univerjs/ui";import{BehaviorSubject as Ct,Subject as wt,bufferTime as Tt,debounceTime as Et,distinctUntilChanged as Dt,filter as Ot,of as kt}from"rxjs";import{getPatternType as At}from"@univerjs/sheets-numfmt";import{AutoHeightController as jt,COPY_TYPE as Mt,CellAlertManagerService as Nt,CellAlertType as Pt,HoverManagerService as Ft,IEditorBridgeService as It,IMarkSelectionService as Lt,ISheetCellDropdownManagerService as Rt,ISheetClipboardService as zt,PREDEFINED_HOOK_NAME_PASTE as Bt,SetCellEditVisibleOperation as Vt,SheetSkeletonManagerService as Ht,getCurrentRangeDisable$ as Ut,getRepeatRange as Wt,virtualizeDiscreteRanges as Gt}from"@univerjs/sheets-ui";import{Button as Kt,Checkbox as qt,DraggableList as Jt,Dropdown as Yt,FormLayout as G,Input as Xt,Radio as Zt,RadioGroup as Qt,Select as $t,borderClassName as en,clsx as tn}from"@univerjs/design";import{createElement as nn,useEffect as rn,useMemo as an,useRef as on,useState as K}from"react";import{DataValidationIcon as sn,DeleteIcon as cn,IncreaseIcon as ln,MoreDownIcon as un,MoreUpIcon as dn,SequenceIcon as fn}from"@univerjs/icons";import{deserializeRangeWithSheet as pn,serializeRange as mn}from"@univerjs/engine-formula";import{FormulaEditor as hn,RangeSelector as gn}from"@univerjs/sheets-formula-ui";import{Fragment as _n,jsx as q,jsxs as J}from"react/jsx-runtime";var vn=`@univerjs/sheets-data-validation-ui`,yn=`0.18.0`;function bn(e){"@babel/helpers - typeof";return bn=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},bn(e)}function xn(e,t){if(bn(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(bn(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Sn(e){var t=xn(e,`string`);return bn(t)==`symbol`?t:t+``}function Y(e,t,n){return(t=Sn(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function X(e,t){return function(n,r){t(n,r,e)}}function Z(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let Q=class extends l{get activeRule(){return this._activeRule}get isOpen(){return this._open$.getValue()}constructor(e,t){super(),this._univerInstanceService=e,this._sidebarService=t,Y(this,`_open$`,new Ct(!1)),Y(this,`open$`,this._open$.pipe(Dt())),Y(this,`_activeRule`,void 0),Y(this,`_activeRule$`,new Ct(void 0)),Y(this,`activeRule$`,this._activeRule$.asObservable()),Y(this,`_closeDisposable`,null),Y(this,`_focusFormulaEditorActiveRuleSubUnitId`,null),this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(O.UNIVER_SHEET).pipe(Ot(e=>!e)).subscribe(()=>{this.close()})),this.disposeWithMe(this._sidebarService.sidebarOptions$.subscribe(e=>{e.id===`DataValidationPanel`&&(e.visible||setTimeout(()=>{this._sidebarService.sidebarOptions$.next({visible:!1})}))}))}dispose(){var e;super.dispose(),this._open$.next(!1),this._open$.complete(),this._activeRule$.complete(),(e=this._closeDisposable)==null||e.dispose()}open(){this._open$.next(!0)}close(){var e;this._open$.next(!1),(e=this._closeDisposable)==null||e.dispose()}setCloseDisposable(e){this._closeDisposable=ae(()=>{e.dispose(),this._closeDisposable=null})}setActiveRule(e){this._activeRule=e,this._activeRule$.next(e)}setFocusFormulaEditorActiveRuleSubUnitId(e){this._focusFormulaEditorActiveRuleSubUnitId=e}getFocusFormulaEditorActiveRuleSubUnitId(){return this._focusFormulaEditorActiveRuleSubUnitId}};Q=Z([X(0,m),X(1,mt)],Q);const Cn=`sheets-data-validation-ui.config`;Symbol(Cn);const wn={};let Tn=class extends l{constructor(e,t,n,r,i,a){super(),this._sheetInterceptorService=e,this._dataValidationModel=t,this._dataValidatorRegistryService=n,this._dialogService=r,this._localeService=i,this._sheetsDataValidationValidatorService=a,this._initEditorBridgeInterceptor()}_initEditorBridgeInterceptor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(Ee,{handler:async(e,t,n)=>{let r=await e,{row:a,col:s,unitId:c,subUnitId:l}=t,u=this._dataValidationModel.getRuleIdByLocation(c,l,a,s),d=u?this._dataValidationModel.getRuleById(c,l,u):void 0;if(r===!1)return n(Promise.resolve(!1));if(!d||d.errorStyle!==i.STOP)return n(Promise.resolve(!0));let f=this._dataValidatorRegistryService.getValidatorItem(d.type);return!f||await this._sheetsDataValidationValidatorService.validatorCell(c,l,a,s)===o.VALID?n(Promise.resolve(!0)):(this._dialogService.open({width:368,title:{title:this._localeService.t(`dataValidation.alert.title`)},id:`reject-input-dialog`,children:{title:f.getRuleFinalError(d,{row:a,col:s,unitId:c,subUnitId:l})},footer:{title:nn(Kt,{variant:`primary`,onClick:()=>this._dialogService.close(`reject-input-dialog`)},this._localeService.t(`dataValidation.alert.ok`))},onClose:()=>{this._dialogService.close(`reject-input-dialog`)}}),n(Promise.resolve(!1)))}}))}showReject(e){this._dialogService.open({width:368,title:{title:this._localeService.t(`dataValidation.alert.title`)},id:`reject-input-dialog`,children:{title:e},footer:{title:nn(Kt,{variant:`primary`,onClick:()=>this._dialogService.close(`reject-input-dialog`)},this._localeService.t(`dataValidation.alert.ok`))},onClose:()=>{this._dialogService.close(`reject-input-dialog`)}})}};Tn=Z([X(0,h(Ce)),X(1,h(V)),X(2,h(st)),X(3,ft),X(4,h(v)),X(5,h(Ke))],Tn);const En=e=>{if(e==null||typeof e==`boolean`)return;if(e===``)return j();if(typeof e==`number`||!Number.isNaN(+e))return j(F.format(`yyyy-MM-dd HH:mm:ss`,Number(e)));let t=j(e);if(t.isValid())return t};function Dn(e,t){if(e===At(t))return t;switch(e){case`datetime`:return`yyyy-MM-dd hh:mm:ss`;case`date`:return`yyyy-MM-dd`;case`time`:return`HH:mm:ss`}}let On=class extends l{get activeDropdown(){return this._activeDropdown}constructor(e,t,n,r,i,a,o,s,c,l,u){super(),this._univerInstanceService=e,this._dataValidatorRegistryService=t,this._zenZoneService=n,this._dataValidationModel=r,this._sheetsSelectionsService=i,this._cellDropdownManagerService=a,this._sheetDataValidationModel=o,this._commandService=s,this._editorBridgeService=c,this._injector=l,this._configService=u,Y(this,`_activeDropdown`,void 0),Y(this,`_activeDropdown$`,new wt),Y(this,`_currentPopup`,null),Y(this,`activeDropdown$`,this._activeDropdown$.asObservable()),Y(this,`_zenVisible`,!1),this._init(),this._initSelectionChange(),this.disposeWithMe(()=>{this._activeDropdown$.complete()})}_init(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{this._zenVisible=e,e&&this.hideDropdown()}))}_getDropdownByCell(e,t,n,r){let i=e?this._univerInstanceService.getUnit(e,O.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(O.UNIVER_SHEET);if(!i)return;let a=t?i.getSheetBySheetId(t):i.getActiveSheet();if(!a)return;let o=this._dataValidationModel.getRuleByLocation(i.getUnitId(),a.getSheetId(),n,r);if(!o)return;let s=this._dataValidatorRegistryService.getValidatorItem(o.type);return s==null?void 0:s.dropdownType}_initSelectionChange(){this.disposeWithMe(this._sheetsSelectionsService.selectionMoveEnd$.subscribe(e=>{e&&e.every(e=>!(e.primary&&this._getDropdownByCell(e.primary.unitId,e.primary.sheetId,e.primary.actualRow,e.primary.actualColumn)))&&this.hideDropdown()}))}showDropdown(t){let{location:n}=t,{row:r,col:o,unitId:s,subUnitId:c,workbook:l,worksheet:d}=n;if(this._currentPopup&&this._currentPopup.dispose(),this._zenVisible)return;this._activeDropdown=t,this._activeDropdown$.next(this._activeDropdown);let f=this._sheetDataValidationModel.getRuleByLocation(s,c,r,o);if(!f)return;let p=this._dataValidatorRegistryService.getValidatorItem(f.type);if(!(p!=null&&p.dropdownType))return;let m,h=async(t,n)=>{var a,u,m;if(!t)return!0;let h=t,g=d.getCell(r,o),_=h.format(n===`date`?`YYYY-MM-DD 00:00:00`:`YYYY-MM-DD HH:mm:ss`),v=(a=F.parseDate(_))==null?void 0:a.v,y=n===`time`?v%1:v,b=l.getStyles().getStyleByCell(g),x=(u=b==null||(m=b.n)==null?void 0:m.pattern)==null?``:u;return f.errorStyle!==i.STOP||await p.validator({value:y,unitId:s,subUnitId:c,row:r,column:o,worksheet:d,workbook:l,interceptValue:_.replace(`Z`,``).replace(`T`,` `),t:e.NUMBER},f)?(await this._commandService.executeCommand(xe.id,{unitId:s,subUnitId:c,range:{startColumn:o,endColumn:o,startRow:r,endRow:r},value:{v:y,t:2,p:null,f:null,si:null,s:{n:{pattern:Dn(n,x)}}}}),await this._commandService.executeCommand(Vt.id,{visible:!1,eventType:R.Keyboard,unitId:s,keycode:gt.ESC}),!0):(this._injector.has(Tn)&&this._injector.get(Tn).showReject(p.getRuleFinalError(f,{row:r,col:o,unitId:s,subUnitId:c})),!1)},g;switch(p.dropdownType){case U.DATE:{var _;let e=En(H(d.getCellRaw(r,o))),t=!!((_=f.bizInfo)!=null&&_.showTime);g={location:n,type:`datepicker`,props:{showTime:t,onChange:e=>h(e,t?`datetime`:`date`),defaultValue:e,patternType:`date`}};break}case U.TIME:g={location:n,type:`datepicker`,props:{onChange:e=>h(e,`time`),defaultValue:En(H(d.getCellRaw(r,o))),patternType:`time`}};break;case U.DATETIME:g={location:n,type:`datepicker`,props:{onChange:e=>h(e,`datetime`),defaultValue:En(H(d.getCellRaw(r,o))),patternType:`datetime`}};break;case U.LIST:case U.MULTIPLE_LIST:{var v,y,b,x;let e=p.dropdownType===U.MULTIPLE_LIST,t=async t=>{let n=rt(t),i={unitId:s,subUnitId:c,range:{startColumn:o,endColumn:o,startRow:r,endRow:r},value:{v:n,p:null,f:null,si:null}};return this._commandService.executeCommand(xe.id,i),this._editorBridgeService.isVisible().visible&&await this._commandService.executeCommand(Vt.id,{visible:!1,eventType:R.Keyboard,unitId:s,keycode:gt.ESC}),!e},i=(f==null?void 0:f.renderMode)===a.CUSTOM||(f==null?void 0:f.renderMode)===void 0,l=p.getListWithColor(f,s,c),u=$e(d.getCellRaw(r,o));g={location:n,type:`list`,props:{onChange:e=>t(e),options:l.map(e=>({label:e.label,value:e.label,color:i||e.color?e.color||`#ECECEC`:`transparent`})),onEdit:()=>{this._commandService.executeCommand(An.id,{ruleId:f.uid}),m==null||m.dispose()},defaultValue:u,multiple:e,showEdit:(v=(y=this._configService.getConfig(`sheets-data-validation-ui.config`))==null?void 0:y.showEditOnDropdown)==null?!0:v,showSearch:(b=(x=this._configService.getConfig(`sheets-data-validation-ui.config`))==null?void 0:x.showSearchOnDropdown)==null?!0:b}};break}case U.CASCADE:var S;g={type:`cascader`,props:{onChange:e=>{let t={unitId:s,subUnitId:c,range:{startColumn:o,endColumn:o,startRow:r,endRow:r},value:{v:e.join(`/`),p:null,f:null,si:null}};return this._commandService.syncExecuteCommand(xe.id,t),this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(Vt.id,{visible:!1,eventType:R.Keyboard,unitId:s,keycode:gt.ESC}),!0},defaultValue:$e(d.getCellRaw(r,o)).split(`/`),options:JSON.parse((S=f.formula1)==null?`[]`:S)},location:n};break;case U.COLOR:g={type:`color`,props:{onChange:e=>{let t={unitId:s,subUnitId:c,range:{startColumn:o,endColumn:o,startRow:r,endRow:r},value:{v:e,p:null,f:null,si:null}};return this._commandService.syncExecuteCommand(xe.id,t),this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(Vt.id,{visible:!1,eventType:R.Keyboard,unitId:s,keycode:gt.ESC}),!0},defaultValue:$e(d.getCellRaw(r,o))},location:n};break;default:throw Error(`[DataValidationDropdownManagerService]: unknown type!`)}if(m=this._cellDropdownManagerService.showDropdown({...g,onHide:()=>{this._activeDropdown=null,this._activeDropdown$.next(null)}}),!m)throw Error(`[DataValidationDropdownManagerService]: cannot show dropdown!`);let C=new u;C.add(m),C.add({dispose:()=>{var e,t;(e=this._activeDropdown)==null||(t=e.onHide)==null||t.call(e)}}),this._currentPopup=C}hideDropdown(){this._activeDropdown&&(this._currentPopup&&this._currentPopup.dispose(),this._currentPopup=null,this._activeDropdown=null,this._activeDropdown$.next(null))}showDataValidationDropdown(e,t,n,r,i){let a=this._univerInstanceService.getUnit(e,O.UNIVER_SHEET);if(!a)return;let o=a.getSheetBySheetId(t);if(!o)return;let s=this._dataValidationModel.getRuleByLocation(a.getUnitId(),o.getSheetId(),n,r);if(!s)return;let c=this._dataValidatorRegistryService.getValidatorItem(s.type);if(!c||!c.dropdownType){this.hideDropdown();return}this.showDropdown({location:{workbook:a,worksheet:o,row:n,col:r,unitId:e,subUnitId:t},onHide:i})}};On=Z([X(0,m),X(1,h(st)),X(2,ht),X(3,h(V)),X(4,h(Te)),X(5,h(Rt)),X(6,h(V)),X(7,f),X(8,It),X(9,h(g)),X(10,p)],On);const kn=`DataValidationPanel`,An={id:`data-validation.operation.open-validation-panel`,type:n.OPERATION,handler(e,t){if(!t)return!1;let{ruleId:n,isAdd:r}=t,i=e.get(Q),a=e.get(at),o=e.get(m),s=e.get(mt),c=je(o);if(!c)return!1;let{unitId:l,subUnitId:u}=c,d=n?a.getRuleById(l,u,n):void 0;i.open(),i.setActiveRule(d&&{unitId:l,subUnitId:u,rule:d});let f=s.open({id:kn,header:{title:r?`dataValidation.panel.addTitle`:`dataValidation.panel.title`},children:{label:kn},width:312,onClose:()=>i.close()});return i.setCloseDisposable(f),!0}},jn={id:`data-validation.operation.close-validation-panel`,type:n.OPERATION,handler(e){return e.get(Q).close(),!0}},Mn={id:`data-validation.operation.toggle-validation-panel`,type:n.OPERATION,handler(e){let t=e.get(f),n=e.get(Q);return n.open(),n.isOpen?t.executeCommand(jn.id):t.executeCommand(An.id),!0}},Nn={type:n.OPERATION,id:`sheet.operation.show-data-validation-dropdown`,handler(e,t){if(!t)return!1;let n=e.get(On),{unitId:r,subUnitId:i,row:a,column:o}=t,s=n.activeDropdown,c=s==null?void 0:s.location;return c&&c.unitId===r&&c.subUnitId===i&&c.row===a&&c.col===o||n.showDataValidationDropdown(r,i,a,o),!0}},Pn={type:n.OPERATION,id:`sheet.operation.hide-data-validation-dropdown`,handler(e,t){return t?(e.get(On).hideDropdown(),!0):!1}},Fn={type:n.COMMAND,id:`data-validation.command.addRuleAndOpen`,handler(e){let t=je(e.get(m));if(!t)return!1;let{workbook:n,worksheet:r}=t,i=Ze(e),a=e.get(f),o={rule:i,unitId:n.getUnitId(),subUnitId:r.getSheetId()};return a.syncExecuteCommand(Ne.id,o)?(a.syncExecuteCommand(An.id,{ruleId:i.uid,isAdd:!0}),!0):!1}},In=`SHEET_DATA_VALIDATION_ALERT`;let Ln=class extends l{constructor(e,t,n,r,i,a){super(),this._hoverManagerService=e,this._cellAlertManagerService=t,this._univerInstanceService=n,this._localeService=r,this._zenZoneService=i,this._dataValidationModel=a,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(Et(100)).subscribe(e=>{if(e){let n=this._univerInstanceService.getUnit(e.location.unitId,O.UNIVER_SHEET),r=n.getSheetBySheetId(e.location.subUnitId);if(!r)return;let i=this._dataValidationModel.getRuleByLocation(e.location.unitId,e.location.subUnitId,e.location.row,e.location.col);if(!i){this._cellAlertManagerService.removeAlert(In);return}if(this._dataValidationModel.validator(i,{...e.location,workbook:n,worksheet:r})===o.INVALID){var t;let n=this._cellAlertManagerService.currentAlert.get(In),r=n==null||(t=n.alert)==null?void 0:t.location;if(r&&r.row===e.location.row&&r.col===e.location.col&&r.subUnitId===e.location.subUnitId&&r.unitId===e.location.unitId){this._cellAlertManagerService.removeAlert(In);return}let a=this._dataValidationModel.getValidator(i.type);if(!a){this._cellAlertManagerService.removeAlert(In);return}this._cellAlertManagerService.showAlert({type:Pt.ERROR,title:this._localeService.t(`dataValidation.error.title`),message:a==null?void 0:a.getRuleFinalError(i,e.location),location:e.location,width:200,height:74,key:In});return}}this._cellAlertManagerService.removeAlert(In)}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._cellAlertManagerService.removeAlert(In)}))}};Ln=Z([X(0,h(Ft)),X(1,h(Nt)),X(2,m),X(3,h(v)),X(4,ht),X(5,h(V))],Ln);let Rn=class extends l{constructor(e,t,n){super(),this._autoFillService=e,this._sheetDataValidationModel=t,this._injector=n,this._initAutoFill()}_initAutoFill(){let e=()=>({redos:[],undos:[]}),t=(e,t)=>{let{source:n,target:r,unitId:i,subUnitId:a}=e,o=this._sheetDataValidationModel.getRuleObjectMatrix(i,a).clone(),s=Gt([n,r]),[c,l]=s.ranges,{mapFunc:u}=s,d={row:c.startRow,col:c.startColumn},f=ge.getAutoFillRepeatRange(c,l),p=new y,m=new Set;f.forEach(e=>{let t=e.repeatStartCell,n=e.relativeRange,r={startRow:d.row,startColumn:d.col,endColumn:d.col,endRow:d.row},o={startRow:t.row,startColumn:t.col,endColumn:t.col,endRow:t.row};S.foreach(n,(e,t)=>{let n=C.getPositionRange({startRow:e,startColumn:t,endColumn:t,endRow:e},r),{row:s,col:c}=u(n.startRow,n.startColumn),l=this._sheetDataValidationModel.getRuleIdByLocation(i,a,s,c)||``,d=C.getPositionRange({startRow:e,startColumn:t,endColumn:t,endRow:e},o),{row:f,col:h}=u(d.startRow,d.startColumn);p.setValue(f,h,l),m.add(l)})});let h=Array.from(m).map(e=>({id:e,ranges:I(p,t=>t===e)}));o.addRangeRules(h);let{redoMutations:g,undoMutations:_}=et(i,a,o.diff(this._sheetDataValidationModel.getRules(i,a)),this._injector,`patched`,t===he.ONLY_FORMAT);return{undos:_,redos:g}},n={id:ze,onBeforeFillData:e=>{let{source:t,unitId:n,subUnitId:r}=e;for(let e of t.rows)for(let i of t.cols){let t=this._sheetDataValidationModel.getRuleByLocation(n,r,e,i);if(t&&t.type===s.CHECKBOX){this._autoFillService.setDisableApplyType(he.SERIES,!0);return}}},onFillData:(n,r,i)=>i===he.COPY||i===he.ONLY_FORMAT||i===he.SERIES?t(n,i):e(),onAfterFillData:()=>{}};this.disposeWithMe(this._autoFillService.addHook(n))}};Rn=Z([X(0,_e),X(1,h(V)),X(2,h(g))],Rn);let zn=class extends l{constructor(e,t,n){super(),this._sheetClipboardService=e,this._sheetDataValidationModel=t,this._injector=n,Y(this,`_copyInfo`,void 0),this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:ze,onBeforeCopy:(e,t,n)=>this._collect(e,t,n),onPasteCells:(e,t,n,r)=>{let{copyType:i=Mt.COPY,pasteType:a}=r,{range:o}=e||{},{range:s,unitId:c,subUnitId:l}=t;return this._generateMutations(s,{copyType:i,pasteType:a,copyRange:o,unitId:c,subUnitId:l})}})}_collect(e,t,n){let r=new y;this._copyInfo={unitId:e,subUnitId:t,matrix:r};let i=this._injector.invoke(r=>Me(n,r,e,t));if(!i)return;let{rows:a,cols:o}=i;a.forEach((n,i)=>{o.forEach((a,o)=>{let s=this._sheetDataValidationModel.getRuleIdByLocation(e,t,n,a);r.setValue(i,o,s==null?``:s)})})}_generateMutations(e,t){if(!this._copyInfo)return{redos:[],undos:[]};if(t.copyType===Mt.CUT)return this._copyInfo=null,{redos:[],undos:[]};if(!this._copyInfo||!this._copyInfo.matrix.getSizeOf()||!t.copyRange||[Bt.SPECIAL_PASTE_COL_WIDTH,Bt.SPECIAL_PASTE_VALUE,Bt.SPECIAL_PASTE_FORMAT,Bt.SPECIAL_PASTE_FORMULA].includes(t.pasteType))return{redos:[],undos:[]};let{unitId:n,subUnitId:r}=this._copyInfo;if(t.unitId!==n||r!==t.subUnitId){let i=this._sheetDataValidationModel.getRuleObjectMatrix(t.unitId,t.subUnitId).clone(),a=new y,o=new Set,{ranges:[s,c],mapFunc:l}=Gt([t.copyRange,e]),u=Wt(s,c,!0),d=new Map;u.forEach(({startRange:e})=>{var i;(i=this._copyInfo)==null||i.matrix.forValue((i,s,c)=>{let u=C.getPositionRange({startRow:i,endRow:i,startColumn:s,endColumn:s},e),f=`${r}-${c}`,p=this._sheetDataValidationModel.getRuleById(n,r,c);!this._sheetDataValidationModel.getRuleById(t.unitId,t.subUnitId,f)&&p&&d.set(f,{...p,uid:f});let{row:m,col:h}=l(u.startRow,u.startColumn);o.add(f),a.setValue(m,h,f)})});let f=Array.from(o).map(e=>({id:e,ranges:I(a,t=>t===e)}));i.addRangeRules(f);let{redoMutations:p,undoMutations:m}=et(t.unitId,t.subUnitId,i.diffWithAddition(this._sheetDataValidationModel.getRules(t.unitId,t.subUnitId),d.values()),this._injector,`patched`,!1);return{redos:p,undos:m}}else{let i=this._sheetDataValidationModel.getRuleObjectMatrix(n,r).clone(),a=new y,o=new Set,{ranges:[s,c],mapFunc:l}=Gt([t.copyRange,e]);Wt(s,c,!0).forEach(({startRange:e})=>{var t;(t=this._copyInfo)==null||t.matrix.forValue((t,n,r)=>{let i=C.getPositionRange({startRow:t,endRow:t,startColumn:n,endColumn:n},e),{row:s,col:c}=l(i.startRow,i.startColumn);a.setValue(s,c,r),o.add(r)})});let u=Array.from(o).map(e=>({id:e,ranges:I(a,t=>t===e)}));i.addRangeRules(u);let{redoMutations:d,undoMutations:f}=et(n,r,i.diff(this._sheetDataValidationModel.getRules(n,r)),this._injector,`patched`,!1);return{redos:d,undos:f}}}};zn=Z([X(0,zt),X(1,h(V)),X(2,h(g))],zn);let Bn=class extends l{constructor(e,t,n){super(),this._localeService=e,this._commandService=t,this._sheetPermissionCheckController=n,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===Ne.id){let{unitId:t,subUnitId:n,rule:{ranges:r}}=e.params;this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[De],rangeTypes:[be],worksheetTypes:[Oe,ke]},r,t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.setStyleErr`))}if(e.id===Ye.id){let{unitId:t,subUnitId:n,ranges:r}=e.params;this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[De],rangeTypes:[be],worksheetTypes:[Oe,ke]},r,t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.setStyleErr`))}}))}};Bn=Z([X(0,h(v)),X(1,f),X(2,h(we))],Bn);const Vn=`sheet.menu.data-validation`;function Hn(e){return{id:Vn,type:_t.SUBITEMS,icon:`DataValidationIcon`,tooltip:`dataValidation.title`,hidden$:yt(e,O.UNIVER_SHEET),disabled$:Ut(e,{workbookTypes:[De],worksheetTypes:[ke,Oe],rangeTypes:[be]})}}function Un(e){return{id:An.id,title:`dataValidation.panel.title`,type:_t.BUTTON}}function Wn(e){return{id:Fn.id,title:`dataValidation.panel.add`,type:_t.BUTTON}}const Gn={[vt.RULES]:{[Vn]:{order:0,menuItemFactory:Hn,[An.id]:{order:0,menuItemFactory:Un},[Fn.id]:{order:1,menuItemFactory:Wn}}}},Kn={tr:{size:6,color:`#fe4b4b`}};let qn=class extends T{constructor(e,t,n,r,i,a,o,s,c,l,u){super(),this._commandService=e,this._menuManagerService=t,this._renderManagerService=n,this._univerInstanceService=r,this._autoHeightController=i,this._dropdownManagerService=a,this._sheetDataValidationModel=o,this._dataValidatorRegistryService=s,this._sheetInterceptorService=c,this._dataValidationCacheService=l,this._editorBridgeService=u,this._initMenu(),this._initDropdown(),this._initViewModelIntercept(),this._initAutoHeight()}_initMenu(){this._menuManagerService.mergeMenu(Gn)}_initDropdown(){this._editorBridgeService&&this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{if(!e.visible){var t;((t=this._dropdownManagerService.activeDropdown)==null?void 0:t.trigger)===`editor-bridge`&&this._dropdownManagerService.hideDropdown();return}let n=this._editorBridgeService.getEditCellState();if(n){let{unitId:e,sheetId:t,row:r,column:i}=n,a=this._univerInstanceService.getUniverSheetInstance(e);if(!a)return;let o=this._sheetDataValidationModel.getRuleByLocation(e,t,r,i);if(!o)return;let s=this._dataValidatorRegistryService.getValidatorItem(o.type);if(!(s!=null&&s.dropdownType))return;let c=a.getActiveSheet();if(!c)return;let l=this._dropdownManagerService.activeDropdown,u=l==null?void 0:l.location;if(u&&u.unitId===e&&u.subUnitId===t&&u.row===r&&u.col===i)return;this._dropdownManagerService.showDropdown({location:{unitId:e,subUnitId:t,row:r,col:i,workbook:a,worksheet:c},trigger:`editor-bridge`,closeOnOutSide:!1})}}))}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(ve.CELL_CONTENT,{effect:_.Style,priority:ye.DATA_VALIDATION,handler:(e,t,n)=>{var r,i,a,c,l;let{row:u,col:d,unitId:f,subUnitId:p,workbook:m,worksheet:h}=t,g=this._sheetDataValidationModel.getRuleIdByLocation(f,p,u,d);if(!g)return n(e);let _=this._sheetDataValidationModel.getRuleById(f,p,g);if(!_)return n(e);let v=(r=this._dataValidationCacheService.getValue(f,p,u,d))==null?o.VALID:r,y=this._dataValidatorRegistryService.getValidatorItem(_.type),b=t.rawData,x,S={get value(){var e;return x===void 0&&(x=(e=H(b))==null?null:e),x}},C={get value(){var e;return`${(e=S.value)==null?``:e}`}};return(!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,...v===o.INVALID?Kn:null},e.customRender=[...(i=e==null?void 0:e.customRender)==null?[]:i,...y!=null&&y.canvasRender?[y.canvasRender]:[]],e.fontRenderExtension={...e==null?void 0:e.fontRenderExtension,isSkip:(e==null||(a=e.fontRenderExtension)==null?void 0:a.isSkip)||(y==null||(c=y.skipDefaultFontRender)==null?void 0:c.call(y,_,S.value,t))},e.interceptorStyle={...e==null?void 0:e.interceptorStyle,...y==null?void 0:y.getExtraStyle(_,C.value,{get style(){let t=m.getStyles();return(typeof(e==null?void 0:e.s)==`string`?t.get(e==null?void 0:e.s):e==null?void 0:e.s)||{}}},u,d)},e.interceptorAutoHeight=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(f))==null||(t=t.with(Ht).getSkeletonParam(p))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(u,d),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?u:n,(r=s==null?void 0:s.startColumn)==null?d:r),unitId:f,subUnitId:p,row:u,col:d,workbook:m,worksheet:h};return y==null||(i=y.canvasRender)==null||(a=i.calcCellAutoHeight)==null?void 0:a.call(i,c)},e.interceptorAutoWidth=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(f))==null||(t=t.with(Ht).getSkeletonParam(p))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(u,d),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?u:n,(r=s==null?void 0:s.startColumn)==null?d:r),unitId:f,subUnitId:p,row:u,col:d,workbook:m,worksheet:h};return y==null||(i=y.canvasRender)==null||(a=i.calcCellAutoWidth)==null?void 0:a.call(i,c)},e.coverable=((l=e==null?void 0:e.coverable)==null?!0:l)&&!(_.type===s.LIST||_.type===s.LIST_MULTIPLE),n(e)}}))}_initAutoHeight(){this._sheetDataValidationModel.ruleChange$.pipe(Ot(e=>e.source===`command`),Tt(100)).subscribe(e=>{if(e.length===0)return;let t=[];e.forEach(e=>{if(e.rule.type===s.LIST_MULTIPLE||e.rule.type===s.LIST){var n;(n=e.rule)!=null&&n.ranges&&t.push(...e.rule.ranges)}}),t.length&&re(this._autoHeightController.getUndoRedoParamsOfAutoHeight(t).redos,this._commandService)})}};qn=Z([X(0,f),X(1,pt),X(2,B),X(3,m),X(4,h(jt)),X(5,h(On)),X(6,h(V)),X(7,h(st)),X(8,h(Ce)),X(9,h(Be)),X(10,b(It))],qn);let Jn=class extends T{constructor(e,t,n,r,i,a,o){super(),this._commandService=e,this._renderManagerService=t,this._autoHeightController=n,this._dataValidatorRegistryService=r,this._sheetInterceptorService=i,this._sheetDataValidationModel=a,this._dataValidationCacheService=o,this._initViewModelIntercept(),this._initAutoHeight()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(ve.CELL_CONTENT,{effect:_.Style,priority:ye.DATA_VALIDATION,handler:(e,t,n)=>{var r,i,a,c,l;let{row:u,col:d,unitId:f,subUnitId:p,workbook:m,worksheet:h}=t,g=this._sheetDataValidationModel.getRuleIdByLocation(f,p,u,d);if(!g)return n(e);let _=this._sheetDataValidationModel.getRuleById(f,p,g);if(!_)return n(e);let v=(r=this._dataValidationCacheService.getValue(f,p,u,d))==null?o.VALID:r,y=this._dataValidatorRegistryService.getValidatorItem(_.type),b=H(h.getCellRaw(u,d)),x=`${b==null?``:b}`;return(!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,...v===o.INVALID?Kn:null},e.customRender=[...(i=e==null?void 0:e.customRender)==null?[]:i,...y!=null&&y.canvasRender?[y.canvasRender]:[]],e.fontRenderExtension={...e==null?void 0:e.fontRenderExtension,isSkip:(e==null||(a=e.fontRenderExtension)==null?void 0:a.isSkip)||(y==null||(c=y.skipDefaultFontRender)==null?void 0:c.call(y,_,b,t))},e.interceptorStyle={...e==null?void 0:e.interceptorStyle,...y==null?void 0:y.getExtraStyle(_,x,{get style(){let t=m.getStyles();return(typeof(e==null?void 0:e.s)==`string`?t.get(e==null?void 0:e.s):e==null?void 0:e.s)||{}}},u,d)},e.interceptorAutoHeight=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(f))==null||(t=t.with(Ht).getSkeletonParam(p))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(u,d),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?u:n,(r=s==null?void 0:s.startColumn)==null?d:r),unitId:f,subUnitId:p,row:u,col:d,workbook:m,worksheet:h};return y==null||(i=y.canvasRender)==null||(a=i.calcCellAutoHeight)==null?void 0:a.call(i,c)},e.interceptorAutoWidth=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(f))==null||(t=t.with(Ht).getSkeletonParam(p))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(u,d),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?u:n,(r=s==null?void 0:s.startColumn)==null?d:r),unitId:f,subUnitId:p,row:u,col:d,workbook:m,worksheet:h};return y==null||(i=y.canvasRender)==null||(a=i.calcCellAutoWidth)==null?void 0:a.call(i,c)},e.coverable=((l=e==null?void 0:e.coverable)==null?!0:l)&&!(_.type===s.LIST||_.type===s.LIST_MULTIPLE),n(e)}}))}_initAutoHeight(){this._sheetDataValidationModel.ruleChange$.pipe(Ot(e=>e.source===`command`),Tt(16)).subscribe(e=>{let t=[];e.forEach(e=>{if(e.rule.type===s.LIST_MULTIPLE||e.rule.type===s.LIST){var n;(n=e.rule)!=null&&n.ranges&&t.push(...e.rule.ranges)}}),t.length&&re(this._autoHeightController.getUndoRedoParamsOfAutoHeight(t).redos,this._commandService)})}};Jn=Z([X(0,f),X(1,B),X(2,h(jt)),X(3,h(st)),X(4,h(Ce)),X(5,h(V)),X(6,h(Be))],Jn);let Yn=class extends l{constructor(e,t,n){super(),this._context=e,this._sheetDataValidationModel=t,this._sheetSkeletonManagerService=n,this._initSkeletonChange()}_initSkeletonChange(){this.disposeWithMe(this._sheetDataValidationModel.validStatusChange$.pipe(ee(16)).subscribe(e=>{var t;if(!e.length)return;let n=new Set;e.forEach(e=>{n.add(e.subUnitId)}),n.forEach(e=>{var t;(t=this._sheetSkeletonManagerService.getSkeletonParam(e))==null||t.skeleton.makeDirty(!0)}),(t=this._context.mainComponent)==null||t.makeForceDirty()}))}};Yn=Z([X(1,h(V)),X(2,h(Ht))],Yn);function Xn(e){var t;let n=W(v),r=W(dt),{value:a,onChange:o,extraComponent:s}=e,[c,l]=K(!1),u=s?r.get(s):null;return J(_n,{children:[J(`div`,{className:`
|
|
2
2
|
univer-mb-3 univer-flex univer-cursor-pointer univer-items-center univer-text-sm univer-text-gray-900
|
|
3
3
|
dark:!univer-text-white
|
|
4
4
|
`,onClick:()=>l(!c),children:[n.t(`dataValidation.panel.options`),q(c?dn:un,{className:`univer-ml-1`})]}),c&&J(_n,{children:[u?q(u,{value:a,onChange:o}):null,q(G,{label:n.t(`dataValidation.panel.invalid`),children:J(Qt,{value:`${(t=a.errorStyle)==null?i.WARNING:t}`,onChange:e=>o({...a,errorStyle:+e}),children:[q(Zt,{value:`${i.WARNING}`,children:n.t(`dataValidation.panel.showWarning`)}),q(Zt,{value:`${i.STOP}`,children:n.t(`dataValidation.panel.rejectInput`)})]})}),q(G,{label:n.t(`dataValidation.panel.messageInfo`),children:q(qt,{checked:a.showErrorMessage,onChange:()=>o({...a,showErrorMessage:!a.showErrorMessage}),children:n.t(`dataValidation.panel.showInfo`)})}),a.showErrorMessage?q(G,{children:q(Xt,{value:a.error,onChange:e=>o({...a,error:e})})}):null]})]})}const Zn=e=>M(async(t,n,r,i)=>{let a=await e.executeCommand(t,n,r);i==null||i(a)},1e3);function Qn(e,t,n){var r;if(t){var i;return((i=e.getUnit(t))==null||(i=i.getSheetBySheetName(n))==null?void 0:i.getSheetId())||``}return((r=e.getCurrentUnitForType(O.UNIVER_SHEET))==null||(r=r.getSheetBySheetName(n))==null?void 0:r.getSheetId())||``}function $n(){var e,t;let[n,r]=K(0),i=W(Q),{unitId:a,subUnitId:o,rule:s}=xt(i.activeRule$,i.activeRule)||{},c=s.uid,l=W(st),u=W(m),d=W(dt),p=W(f),h=W(at),g=W(v),_=xt(()=>u.getCurrentTypeOfUnit$(O.UNIVER_SHEET),void 0,void 0,[]),y=xt(()=>{var e;return(e=_==null?void 0:_.activeSheet$)==null?kt(null):e},void 0,void 0,[]),[b,x]=K(s),S=l.getValidatorItem(b.type),[C,T]=K(!1),E=l.getValidatorsByScope(ot.SHEET),[k,A]=K(()=>b.ranges.map(e=>({unitId:``,sheetId:``,range:e}))),ee=an(()=>Zn(p),[p]),[j,M]=K(!1),[te,N]=K(!1),P=on(null),F=W(Te);if(rn(()=>()=>{let e=F.getCurrentLastSelection();e&&F.setSelections([e])},[F]),rn(()=>{p.onCommandExecuted(e=>{(e.id===D.id||e.id===w.id)&&setTimeout(()=>{let e=h.getRuleById(a,o,c);r(e=>e+1),e&&(x(e),A(e.ranges.map(e=>({unitId:``,sheetId:``,range:e}))))},20)})},[p,h,c,o,a]),!S)return null;let I=S.operators,re=S.operatorNames,ae=b.operator?ct.includes(b.operator):!1,L=()=>{(y==null?void 0:y.getSheetId())!==o&&p.syncExecuteCommand(Se.id,{unitId:a,subUnitId:o})},oe=()=>{var e;if(!((e=P.current)==null||(e=e.editor)==null)&&e.isFocus()){var t;R((t=P.current)==null?void 0:t.getValue())}!b.ranges.length||j||(S.validatorFormula(b,a,o).success?i.setActiveRule(null):T(!0),L())},R=bt(e=>{let t=e.split(`,`).filter(Boolean).map(pn).map(e=>{let t=e.sheetName;if(t){let n=Qn(u,e.unitId,t);return{...e,sheetId:n}}return{...e,sheetId:``}});if(ne(t,k))return;A(t);let n=t.filter(e=>(!e.unitId||e.unitId===a)&&(!e.sheetId||e.sheetId===o)).map(e=>e.range);if(x({...b,ranges:n}),n.length===0)return;let r={unitId:a,subUnitId:o,ruleId:c,ranges:n};ee(Ye.id,r)}),z=e=>{if(ie(e,ut(b)))return;x({...b,...e});let t={unitId:a,subUnitId:o,ruleId:c,setting:e};ee(Xe.id,t,void 0)},se=async()=>{await p.executeCommand(Ge.id,{ruleId:c,unitId:a,subUnitId:o}),i.setActiveRule(null),L()},B={type:b.type,operator:b.operator,formula1:b.formula1,formula2:b.formula2,allowBlank:b.allowBlank},ce=e=>{let t=l.getValidatorItem(e);if(!t)return;let n=t.operators,r=h.getRuleById(a,o,c),i=e===(r==null?void 0:r.type)||e.includes(`list`)&&r!=null&&r.type.includes(`list`)?{...r,type:e}:{...b,type:e,operator:n[0],formula1:void 0,formula2:void 0};x(i),p.executeCommand(Xe.id,{unitId:a,subUnitId:o,ruleId:b.uid,setting:ut(i)})},le=d.get(S.formulaInput),ue=an(()=>k.map(e=>mn(e.range)).join(`,`),[]),de=lt(b),fe=e=>{ie(e,lt(b))||(x({...b,...e}),ee(Je.id,{unitId:a,subUnitId:o,ruleId:c,options:e}))},pe=I.length&&!b.operator;return J(`div`,{"data-u-comp":`data-validation-detail`,className:`univer-py-2`,children:[q(G,{label:g.t(`dataValidation.panel.range`),error:!b.ranges.length||j?g.t(`dataValidation.panel.rangeError`):``,children:q(gn,{selectorRef:P,unitId:a,subUnitId:o,initialValue:ue,onChange:(e,t)=>{var n;!te&&(n=P.current)!=null&&n.verify()&&R(t)},onFocusChange:(e,t)=>{var n;N(e),!e&&t&&(n=P.current)!=null&&n.verify()&&R(t)},onVerify:e=>M(!e)})}),q(G,{label:g.t(`dataValidation.panel.type`),children:q($t,{className:`univer-w-full`,value:b.type,options:E==null||(e=E.sort((e,t)=>e.order-t.order))==null?void 0:e.map(e=>({label:g.t(e.title),value:e.id})),onChange:ce})}),I!=null&&I.length?q(G,{label:g.t(`dataValidation.panel.operator`),children:q($t,{className:`univer-w-full`,value:`${b.operator}`,options:[{value:``,label:g.t(`dataValidation.operators.legal`)},...I.map((e,t)=>({value:`${e}`,label:re[t]}))],onChange:e=>{z({...B,operator:e})}})}):null,le&&!pe?q(le,{isTwoFormula:ae,value:{formula1:b.formula1,formula2:b.formula2},onChange:e=>{z({...B,...e})},showError:C,validResult:S.validatorFormula(b,a,o),unitId:a,subUnitId:o,ruleId:c},n+b.type):null,q(G,{children:q(qt,{checked:(t=b.allowBlank)==null?!0:t,onChange:()=>{var e;return z({...B,allowBlank:!((e=b.allowBlank)==null||e)})},children:g.t(`dataValidation.panel.allowBlank`)})}),q(Xn,{value:de,onChange:fe,extraComponent:S.optionsInput}),J(`div`,{className:`univer-mt-5 univer-flex univer-flex-row univer-justify-end`,children:[q(Kt,{className:`univer-ml-3`,onClick:se,children:g.t(`dataValidation.panel.removeRule`)}),q(Kt,{className:`univer-ml-3`,variant:`primary`,onClick:oe,children:g.t(`dataValidation.panel.done`)})]})]})}const er=e=>{let{rule:n,onClick:r,unitId:i,subUnitId:a,disable:o}=e,s=W(st),c=W(f),l=W(Lt),u=s.getValidatorItem(n.type),d=on(void 0),[p,m]=K(!1),h=W(E),g=an(()=>{var e;let n=h.getColorFromTheme(`primary.600`),r=h.getColorFromTheme(`loop-color.2`),i=(e=h.getColorFromTheme(r))==null?n:e,a=new t(i).toRgb();return{fill:`rgba(${a.r}, ${a.g}, ${a.b}, 0.1)`,stroke:i}},[xt(h.currentTheme$)]),_=e=>{c.executeCommand(Ge.id,{ruleId:n.uid,unitId:i,subUnitId:a}),e.stopPropagation()};return rn(()=>()=>{if(d.current){var e;(e=d.current)==null||e.forEach(e=>{e&&l.removeShape(e)})}},[l]),J(`div`,{className:tn(`
|
package/lib/umd/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/engine-render`),require(`@univerjs/sheets`),require(`@univerjs/sheets-data-validation`),require(`@univerjs/data-validation`),require(`@univerjs/ui`),require(`rxjs`),require(`@univerjs/sheets-numfmt`),require(`@univerjs/sheets-ui`),require(`@univerjs/design`),require(`react`),require(`@univerjs/engine-formula`),require(`@univerjs/sheets-formula-ui`),require(`react/jsx-runtime`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/engine-render`,`@univerjs/sheets`,`@univerjs/sheets-data-validation`,`@univerjs/data-validation`,`@univerjs/ui`,`rxjs`,`@univerjs/sheets-numfmt`,`@univerjs/sheets-ui`,`@univerjs/design`,`react`,`@univerjs/engine-formula`,`@univerjs/sheets-formula-ui`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsDataValidationUi={},e.UniverCore,e.UniverEngineRender,e.UniverSheets,e.UniverSheetsDataValidation,e.UniverDataValidation,e.UniverUi,e.rxjs,e.UniverSheetsNumfmt,e.UniverSheetsUi,e.UniverDesign,e.React,e.UniverEngineFormula,e.UniverSheetsFormulaUi,e.React))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var h=Object.create,g=Object.defineProperty,_=Object.getOwnPropertyDescriptor,v=Object.getOwnPropertyNames,y=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty,x=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=v(t),a=0,o=i.length,s;a<o;a++)s=i[a],!b.call(e,s)&&s!==n&&g(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=_(t,s))||r.enumerable});return e};d=((e,t,n)=>(n=e==null?{}:h(y(e)),x(t||!e||!e.__esModule?g(n,`default`,{value:e,enumerable:!0}):n,e)))(d);var S=`@univerjs/sheets-data-validation-ui`,C=`0.17.0-insiders.20260318-5bef180`;function w(e){"@babel/helpers - typeof";return w=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},w(e)}function T(e,t){if(w(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(w(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function E(e){var t=T(e,`string`);return w(t)==`symbol`?t:t+``}function D(e,t,n){return(t=E(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function O(e,t){return function(n,r){t(n,r,e)}}function k(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let A=class extends t.Disposable{get activeRule(){return this._activeRule}get isOpen(){return this._open$.getValue()}constructor(e,n){super(),this._univerInstanceService=e,this._sidebarService=n,D(this,`_open$`,new s.BehaviorSubject(!1)),D(this,`open$`,this._open$.pipe((0,s.distinctUntilChanged)())),D(this,`_activeRule`,void 0),D(this,`_activeRule$`,new s.BehaviorSubject(void 0)),D(this,`activeRule$`,this._activeRule$.asObservable()),D(this,`_closeDisposable`,null),D(this,`_focusFormulaEditorActiveRuleSubUnitId`,null),this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe((0,s.filter)(e=>!e)).subscribe(()=>{this.close()})),this.disposeWithMe(this._sidebarService.sidebarOptions$.subscribe(e=>{e.id===`DataValidationPanel`&&(e.visible||setTimeout(()=>{this._sidebarService.sidebarOptions$.next({visible:!1})}))}))}dispose(){var e;super.dispose(),this._open$.next(!1),this._open$.complete(),this._activeRule$.complete(),(e=this._closeDisposable)==null||e.dispose()}open(){this._open$.next(!0)}close(){var e;this._open$.next(!1),(e=this._closeDisposable)==null||e.dispose()}setCloseDisposable(e){this._closeDisposable=(0,t.toDisposable)(()=>{e.dispose(),this._closeDisposable=null})}setActiveRule(e){this._activeRule=e,this._activeRule$.next(e)}setFocusFormulaEditorActiveRuleSubUnitId(e){this._focusFormulaEditorActiveRuleSubUnitId=e}getFocusFormulaEditorActiveRuleSubUnitId(){return this._focusFormulaEditorActiveRuleSubUnitId}};A=k([O(0,t.IUniverInstanceService),O(1,o.ISidebarService)],A);let j=`sheets-data-validation-ui.config`;Symbol(j);let M={},N=class extends t.Disposable{constructor(e,t,n,r,i,a){super(),this._sheetInterceptorService=e,this._dataValidationModel=t,this._dataValidatorRegistryService=n,this._dialogService=r,this._localeService=i,this._sheetsDataValidationValidatorService=a,this._initEditorBridgeInterceptor()}_initEditorBridgeInterceptor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(r.VALIDATE_CELL,{handler:async(e,n,r)=>{let i=await e,{row:a,col:o,unitId:s,subUnitId:c}=n,l=this._dataValidationModel.getRuleIdByLocation(s,c,a,o),f=l?this._dataValidationModel.getRuleById(s,c,l):void 0;if(i===!1)return r(Promise.resolve(!1));if(!f||f.errorStyle!==t.DataValidationErrorStyle.STOP)return r(Promise.resolve(!0));let p=this._dataValidatorRegistryService.getValidatorItem(f.type);return!p||await this._sheetsDataValidationValidatorService.validatorCell(s,c,a,o)===t.DataValidationStatus.VALID?r(Promise.resolve(!0)):(this._dialogService.open({width:368,title:{title:this._localeService.t(`dataValidation.alert.title`)},id:`reject-input-dialog`,children:{title:p.getRuleFinalError(f,{row:a,col:o,unitId:s,subUnitId:c})},footer:{title:(0,d.createElement)(u.Button,{variant:`primary`,onClick:()=>this._dialogService.close(`reject-input-dialog`)},this._localeService.t(`dataValidation.alert.ok`))},onClose:()=>{this._dialogService.close(`reject-input-dialog`)}}),r(Promise.resolve(!1)))}}))}showReject(e){this._dialogService.open({width:368,title:{title:this._localeService.t(`dataValidation.alert.title`)},id:`reject-input-dialog`,children:{title:e},footer:{title:(0,d.createElement)(u.Button,{variant:`primary`,onClick:()=>this._dialogService.close(`reject-input-dialog`)},this._localeService.t(`dataValidation.alert.ok`))},onClose:()=>{this._dialogService.close(`reject-input-dialog`)}})}};N=k([O(0,(0,t.Inject)(r.SheetInterceptorService)),O(1,(0,t.Inject)(i.SheetDataValidationModel)),O(2,(0,t.Inject)(a.DataValidatorRegistryService)),O(3,o.IDialogService),O(4,(0,t.Inject)(t.LocaleService)),O(5,(0,t.Inject)(i.SheetsDataValidationValidatorService))],N);let P=e=>{if(e==null||typeof e==`boolean`)return;if(e===``)return(0,t.dayjs)();if(typeof e==`number`||!Number.isNaN(+e))return(0,t.dayjs)(t.numfmt.format(`yyyy-MM-dd HH:mm:ss`,Number(e)));let n=(0,t.dayjs)(e);if(n.isValid())return n};function F(e,t){if(e===(0,c.getPatternType)(t))return t;switch(e){case`datetime`:return`yyyy-MM-dd hh:mm:ss`;case`date`:return`yyyy-MM-dd`;case`time`:return`HH:mm:ss`}}let I=class extends t.Disposable{get activeDropdown(){return this._activeDropdown}constructor(e,t,n,r,i,a,o,c,l,u,d){super(),this._univerInstanceService=e,this._dataValidatorRegistryService=t,this._zenZoneService=n,this._dataValidationModel=r,this._sheetsSelectionsService=i,this._cellDropdownManagerService=a,this._sheetDataValidationModel=o,this._commandService=c,this._editorBridgeService=l,this._injector=u,this._configService=d,D(this,`_activeDropdown`,void 0),D(this,`_activeDropdown$`,new s.Subject),D(this,`_currentPopup`,null),D(this,`activeDropdown$`,this._activeDropdown$.asObservable()),D(this,`_zenVisible`,!1),this._init(),this._initSelectionChange(),this.disposeWithMe(()=>{this._activeDropdown$.complete()})}_init(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{this._zenVisible=e,e&&this.hideDropdown()}))}_getDropdownByCell(e,n,r,i){let a=e?this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET);if(!a)return;let o=n?a.getSheetBySheetId(n):a.getActiveSheet();if(!o)return;let s=this._dataValidationModel.getRuleByLocation(a.getUnitId(),o.getSheetId(),r,i);if(!s)return;let c=this._dataValidatorRegistryService.getValidatorItem(s.type);return c==null?void 0:c.dropdownType}_initSelectionChange(){this.disposeWithMe(this._sheetsSelectionsService.selectionMoveEnd$.subscribe(e=>{e&&e.every(e=>!(e.primary&&this._getDropdownByCell(e.primary.unitId,e.primary.sheetId,e.primary.actualRow,e.primary.actualColumn)))&&this.hideDropdown()}))}showDropdown(e){let{location:s}=e,{row:c,col:u,unitId:d,subUnitId:f,workbook:p,worksheet:m}=s;if(this._currentPopup&&this._currentPopup.dispose(),this._zenVisible)return;this._activeDropdown=e,this._activeDropdown$.next(this._activeDropdown);let h=this._sheetDataValidationModel.getRuleByLocation(d,f,c,u);if(!h)return;let g=this._dataValidatorRegistryService.getValidatorItem(h.type);if(!(g!=null&&g.dropdownType))return;let _,v=async(e,i)=>{var a,s,_;if(!e)return!0;let v=e,y=m.getCell(c,u),b=v.format(i===`date`?`YYYY-MM-DD 00:00:00`:`YYYY-MM-DD HH:mm:ss`),x=(a=t.numfmt.parseDate(b))==null?void 0:a.v,S=i===`time`?x%1:x,C=p.getStyles().getStyleByCell(y),w=(s=C==null||(_=C.n)==null?void 0:_.pattern)==null?``:s;return h.errorStyle!==t.DataValidationErrorStyle.STOP||await g.validator({value:S,unitId:d,subUnitId:f,row:c,column:u,worksheet:m,workbook:p,interceptValue:b.replace(`Z`,``).replace(`T`,` `),t:t.CellValueType.NUMBER},h)?(await this._commandService.executeCommand(r.SetRangeValuesCommand.id,{unitId:d,subUnitId:f,range:{startColumn:u,endColumn:u,startRow:c,endRow:c},value:{v:S,t:2,p:null,f:null,si:null,s:{n:{pattern:F(i,w)}}}}),await this._commandService.executeCommand(l.SetCellEditVisibleOperation.id,{visible:!1,eventType:n.DeviceInputEventType.Keyboard,unitId:d,keycode:o.KeyCode.ESC}),!0):(this._injector.has(N)&&this._injector.get(N).showReject(g.getRuleFinalError(h,{row:c,col:u,unitId:d,subUnitId:f})),!1)},y;switch(g.dropdownType){case a.DataValidatorDropdownType.DATE:{var b;let e=P((0,i.getCellValueOrigin)(m.getCellRaw(c,u))),t=!!((b=h.bizInfo)!=null&&b.showTime);y={location:s,type:`datepicker`,props:{showTime:t,onChange:e=>v(e,t?`datetime`:`date`),defaultValue:e,patternType:`date`}};break}case a.DataValidatorDropdownType.TIME:y={location:s,type:`datepicker`,props:{onChange:e=>v(e,`time`),defaultValue:P((0,i.getCellValueOrigin)(m.getCellRaw(c,u))),patternType:`time`}};break;case a.DataValidatorDropdownType.DATETIME:y={location:s,type:`datepicker`,props:{onChange:e=>v(e,`datetime`),defaultValue:P((0,i.getCellValueOrigin)(m.getCellRaw(c,u))),patternType:`datetime`}};break;case a.DataValidatorDropdownType.LIST:case a.DataValidatorDropdownType.MULTIPLE_LIST:{var x,S,C,w;let e=g.dropdownType===a.DataValidatorDropdownType.MULTIPLE_LIST,p=async t=>{let a=(0,i.serializeListOptions)(t),s={unitId:d,subUnitId:f,range:{startColumn:u,endColumn:u,startRow:c,endRow:c},value:{v:a,p:null,f:null,si:null}};return this._commandService.executeCommand(r.SetRangeValuesCommand.id,s),this._editorBridgeService.isVisible().visible&&await this._commandService.executeCommand(l.SetCellEditVisibleOperation.id,{visible:!1,eventType:n.DeviceInputEventType.Keyboard,unitId:d,keycode:o.KeyCode.ESC}),!e},v=(h==null?void 0:h.renderMode)===t.DataValidationRenderMode.CUSTOM||(h==null?void 0:h.renderMode)===void 0,b=g.getListWithColor(h,d,f),T=(0,i.getDataValidationCellValue)(m.getCellRaw(c,u));y={location:s,type:`list`,props:{onChange:e=>p(e),options:b.map(e=>({label:e.label,value:e.label,color:v||e.color?e.color||`#ECECEC`:`transparent`})),onEdit:()=>{this._commandService.executeCommand(R.id,{ruleId:h.uid}),_==null||_.dispose()},defaultValue:T,multiple:e,showEdit:(x=(S=this._configService.getConfig(`sheets-data-validation-ui.config`))==null?void 0:S.showEditOnDropdown)==null?!0:x,showSearch:(C=(w=this._configService.getConfig(`sheets-data-validation-ui.config`))==null?void 0:w.showSearchOnDropdown)==null?!0:C}};break}case a.DataValidatorDropdownType.CASCADE:var T;y={type:`cascader`,props:{onChange:e=>{let t={unitId:d,subUnitId:f,range:{startColumn:u,endColumn:u,startRow:c,endRow:c},value:{v:e.join(`/`),p:null,f:null,si:null}};return this._commandService.syncExecuteCommand(r.SetRangeValuesCommand.id,t),this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(l.SetCellEditVisibleOperation.id,{visible:!1,eventType:n.DeviceInputEventType.Keyboard,unitId:d,keycode:o.KeyCode.ESC}),!0},defaultValue:(0,i.getDataValidationCellValue)(m.getCellRaw(c,u)).split(`/`),options:JSON.parse((T=h.formula1)==null?`[]`:T)},location:s};break;case a.DataValidatorDropdownType.COLOR:y={type:`color`,props:{onChange:e=>{let t={unitId:d,subUnitId:f,range:{startColumn:u,endColumn:u,startRow:c,endRow:c},value:{v:e,p:null,f:null,si:null}};return this._commandService.syncExecuteCommand(r.SetRangeValuesCommand.id,t),this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(l.SetCellEditVisibleOperation.id,{visible:!1,eventType:n.DeviceInputEventType.Keyboard,unitId:d,keycode:o.KeyCode.ESC}),!0},defaultValue:(0,i.getDataValidationCellValue)(m.getCellRaw(c,u))},location:s};break;default:throw Error(`[DataValidationDropdownManagerService]: unknown type!`)}if(_=this._cellDropdownManagerService.showDropdown({...y,onHide:()=>{this._activeDropdown=null,this._activeDropdown$.next(null)}}),!_)throw Error(`[DataValidationDropdownManagerService]: cannot show dropdown!`);let E=new t.DisposableCollection;E.add(_),E.add({dispose:()=>{var e,t;(e=this._activeDropdown)==null||(t=e.onHide)==null||t.call(e)}}),this._currentPopup=E}hideDropdown(){this._activeDropdown&&(this._currentPopup&&this._currentPopup.dispose(),this._currentPopup=null,this._activeDropdown=null,this._activeDropdown$.next(null))}showDataValidationDropdown(e,n,r,i,a){let o=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!o)return;let s=o.getSheetBySheetId(n);if(!s)return;let c=this._dataValidationModel.getRuleByLocation(o.getUnitId(),s.getSheetId(),r,i);if(!c)return;let l=this._dataValidatorRegistryService.getValidatorItem(c.type);if(!l||!l.dropdownType){this.hideDropdown();return}this.showDropdown({location:{workbook:o,worksheet:s,row:r,col:i,unitId:e,subUnitId:n},onHide:a})}};I=k([O(0,t.IUniverInstanceService),O(1,(0,t.Inject)(a.DataValidatorRegistryService)),O(2,o.IZenZoneService),O(3,(0,t.Inject)(i.SheetDataValidationModel)),O(4,(0,t.Inject)(r.SheetsSelectionsService)),O(5,(0,t.Inject)(l.ISheetCellDropdownManagerService)),O(6,(0,t.Inject)(i.SheetDataValidationModel)),O(7,t.ICommandService),O(8,l.IEditorBridgeService),O(9,(0,t.Inject)(t.Injector)),O(10,t.IConfigService)],I);let L=`DataValidationPanel`,R={id:`data-validation.operation.open-validation-panel`,type:t.CommandType.OPERATION,handler(e,n){if(!n)return!1;let{ruleId:i,isAdd:s}=n,c=e.get(A),l=e.get(a.DataValidationModel),u=e.get(t.IUniverInstanceService),d=e.get(o.ISidebarService),f=(0,r.getSheetCommandTarget)(u);if(!f)return!1;let{unitId:p,subUnitId:m}=f,h=i?l.getRuleById(p,m,i):void 0;c.open(),c.setActiveRule(h&&{unitId:p,subUnitId:m,rule:h});let g=d.open({id:L,header:{title:s?`dataValidation.panel.addTitle`:`dataValidation.panel.title`},children:{label:L},width:312,onClose:()=>c.close()});return c.setCloseDisposable(g),!0}},z={id:`data-validation.operation.close-validation-panel`,type:t.CommandType.OPERATION,handler(e){return e.get(A).close(),!0}},B={id:`data-validation.operation.toggle-validation-panel`,type:t.CommandType.OPERATION,handler(e){let n=e.get(t.ICommandService),r=e.get(A);return r.open(),r.isOpen?n.executeCommand(z.id):n.executeCommand(R.id),!0}},V={type:t.CommandType.OPERATION,id:`sheet.operation.show-data-validation-dropdown`,handler(e,t){if(!t)return!1;let n=e.get(I),{unitId:r,subUnitId:i,row:a,column:o}=t,s=n.activeDropdown,c=s==null?void 0:s.location;return c&&c.unitId===r&&c.subUnitId===i&&c.row===a&&c.col===o||n.showDataValidationDropdown(r,i,a,o),!0}},H={type:t.CommandType.OPERATION,id:`sheet.operation.hide-data-validation-dropdown`,handler(e,t){return t?(e.get(I).hideDropdown(),!0):!1}},U={type:t.CommandType.COMMAND,id:`data-validation.command.addRuleAndOpen`,handler(e){let n=(0,r.getSheetCommandTarget)(e.get(t.IUniverInstanceService));if(!n)return!1;let{workbook:a,worksheet:o}=n,s=(0,i.createDefaultNewRule)(e),c=e.get(t.ICommandService),l={rule:s,unitId:a.getUnitId(),subUnitId:o.getSheetId()};return c.syncExecuteCommand(i.AddSheetDataValidationCommand.id,l)?(c.syncExecuteCommand(R.id,{ruleId:s.uid,isAdd:!0}),!0):!1}},W=`SHEET_DATA_VALIDATION_ALERT`,G=class extends t.Disposable{constructor(e,t,n,r,i,a){super(),this._hoverManagerService=e,this._cellAlertManagerService=t,this._univerInstanceService=n,this._localeService=r,this._zenZoneService=i,this._dataValidationModel=a,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe((0,s.debounceTime)(100)).subscribe(e=>{if(e){let r=this._univerInstanceService.getUnit(e.location.unitId,t.UniverInstanceType.UNIVER_SHEET),i=r.getSheetBySheetId(e.location.subUnitId);if(!i)return;let a=this._dataValidationModel.getRuleByLocation(e.location.unitId,e.location.subUnitId,e.location.row,e.location.col);if(!a){this._cellAlertManagerService.removeAlert(W);return}if(this._dataValidationModel.validator(a,{...e.location,workbook:r,worksheet:i})===t.DataValidationStatus.INVALID){var n;let t=this._cellAlertManagerService.currentAlert.get(W),r=t==null||(n=t.alert)==null?void 0:n.location;if(r&&r.row===e.location.row&&r.col===e.location.col&&r.subUnitId===e.location.subUnitId&&r.unitId===e.location.unitId){this._cellAlertManagerService.removeAlert(W);return}let i=this._dataValidationModel.getValidator(a.type);if(!i){this._cellAlertManagerService.removeAlert(W);return}this._cellAlertManagerService.showAlert({type:l.CellAlertType.ERROR,title:this._localeService.t(`dataValidation.error.title`),message:i==null?void 0:i.getRuleFinalError(a,e.location),location:e.location,width:200,height:74,key:W});return}}this._cellAlertManagerService.removeAlert(W)}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._cellAlertManagerService.removeAlert(W)}))}};G=k([O(0,(0,t.Inject)(l.HoverManagerService)),O(1,(0,t.Inject)(l.CellAlertManagerService)),O(2,t.IUniverInstanceService),O(3,(0,t.Inject)(t.LocaleService)),O(4,o.IZenZoneService),O(5,(0,t.Inject)(i.SheetDataValidationModel))],G);let K=class extends t.Disposable{constructor(e,t,n){super(),this._autoFillService=e,this._sheetDataValidationModel=t,this._injector=n,this._initAutoFill()}_initAutoFill(){let e=()=>({redos:[],undos:[]}),n=(e,n)=>{let{source:a,target:o,unitId:s,subUnitId:c}=e,u=this._sheetDataValidationModel.getRuleObjectMatrix(s,c).clone(),d=(0,l.virtualizeDiscreteRanges)([a,o]),[f,p]=d.ranges,{mapFunc:m}=d,h={row:f.startRow,col:f.startColumn},g=r.AutoFillTools.getAutoFillRepeatRange(f,p),_=new t.ObjectMatrix,v=new Set;g.forEach(e=>{let n=e.repeatStartCell,r=e.relativeRange,i={startRow:h.row,startColumn:h.col,endColumn:h.col,endRow:h.row},a={startRow:n.row,startColumn:n.col,endColumn:n.col,endRow:n.row};t.Range.foreach(r,(e,n)=>{let r=t.Rectangle.getPositionRange({startRow:e,startColumn:n,endColumn:n,endRow:e},i),{row:o,col:l}=m(r.startRow,r.startColumn),u=this._sheetDataValidationModel.getRuleIdByLocation(s,c,o,l)||``,d=t.Rectangle.getPositionRange({startRow:e,startColumn:n,endColumn:n,endRow:e},a),{row:f,col:p}=m(d.startRow,d.startColumn);_.setValue(f,p,u),v.add(u)})});let y=Array.from(v).map(e=>({id:e,ranges:(0,t.queryObjectMatrix)(_,t=>t===e)}));u.addRangeRules(y);let{redoMutations:b,undoMutations:x}=(0,i.getDataValidationDiffMutations)(s,c,u.diff(this._sheetDataValidationModel.getRules(s,c)),this._injector,`patched`,n===r.AUTO_FILL_APPLY_TYPE.ONLY_FORMAT);return{undos:x,redos:b}},a={id:i.DATA_VALIDATION_PLUGIN_NAME,onBeforeFillData:e=>{let{source:n,unitId:i,subUnitId:a}=e;for(let e of n.rows)for(let o of n.cols){let n=this._sheetDataValidationModel.getRuleByLocation(i,a,e,o);if(n&&n.type===t.DataValidationType.CHECKBOX){this._autoFillService.setDisableApplyType(r.AUTO_FILL_APPLY_TYPE.SERIES,!0);return}}},onFillData:(t,i,a)=>a===r.AUTO_FILL_APPLY_TYPE.COPY||a===r.AUTO_FILL_APPLY_TYPE.ONLY_FORMAT||a===r.AUTO_FILL_APPLY_TYPE.SERIES?n(t,a):e(),onAfterFillData:()=>{}};this.disposeWithMe(this._autoFillService.addHook(a))}};K=k([O(0,r.IAutoFillService),O(1,(0,t.Inject)(i.SheetDataValidationModel)),O(2,(0,t.Inject)(t.Injector))],K);let q=class extends t.Disposable{constructor(e,t,n){super(),this._sheetClipboardService=e,this._sheetDataValidationModel=t,this._injector=n,D(this,`_copyInfo`,void 0),this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:i.DATA_VALIDATION_PLUGIN_NAME,onBeforeCopy:(e,t,n)=>this._collect(e,t,n),onPasteCells:(e,t,n,r)=>{let{copyType:i=l.COPY_TYPE.COPY,pasteType:a}=r,{range:o}=e||{},{range:s,unitId:c,subUnitId:u}=t;return this._generateMutations(s,{copyType:i,pasteType:a,copyRange:o,unitId:c,subUnitId:u})}})}_collect(e,n,i){let a=new t.ObjectMatrix;this._copyInfo={unitId:e,subUnitId:n,matrix:a};let o=this._injector.invoke(t=>(0,r.rangeToDiscreteRange)(i,t,e,n));if(!o)return;let{rows:s,cols:c}=o;s.forEach((t,r)=>{c.forEach((i,o)=>{let s=this._sheetDataValidationModel.getRuleIdByLocation(e,n,t,i);a.setValue(r,o,s==null?``:s)})})}_generateMutations(e,n){if(!this._copyInfo)return{redos:[],undos:[]};if(n.copyType===l.COPY_TYPE.CUT)return this._copyInfo=null,{redos:[],undos:[]};if(!this._copyInfo||!this._copyInfo.matrix.getSizeOf()||!n.copyRange||[l.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_COL_WIDTH,l.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_VALUE,l.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMAT,l.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMULA].includes(n.pasteType))return{redos:[],undos:[]};let{unitId:r,subUnitId:a}=this._copyInfo;if(n.unitId!==r||a!==n.subUnitId){let o=this._sheetDataValidationModel.getRuleObjectMatrix(n.unitId,n.subUnitId).clone(),s=new t.ObjectMatrix,c=new Set,{ranges:[u,d],mapFunc:f}=(0,l.virtualizeDiscreteRanges)([n.copyRange,e]),p=(0,l.getRepeatRange)(u,d,!0),m=new Map;p.forEach(({startRange:e})=>{var i;(i=this._copyInfo)==null||i.matrix.forValue((i,o,l)=>{let u=t.Rectangle.getPositionRange({startRow:i,endRow:i,startColumn:o,endColumn:o},e),d=`${a}-${l}`,p=this._sheetDataValidationModel.getRuleById(r,a,l);!this._sheetDataValidationModel.getRuleById(n.unitId,n.subUnitId,d)&&p&&m.set(d,{...p,uid:d});let{row:h,col:g}=f(u.startRow,u.startColumn);c.add(d),s.setValue(h,g,d)})});let h=Array.from(c).map(e=>({id:e,ranges:(0,t.queryObjectMatrix)(s,t=>t===e)}));o.addRangeRules(h);let{redoMutations:g,undoMutations:_}=(0,i.getDataValidationDiffMutations)(n.unitId,n.subUnitId,o.diffWithAddition(this._sheetDataValidationModel.getRules(n.unitId,n.subUnitId),m.values()),this._injector,`patched`,!1);return{redos:g,undos:_}}else{let o=this._sheetDataValidationModel.getRuleObjectMatrix(r,a).clone(),s=new t.ObjectMatrix,c=new Set,{ranges:[u,d],mapFunc:f}=(0,l.virtualizeDiscreteRanges)([n.copyRange,e]);(0,l.getRepeatRange)(u,d,!0).forEach(({startRange:e})=>{var n;(n=this._copyInfo)==null||n.matrix.forValue((n,r,i)=>{let a=t.Rectangle.getPositionRange({startRow:n,endRow:n,startColumn:r,endColumn:r},e),{row:o,col:l}=f(a.startRow,a.startColumn);s.setValue(o,l,i),c.add(i)})});let p=Array.from(c).map(e=>({id:e,ranges:(0,t.queryObjectMatrix)(s,t=>t===e)}));o.addRangeRules(p);let{redoMutations:m,undoMutations:h}=(0,i.getDataValidationDiffMutations)(r,a,o.diff(this._sheetDataValidationModel.getRules(r,a)),this._injector,`patched`,!1);return{redos:m,undos:h}}}};q=k([O(0,l.ISheetClipboardService),O(1,(0,t.Inject)(i.SheetDataValidationModel)),O(2,(0,t.Inject)(t.Injector))],q);let J=class extends t.Disposable{constructor(e,t,n){super(),this._localeService=e,this._commandService=t,this._sheetPermissionCheckController=n,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===i.AddSheetDataValidationCommand.id){let{unitId:t,subUnitId:n,rule:{ranges:i}}=e.params;this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[r.WorkbookEditablePermission],rangeTypes:[r.RangeProtectionPermissionEditPoint],worksheetTypes:[r.WorksheetEditPermission,r.WorksheetSetCellStylePermission]},i,t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.setStyleErr`))}if(e.id===i.UpdateSheetDataValidationRangeCommand.id){let{unitId:t,subUnitId:n,ranges:i}=e.params;this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[r.WorkbookEditablePermission],rangeTypes:[r.RangeProtectionPermissionEditPoint],worksheetTypes:[r.WorksheetEditPermission,r.WorksheetSetCellStylePermission]},i,t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.setStyleErr`))}}))}};J=k([O(0,(0,t.Inject)(t.LocaleService)),O(1,t.ICommandService),O(2,(0,t.Inject)(r.SheetPermissionCheckController))],J);let ee=`sheet.menu.data-validation`;function te(e){return{id:ee,type:o.MenuItemType.SUBITEMS,icon:`DataValidationIcon`,tooltip:`dataValidation.title`,hidden$:(0,o.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:(0,l.getCurrentRangeDisable$)(e,{workbookTypes:[r.WorkbookEditablePermission],worksheetTypes:[r.WorksheetSetCellStylePermission,r.WorksheetEditPermission],rangeTypes:[r.RangeProtectionPermissionEditPoint]})}}function ne(e){return{id:R.id,title:`dataValidation.panel.title`,type:o.MenuItemType.BUTTON}}function re(e){return{id:U.id,title:`dataValidation.panel.add`,type:o.MenuItemType.BUTTON}}let ie={[o.RibbonDataGroup.RULES]:{[ee]:{order:0,menuItemFactory:te,[R.id]:{order:0,menuItemFactory:ne},[U.id]:{order:1,menuItemFactory:re}}}},ae={tr:{size:6,color:`#fe4b4b`}},Y=class extends t.RxDisposable{constructor(e,t,n,r,i,a,o,s,c,l,u){super(),this._commandService=e,this._menuManagerService=t,this._renderManagerService=n,this._univerInstanceService=r,this._autoHeightController=i,this._dropdownManagerService=a,this._sheetDataValidationModel=o,this._dataValidatorRegistryService=s,this._sheetInterceptorService=c,this._dataValidationCacheService=l,this._editorBridgeService=u,this._initMenu(),this._initDropdown(),this._initViewModelIntercept(),this._initAutoHeight()}_initMenu(){this._menuManagerService.mergeMenu(ie)}_initDropdown(){this._editorBridgeService&&this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{if(!e.visible){var t;((t=this._dropdownManagerService.activeDropdown)==null?void 0:t.trigger)===`editor-bridge`&&this._dropdownManagerService.hideDropdown();return}let n=this._editorBridgeService.getEditCellState();if(n){let{unitId:e,sheetId:t,row:r,column:i}=n,a=this._univerInstanceService.getUniverSheetInstance(e);if(!a)return;let o=this._sheetDataValidationModel.getRuleByLocation(e,t,r,i);if(!o)return;let s=this._dataValidatorRegistryService.getValidatorItem(o.type);if(!(s!=null&&s.dropdownType))return;let c=a.getActiveSheet();if(!c)return;let l=this._dropdownManagerService.activeDropdown,u=l==null?void 0:l.location;if(u&&u.unitId===e&&u.subUnitId===t&&u.row===r&&u.col===i)return;this._dropdownManagerService.showDropdown({location:{unitId:e,subUnitId:t,row:r,col:i,workbook:a,worksheet:c},trigger:`editor-bridge`,closeOnOutSide:!1})}}))}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(r.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Style,priority:r.InterceptCellContentPriority.DATA_VALIDATION,handler:(e,n,r)=>{var a,o,s,c,u;let{row:d,col:f,unitId:p,subUnitId:m,workbook:h,worksheet:g}=n,_=this._sheetDataValidationModel.getRuleIdByLocation(p,m,d,f);if(!_)return r(e);let v=this._sheetDataValidationModel.getRuleById(p,m,_);if(!v)return r(e);let y=(a=this._dataValidationCacheService.getValue(p,m,d,f))==null?t.DataValidationStatus.VALID:a,b=this._dataValidatorRegistryService.getValidatorItem(v.type),x=n.rawData,S,C={get value(){var e;return S===void 0&&(S=(e=(0,i.getCellValueOrigin)(x))==null?null:e),S}},w={get value(){var e;return`${(e=C.value)==null?``:e}`}};return(!e||e===n.rawData)&&(e={...n.rawData}),e.markers={...e==null?void 0:e.markers,...y===t.DataValidationStatus.INVALID?ae:null},e.customRender=[...(o=e==null?void 0:e.customRender)==null?[]:o,...b!=null&&b.canvasRender?[b.canvasRender]:[]],e.fontRenderExtension={...e==null?void 0:e.fontRenderExtension,isSkip:(e==null||(s=e.fontRenderExtension)==null?void 0:s.isSkip)||(b==null||(c=b.skipDefaultFontRender)==null?void 0:c.call(b,v,C.value,n))},e.interceptorStyle={...e==null?void 0:e.interceptorStyle,...b==null?void 0:b.getExtraStyle(v,w.value,{get style(){let t=h.getStyles();return(typeof(e==null?void 0:e.s)==`string`?t.get(e==null?void 0:e.s):e==null?void 0:e.s)||{}}},d,f)},e.interceptorAutoHeight=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(p))==null||(t=t.with(l.SheetSkeletonManagerService).getSkeletonParam(m))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(d,f),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?d:n,(r=s==null?void 0:s.startColumn)==null?f:r),unitId:p,subUnitId:m,row:d,col:f,workbook:h,worksheet:g};return b==null||(i=b.canvasRender)==null||(a=i.calcCellAutoHeight)==null?void 0:a.call(i,c)},e.interceptorAutoWidth=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(p))==null||(t=t.with(l.SheetSkeletonManagerService).getSkeletonParam(m))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(d,f),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?d:n,(r=s==null?void 0:s.startColumn)==null?f:r),unitId:p,subUnitId:m,row:d,col:f,workbook:h,worksheet:g};return b==null||(i=b.canvasRender)==null||(a=i.calcCellAutoWidth)==null?void 0:a.call(i,c)},e.coverable=((u=e==null?void 0:e.coverable)==null?!0:u)&&!(v.type===t.DataValidationType.LIST||v.type===t.DataValidationType.LIST_MULTIPLE),r(e)}}))}_initAutoHeight(){this._sheetDataValidationModel.ruleChange$.pipe((0,s.filter)(e=>e.source===`command`),(0,s.bufferTime)(100)).subscribe(e=>{if(e.length===0)return;let n=[];e.forEach(e=>{if(e.rule.type===t.DataValidationType.LIST_MULTIPLE||e.rule.type===t.DataValidationType.LIST){var r;(r=e.rule)!=null&&r.ranges&&n.push(...e.rule.ranges)}}),n.length&&(0,t.sequenceExecute)(this._autoHeightController.getUndoRedoParamsOfAutoHeight(n).redos,this._commandService)})}};Y=k([O(0,t.ICommandService),O(1,o.IMenuManagerService),O(2,n.IRenderManagerService),O(3,t.IUniverInstanceService),O(4,(0,t.Inject)(l.AutoHeightController)),O(5,(0,t.Inject)(I)),O(6,(0,t.Inject)(i.SheetDataValidationModel)),O(7,(0,t.Inject)(a.DataValidatorRegistryService)),O(8,(0,t.Inject)(r.SheetInterceptorService)),O(9,(0,t.Inject)(i.DataValidationCacheService)),O(10,(0,t.Optional)(l.IEditorBridgeService))],Y);let oe=class extends t.RxDisposable{constructor(e,t,n,r,i,a,o){super(),this._commandService=e,this._renderManagerService=t,this._autoHeightController=n,this._dataValidatorRegistryService=r,this._sheetInterceptorService=i,this._sheetDataValidationModel=a,this._dataValidationCacheService=o,this._initViewModelIntercept(),this._initAutoHeight()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(r.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Style,priority:r.InterceptCellContentPriority.DATA_VALIDATION,handler:(e,n,r)=>{var a,o,s,c,u;let{row:d,col:f,unitId:p,subUnitId:m,workbook:h,worksheet:g}=n,_=this._sheetDataValidationModel.getRuleIdByLocation(p,m,d,f);if(!_)return r(e);let v=this._sheetDataValidationModel.getRuleById(p,m,_);if(!v)return r(e);let y=(a=this._dataValidationCacheService.getValue(p,m,d,f))==null?t.DataValidationStatus.VALID:a,b=this._dataValidatorRegistryService.getValidatorItem(v.type),x=(0,i.getCellValueOrigin)(g.getCellRaw(d,f)),S=`${x==null?``:x}`;return(!e||e===n.rawData)&&(e={...n.rawData}),e.markers={...e==null?void 0:e.markers,...y===t.DataValidationStatus.INVALID?ae:null},e.customRender=[...(o=e==null?void 0:e.customRender)==null?[]:o,...b!=null&&b.canvasRender?[b.canvasRender]:[]],e.fontRenderExtension={...e==null?void 0:e.fontRenderExtension,isSkip:(e==null||(s=e.fontRenderExtension)==null?void 0:s.isSkip)||(b==null||(c=b.skipDefaultFontRender)==null?void 0:c.call(b,v,x,n))},e.interceptorStyle={...e==null?void 0:e.interceptorStyle,...b==null?void 0:b.getExtraStyle(v,S,{get style(){let t=h.getStyles();return(typeof(e==null?void 0:e.s)==`string`?t.get(e==null?void 0:e.s):e==null?void 0:e.s)||{}}},d,f)},e.interceptorAutoHeight=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(p))==null||(t=t.with(l.SheetSkeletonManagerService).getSkeletonParam(m))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(d,f),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?d:n,(r=s==null?void 0:s.startColumn)==null?f:r),unitId:p,subUnitId:m,row:d,col:f,workbook:h,worksheet:g};return b==null||(i=b.canvasRender)==null||(a=i.calcCellAutoHeight)==null?void 0:a.call(i,c)},e.interceptorAutoWidth=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(p))==null||(t=t.with(l.SheetSkeletonManagerService).getSkeletonParam(m))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(d,f),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?d:n,(r=s==null?void 0:s.startColumn)==null?f:r),unitId:p,subUnitId:m,row:d,col:f,workbook:h,worksheet:g};return b==null||(i=b.canvasRender)==null||(a=i.calcCellAutoWidth)==null?void 0:a.call(i,c)},e.coverable=((u=e==null?void 0:e.coverable)==null?!0:u)&&!(v.type===t.DataValidationType.LIST||v.type===t.DataValidationType.LIST_MULTIPLE),r(e)}}))}_initAutoHeight(){this._sheetDataValidationModel.ruleChange$.pipe((0,s.filter)(e=>e.source===`command`),(0,s.bufferTime)(16)).subscribe(e=>{let n=[];e.forEach(e=>{if(e.rule.type===t.DataValidationType.LIST_MULTIPLE||e.rule.type===t.DataValidationType.LIST){var r;(r=e.rule)!=null&&r.ranges&&n.push(...e.rule.ranges)}}),n.length&&(0,t.sequenceExecute)(this._autoHeightController.getUndoRedoParamsOfAutoHeight(n).redos,this._commandService)})}};oe=k([O(0,t.ICommandService),O(1,n.IRenderManagerService),O(2,(0,t.Inject)(l.AutoHeightController)),O(3,(0,t.Inject)(a.DataValidatorRegistryService)),O(4,(0,t.Inject)(r.SheetInterceptorService)),O(5,(0,t.Inject)(i.SheetDataValidationModel)),O(6,(0,t.Inject)(i.DataValidationCacheService))],oe);let se=class extends t.Disposable{constructor(e,t,n){super(),this._context=e,this._sheetDataValidationModel=t,this._sheetSkeletonManagerService=n,this._initSkeletonChange()}_initSkeletonChange(){this.disposeWithMe(this._sheetDataValidationModel.validStatusChange$.pipe((0,t.bufferDebounceTime)(16)).subscribe(e=>{var t;if(!e.length)return;let n=new Set;e.forEach(e=>{n.add(e.subUnitId)}),n.forEach(e=>{var t;(t=this._sheetSkeletonManagerService.getSkeletonParam(e))==null||t.skeleton.makeDirty(!0)}),(t=this._context.mainComponent)==null||t.makeForceDirty()}))}};se=k([O(1,(0,t.Inject)(i.SheetDataValidationModel)),O(2,(0,t.Inject)(l.SheetSkeletonManagerService))],se);function X({ref:e,...t}){let{icon:n,id:r,className:i,extend:a,...o}=t,s=`univerjs-icon univerjs-icon-${r} ${i||``}`.trim(),c=(0,d.useRef)(`_${de()}`);return ce(n,`${r}`,{defIds:n.defIds,idSuffix:c.current},{ref:e,className:s,...o},a)}function ce(e,t,n,r,i){return(0,d.createElement)(e.tag,{key:t,...le(e,n,i),...r},(ue(e,n).children||[]).map((r,a)=>ce(r,`${t}-${e.tag}-${a}`,n,void 0,i)))}function le(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),e.tag===`mask`&&r.id&&(r.id+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{e===`mask`&&typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});let{defIds:i}=t;return!i||i.length===0?r:(e.tag===`use`&&r[`xlink:href`]&&(r[`xlink:href`]+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))}),r)}function ue(e,t){var n;let{defIds:r}=t;return!r||r.length===0?e:e.tag===`defs`&&(n=e.children)!=null&&n.length?{...e,children:e.children.map(e=>typeof e.attrs.id==`string`&&r&&r.includes(e.attrs.id)?{...e,attrs:{...e.attrs,id:e.attrs.id+t.idSuffix}}:e)}:e}function de(){return Math.random().toString(36).substring(2,8)}X.displayName=`UniverIcon`;let fe={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 17 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M1.4917 3.07803C1.4917 2.19437 2.20804 1.47803 3.0917 1.47803H5.6917C6.57536 1.47803 7.2917 2.19437 7.2917 3.07803V5.67803C7.2917 6.56168 6.57535 7.27803 5.6917 7.27803H3.0917C2.20804 7.27803 1.4917 6.56168 1.4917 5.67803V3.07803ZM3.0917 2.67803C2.87078 2.67803 2.6917 2.85711 2.6917 3.07803V5.67803C2.6917 5.89894 2.87079 6.07803 3.0917 6.07803H5.6917C5.91261 6.07803 6.0917 5.89894 6.0917 5.67803V3.07803C6.0917 2.85711 5.91261 2.67803 5.6917 2.67803H3.0917Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M14.6175 2.45279C14.8518 2.68711 14.8518 3.06701 14.6175 3.30132L11.6151 6.30365C11.3957 6.52307 11.0451 6.53897 10.8067 6.34031L8.80915 4.67566C8.55458 4.46352 8.52019 4.08518 8.73233 3.83062C8.94447 3.57605 9.32281 3.54166 9.57737 3.7538L11.154 5.06767L13.769 2.45278C14.0033 2.21847 14.3832 2.21848 14.6175 2.45279Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M14.1175 9.19746C14.3518 9.43178 14.3518 9.81168 14.1175 10.046L12.5418 11.6217L14.1175 13.1975C14.3518 13.4318 14.3518 13.8117 14.1175 14.046C13.8832 14.2803 13.5033 14.2803 13.269 14.046L11.6933 12.4703L10.1175 14.046C9.88321 14.2803 9.50331 14.2803 9.269 14.046C9.03468 13.8117 9.03468 13.4318 9.269 13.1975L10.8447 11.6217L9.269 10.046C9.03468 9.81168 9.03468 9.43178 9.269 9.19746C9.50331 8.96315 9.88321 8.96315 10.1175 9.19746L11.6933 10.7732L13.269 9.19746C13.5033 8.96315 13.8832 8.96315 14.1175 9.19746Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M3.0917 8.72168C2.20804 8.72168 1.4917 9.43802 1.4917 10.3217V12.9217C1.4917 13.8053 2.20804 14.5217 3.0917 14.5217H5.6917C6.57535 14.5217 7.2917 13.8053 7.2917 12.9217V10.3217C7.2917 9.43802 6.57536 8.72168 5.6917 8.72168H3.0917ZM2.6917 10.3217C2.6917 10.1008 2.87078 9.92168 3.0917 9.92168H5.6917C5.91261 9.92168 6.0917 10.1008 6.0917 10.3217V12.9217C6.0917 13.1426 5.91261 13.3217 5.6917 13.3217H3.0917C2.87079 13.3217 2.6917 13.1426 2.6917 12.9217V10.3217Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},pe=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(X,Object.assign({},e,{id:`data-validation-icon`,ref:t,icon:fe}))});pe.displayName=`DataValidationIcon`;let me={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M5.3313 1.4667C5.3313 1.13533 5.59993 0.866699 5.9313 0.866699H10.069C10.4004 0.866699 10.669 1.13533 10.669 1.4667C10.669 1.79807 10.4004 2.0667 10.069 2.0667H5.9313C5.59993 2.0667 5.3313 1.79807 5.3313 1.4667Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.09985 3.64443C1.09985 3.31306 1.36848 3.04443 1.69985 3.04443H14.2999C14.6312 3.04443 14.8999 3.31306 14.8999 3.64443C14.8999 3.9758 14.6312 4.24443 14.2999 4.24443H1.69985C1.36848 4.24443 1.09985 3.9758 1.09985 3.64443Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M6.12398 8.30171C6.35829 8.0674 6.73819 8.0674 6.97251 8.30171L8.00007 9.32928L9.02764 8.30171C9.26195 8.0674 9.64185 8.0674 9.87617 8.30171C10.1105 8.53603 10.1105 8.91593 9.87617 9.15024L8.8486 10.1778L9.87617 11.2054C10.1105 11.4397 10.1105 11.8196 9.87617 12.0539C9.64185 12.2882 9.26195 12.2882 9.02764 12.0539L8.00007 11.0263L6.97251 12.0539C6.73819 12.2882 6.35829 12.2882 6.12398 12.0539C5.88966 11.8196 5.88966 11.4397 6.12398 11.2054L7.15154 10.1778L6.12398 9.15024C5.88966 8.91593 5.88966 8.53603 6.12398 8.30171Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M4.75332 5.22217C3.86966 5.22217 3.15332 5.93851 3.15332 6.82217V12.5331C3.15332 13.9691 4.31738 15.1332 5.75332 15.1332H10.2465C11.6825 15.1332 12.8465 13.9691 12.8465 12.5331V6.82217C12.8465 5.93851 12.1302 5.22217 11.2465 5.22217H4.75332ZM4.35332 6.82217C4.35332 6.60125 4.53241 6.42217 4.75332 6.42217H11.2465C11.4674 6.42217 11.6465 6.60125 11.6465 6.82217V12.5331C11.6465 13.3063 11.0197 13.9332 10.2465 13.9332H5.75332C4.98012 13.9332 4.35332 13.3063 4.35332 12.5331V6.82217Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},he=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(X,Object.assign({},e,{id:`delete-icon`,ref:t,icon:me}))});he.displayName=`DeleteIcon`;let ge={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M8.6 1.99991C8.60001 1.66854 8.33138 1.39991 8.00001 1.3999C7.66864 1.3999 7.40001 1.66853 7.4 1.9999L7.39996 7.3999H1.9999C1.66853 7.3999 1.3999 7.66853 1.3999 7.9999C1.3999 8.33127 1.66853 8.5999 1.9999 8.5999H7.39995L7.3999 13.9999C7.3999 14.3313 7.66853 14.5999 7.9999 14.5999C8.33127 14.5999 8.5999 14.3313 8.5999 13.9999L8.59995 8.5999H13.9999C14.3313 8.5999 14.5999 8.33127 14.5999 7.9999C14.5999 7.66853 14.3313 7.3999 13.9999 7.3999H8.59996L8.6 1.99991Z`}}]},_e=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(X,Object.assign({},e,{id:`increase-icon`,ref:t,icon:ge}))});_e.displayName=`IncreaseIcon`;let ve={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M11.3536 6.14645C11.5488 6.34171 11.5488 6.65829 11.3536 6.85355L8.35355 9.85355C8.15829 10.0488 7.84171 10.0488 7.64645 9.85355L4.64645 6.85355C4.45118 6.65829 4.45118 6.34171 4.64645 6.14645C4.84171 5.95118 5.15829 5.95118 5.35355 6.14645L8 8.79289L10.6464 6.14645C10.8417 5.95118 11.1583 5.95118 11.3536 6.14645Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},ye=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(X,Object.assign({},e,{id:`more-down-icon`,ref:t,icon:ve}))});ye.displayName=`MoreDownIcon`;let be={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M4.64645 9.85355C4.45118 9.65829 4.45118 9.34171 4.64645 9.14645L7.64645 6.14645C7.84171 5.95118 8.15829 5.95118 8.35355 6.14645L11.3536 9.14645C11.5488 9.34171 11.5488 9.65829 11.3536 9.85355C11.1583 10.0488 10.8417 10.0488 10.6464 9.85355L8 7.20711L5.35355 9.85355C5.15829 10.0488 4.84171 10.0488 4.64645 9.85355Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},xe=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(X,Object.assign({},e,{id:`more-up-icon`,ref:t,icon:be}))});xe.displayName=`MoreUpIcon`;let Se={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M6 5C6.55228 5 7 4.55228 7 4C7 3.44772 6.55228 3 6 3C5.44772 3 5 3.44772 5 4C5 4.55228 5.44772 5 6 5Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M6 9C6.55228 9 7 8.55229 7 8C7 7.44772 6.55228 7 6 7C5.44772 7 5 7.44772 5 8C5 8.55229 5.44772 9 6 9Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M7 12C7 12.5523 6.55228 13 6 13C5.44772 13 5 12.5523 5 12C5 11.4477 5.44772 11 6 11C6.55228 11 7 11.4477 7 12Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M10 5C10.5523 5 11 4.55228 11 4C11 3.44772 10.5523 3 10 3C9.44771 3 9 3.44772 9 4C9 4.55228 9.44771 5 10 5Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M11 8C11 8.55229 10.5523 9 10 9C9.44771 9 9 8.55229 9 8C9 7.44772 9.44771 7 10 7C10.5523 7 11 7.44772 11 8Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M10 13C10.5523 13 11 12.5523 11 12C11 11.4477 10.5523 11 10 11C9.44771 11 9 11.4477 9 12C9 12.5523 9.44771 13 10 13Z`}}]},Ce=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(X,Object.assign({},e,{id:`sequence-icon`,ref:t,icon:Se}))});Ce.displayName=`SequenceIcon`;function we(e){var n;let r=(0,o.useDependency)(t.LocaleService),i=(0,o.useDependency)(o.ComponentManager),{value:a,onChange:s,extraComponent:c}=e,[l,f]=(0,d.useState)(!1),p=c?i.get(c):null;return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsxs)(`div`,{className:`
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/engine-render`),require(`@univerjs/sheets`),require(`@univerjs/sheets-data-validation`),require(`@univerjs/data-validation`),require(`@univerjs/ui`),require(`rxjs`),require(`@univerjs/sheets-numfmt`),require(`@univerjs/sheets-ui`),require(`@univerjs/design`),require(`react`),require(`@univerjs/engine-formula`),require(`@univerjs/sheets-formula-ui`),require(`react/jsx-runtime`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/engine-render`,`@univerjs/sheets`,`@univerjs/sheets-data-validation`,`@univerjs/data-validation`,`@univerjs/ui`,`rxjs`,`@univerjs/sheets-numfmt`,`@univerjs/sheets-ui`,`@univerjs/design`,`react`,`@univerjs/engine-formula`,`@univerjs/sheets-formula-ui`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsDataValidationUi={},e.UniverCore,e.UniverEngineRender,e.UniverSheets,e.UniverSheetsDataValidation,e.UniverDataValidation,e.UniverUi,e.rxjs,e.UniverSheetsNumfmt,e.UniverSheetsUi,e.UniverDesign,e.React,e.UniverEngineFormula,e.UniverSheetsFormulaUi,e.React))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var h=Object.create,g=Object.defineProperty,_=Object.getOwnPropertyDescriptor,v=Object.getOwnPropertyNames,y=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty,x=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=v(t),a=0,o=i.length,s;a<o;a++)s=i[a],!b.call(e,s)&&s!==n&&g(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=_(t,s))||r.enumerable});return e};d=((e,t,n)=>(n=e==null?{}:h(y(e)),x(t||!e||!e.__esModule?g(n,`default`,{value:e,enumerable:!0}):n,e)))(d);var S=`@univerjs/sheets-data-validation-ui`,C=`0.18.0`;function w(e){"@babel/helpers - typeof";return w=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},w(e)}function T(e,t){if(w(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(w(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function E(e){var t=T(e,`string`);return w(t)==`symbol`?t:t+``}function D(e,t,n){return(t=E(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function O(e,t){return function(n,r){t(n,r,e)}}function k(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let A=class extends t.Disposable{get activeRule(){return this._activeRule}get isOpen(){return this._open$.getValue()}constructor(e,n){super(),this._univerInstanceService=e,this._sidebarService=n,D(this,`_open$`,new s.BehaviorSubject(!1)),D(this,`open$`,this._open$.pipe((0,s.distinctUntilChanged)())),D(this,`_activeRule`,void 0),D(this,`_activeRule$`,new s.BehaviorSubject(void 0)),D(this,`activeRule$`,this._activeRule$.asObservable()),D(this,`_closeDisposable`,null),D(this,`_focusFormulaEditorActiveRuleSubUnitId`,null),this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe((0,s.filter)(e=>!e)).subscribe(()=>{this.close()})),this.disposeWithMe(this._sidebarService.sidebarOptions$.subscribe(e=>{e.id===`DataValidationPanel`&&(e.visible||setTimeout(()=>{this._sidebarService.sidebarOptions$.next({visible:!1})}))}))}dispose(){var e;super.dispose(),this._open$.next(!1),this._open$.complete(),this._activeRule$.complete(),(e=this._closeDisposable)==null||e.dispose()}open(){this._open$.next(!0)}close(){var e;this._open$.next(!1),(e=this._closeDisposable)==null||e.dispose()}setCloseDisposable(e){this._closeDisposable=(0,t.toDisposable)(()=>{e.dispose(),this._closeDisposable=null})}setActiveRule(e){this._activeRule=e,this._activeRule$.next(e)}setFocusFormulaEditorActiveRuleSubUnitId(e){this._focusFormulaEditorActiveRuleSubUnitId=e}getFocusFormulaEditorActiveRuleSubUnitId(){return this._focusFormulaEditorActiveRuleSubUnitId}};A=k([O(0,t.IUniverInstanceService),O(1,o.ISidebarService)],A);let j=`sheets-data-validation-ui.config`;Symbol(j);let M={},N=class extends t.Disposable{constructor(e,t,n,r,i,a){super(),this._sheetInterceptorService=e,this._dataValidationModel=t,this._dataValidatorRegistryService=n,this._dialogService=r,this._localeService=i,this._sheetsDataValidationValidatorService=a,this._initEditorBridgeInterceptor()}_initEditorBridgeInterceptor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(r.VALIDATE_CELL,{handler:async(e,n,r)=>{let i=await e,{row:a,col:o,unitId:s,subUnitId:c}=n,l=this._dataValidationModel.getRuleIdByLocation(s,c,a,o),f=l?this._dataValidationModel.getRuleById(s,c,l):void 0;if(i===!1)return r(Promise.resolve(!1));if(!f||f.errorStyle!==t.DataValidationErrorStyle.STOP)return r(Promise.resolve(!0));let p=this._dataValidatorRegistryService.getValidatorItem(f.type);return!p||await this._sheetsDataValidationValidatorService.validatorCell(s,c,a,o)===t.DataValidationStatus.VALID?r(Promise.resolve(!0)):(this._dialogService.open({width:368,title:{title:this._localeService.t(`dataValidation.alert.title`)},id:`reject-input-dialog`,children:{title:p.getRuleFinalError(f,{row:a,col:o,unitId:s,subUnitId:c})},footer:{title:(0,d.createElement)(u.Button,{variant:`primary`,onClick:()=>this._dialogService.close(`reject-input-dialog`)},this._localeService.t(`dataValidation.alert.ok`))},onClose:()=>{this._dialogService.close(`reject-input-dialog`)}}),r(Promise.resolve(!1)))}}))}showReject(e){this._dialogService.open({width:368,title:{title:this._localeService.t(`dataValidation.alert.title`)},id:`reject-input-dialog`,children:{title:e},footer:{title:(0,d.createElement)(u.Button,{variant:`primary`,onClick:()=>this._dialogService.close(`reject-input-dialog`)},this._localeService.t(`dataValidation.alert.ok`))},onClose:()=>{this._dialogService.close(`reject-input-dialog`)}})}};N=k([O(0,(0,t.Inject)(r.SheetInterceptorService)),O(1,(0,t.Inject)(i.SheetDataValidationModel)),O(2,(0,t.Inject)(a.DataValidatorRegistryService)),O(3,o.IDialogService),O(4,(0,t.Inject)(t.LocaleService)),O(5,(0,t.Inject)(i.SheetsDataValidationValidatorService))],N);let P=e=>{if(e==null||typeof e==`boolean`)return;if(e===``)return(0,t.dayjs)();if(typeof e==`number`||!Number.isNaN(+e))return(0,t.dayjs)(t.numfmt.format(`yyyy-MM-dd HH:mm:ss`,Number(e)));let n=(0,t.dayjs)(e);if(n.isValid())return n};function F(e,t){if(e===(0,c.getPatternType)(t))return t;switch(e){case`datetime`:return`yyyy-MM-dd hh:mm:ss`;case`date`:return`yyyy-MM-dd`;case`time`:return`HH:mm:ss`}}let I=class extends t.Disposable{get activeDropdown(){return this._activeDropdown}constructor(e,t,n,r,i,a,o,c,l,u,d){super(),this._univerInstanceService=e,this._dataValidatorRegistryService=t,this._zenZoneService=n,this._dataValidationModel=r,this._sheetsSelectionsService=i,this._cellDropdownManagerService=a,this._sheetDataValidationModel=o,this._commandService=c,this._editorBridgeService=l,this._injector=u,this._configService=d,D(this,`_activeDropdown`,void 0),D(this,`_activeDropdown$`,new s.Subject),D(this,`_currentPopup`,null),D(this,`activeDropdown$`,this._activeDropdown$.asObservable()),D(this,`_zenVisible`,!1),this._init(),this._initSelectionChange(),this.disposeWithMe(()=>{this._activeDropdown$.complete()})}_init(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{this._zenVisible=e,e&&this.hideDropdown()}))}_getDropdownByCell(e,n,r,i){let a=e?this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET);if(!a)return;let o=n?a.getSheetBySheetId(n):a.getActiveSheet();if(!o)return;let s=this._dataValidationModel.getRuleByLocation(a.getUnitId(),o.getSheetId(),r,i);if(!s)return;let c=this._dataValidatorRegistryService.getValidatorItem(s.type);return c==null?void 0:c.dropdownType}_initSelectionChange(){this.disposeWithMe(this._sheetsSelectionsService.selectionMoveEnd$.subscribe(e=>{e&&e.every(e=>!(e.primary&&this._getDropdownByCell(e.primary.unitId,e.primary.sheetId,e.primary.actualRow,e.primary.actualColumn)))&&this.hideDropdown()}))}showDropdown(e){let{location:s}=e,{row:c,col:u,unitId:d,subUnitId:f,workbook:p,worksheet:m}=s;if(this._currentPopup&&this._currentPopup.dispose(),this._zenVisible)return;this._activeDropdown=e,this._activeDropdown$.next(this._activeDropdown);let h=this._sheetDataValidationModel.getRuleByLocation(d,f,c,u);if(!h)return;let g=this._dataValidatorRegistryService.getValidatorItem(h.type);if(!(g!=null&&g.dropdownType))return;let _,v=async(e,i)=>{var a,s,_;if(!e)return!0;let v=e,y=m.getCell(c,u),b=v.format(i===`date`?`YYYY-MM-DD 00:00:00`:`YYYY-MM-DD HH:mm:ss`),x=(a=t.numfmt.parseDate(b))==null?void 0:a.v,S=i===`time`?x%1:x,C=p.getStyles().getStyleByCell(y),w=(s=C==null||(_=C.n)==null?void 0:_.pattern)==null?``:s;return h.errorStyle!==t.DataValidationErrorStyle.STOP||await g.validator({value:S,unitId:d,subUnitId:f,row:c,column:u,worksheet:m,workbook:p,interceptValue:b.replace(`Z`,``).replace(`T`,` `),t:t.CellValueType.NUMBER},h)?(await this._commandService.executeCommand(r.SetRangeValuesCommand.id,{unitId:d,subUnitId:f,range:{startColumn:u,endColumn:u,startRow:c,endRow:c},value:{v:S,t:2,p:null,f:null,si:null,s:{n:{pattern:F(i,w)}}}}),await this._commandService.executeCommand(l.SetCellEditVisibleOperation.id,{visible:!1,eventType:n.DeviceInputEventType.Keyboard,unitId:d,keycode:o.KeyCode.ESC}),!0):(this._injector.has(N)&&this._injector.get(N).showReject(g.getRuleFinalError(h,{row:c,col:u,unitId:d,subUnitId:f})),!1)},y;switch(g.dropdownType){case a.DataValidatorDropdownType.DATE:{var b;let e=P((0,i.getCellValueOrigin)(m.getCellRaw(c,u))),t=!!((b=h.bizInfo)!=null&&b.showTime);y={location:s,type:`datepicker`,props:{showTime:t,onChange:e=>v(e,t?`datetime`:`date`),defaultValue:e,patternType:`date`}};break}case a.DataValidatorDropdownType.TIME:y={location:s,type:`datepicker`,props:{onChange:e=>v(e,`time`),defaultValue:P((0,i.getCellValueOrigin)(m.getCellRaw(c,u))),patternType:`time`}};break;case a.DataValidatorDropdownType.DATETIME:y={location:s,type:`datepicker`,props:{onChange:e=>v(e,`datetime`),defaultValue:P((0,i.getCellValueOrigin)(m.getCellRaw(c,u))),patternType:`datetime`}};break;case a.DataValidatorDropdownType.LIST:case a.DataValidatorDropdownType.MULTIPLE_LIST:{var x,S,C,w;let e=g.dropdownType===a.DataValidatorDropdownType.MULTIPLE_LIST,p=async t=>{let a=(0,i.serializeListOptions)(t),s={unitId:d,subUnitId:f,range:{startColumn:u,endColumn:u,startRow:c,endRow:c},value:{v:a,p:null,f:null,si:null}};return this._commandService.executeCommand(r.SetRangeValuesCommand.id,s),this._editorBridgeService.isVisible().visible&&await this._commandService.executeCommand(l.SetCellEditVisibleOperation.id,{visible:!1,eventType:n.DeviceInputEventType.Keyboard,unitId:d,keycode:o.KeyCode.ESC}),!e},v=(h==null?void 0:h.renderMode)===t.DataValidationRenderMode.CUSTOM||(h==null?void 0:h.renderMode)===void 0,b=g.getListWithColor(h,d,f),T=(0,i.getDataValidationCellValue)(m.getCellRaw(c,u));y={location:s,type:`list`,props:{onChange:e=>p(e),options:b.map(e=>({label:e.label,value:e.label,color:v||e.color?e.color||`#ECECEC`:`transparent`})),onEdit:()=>{this._commandService.executeCommand(R.id,{ruleId:h.uid}),_==null||_.dispose()},defaultValue:T,multiple:e,showEdit:(x=(S=this._configService.getConfig(`sheets-data-validation-ui.config`))==null?void 0:S.showEditOnDropdown)==null?!0:x,showSearch:(C=(w=this._configService.getConfig(`sheets-data-validation-ui.config`))==null?void 0:w.showSearchOnDropdown)==null?!0:C}};break}case a.DataValidatorDropdownType.CASCADE:var T;y={type:`cascader`,props:{onChange:e=>{let t={unitId:d,subUnitId:f,range:{startColumn:u,endColumn:u,startRow:c,endRow:c},value:{v:e.join(`/`),p:null,f:null,si:null}};return this._commandService.syncExecuteCommand(r.SetRangeValuesCommand.id,t),this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(l.SetCellEditVisibleOperation.id,{visible:!1,eventType:n.DeviceInputEventType.Keyboard,unitId:d,keycode:o.KeyCode.ESC}),!0},defaultValue:(0,i.getDataValidationCellValue)(m.getCellRaw(c,u)).split(`/`),options:JSON.parse((T=h.formula1)==null?`[]`:T)},location:s};break;case a.DataValidatorDropdownType.COLOR:y={type:`color`,props:{onChange:e=>{let t={unitId:d,subUnitId:f,range:{startColumn:u,endColumn:u,startRow:c,endRow:c},value:{v:e,p:null,f:null,si:null}};return this._commandService.syncExecuteCommand(r.SetRangeValuesCommand.id,t),this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(l.SetCellEditVisibleOperation.id,{visible:!1,eventType:n.DeviceInputEventType.Keyboard,unitId:d,keycode:o.KeyCode.ESC}),!0},defaultValue:(0,i.getDataValidationCellValue)(m.getCellRaw(c,u))},location:s};break;default:throw Error(`[DataValidationDropdownManagerService]: unknown type!`)}if(_=this._cellDropdownManagerService.showDropdown({...y,onHide:()=>{this._activeDropdown=null,this._activeDropdown$.next(null)}}),!_)throw Error(`[DataValidationDropdownManagerService]: cannot show dropdown!`);let E=new t.DisposableCollection;E.add(_),E.add({dispose:()=>{var e,t;(e=this._activeDropdown)==null||(t=e.onHide)==null||t.call(e)}}),this._currentPopup=E}hideDropdown(){this._activeDropdown&&(this._currentPopup&&this._currentPopup.dispose(),this._currentPopup=null,this._activeDropdown=null,this._activeDropdown$.next(null))}showDataValidationDropdown(e,n,r,i,a){let o=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!o)return;let s=o.getSheetBySheetId(n);if(!s)return;let c=this._dataValidationModel.getRuleByLocation(o.getUnitId(),s.getSheetId(),r,i);if(!c)return;let l=this._dataValidatorRegistryService.getValidatorItem(c.type);if(!l||!l.dropdownType){this.hideDropdown();return}this.showDropdown({location:{workbook:o,worksheet:s,row:r,col:i,unitId:e,subUnitId:n},onHide:a})}};I=k([O(0,t.IUniverInstanceService),O(1,(0,t.Inject)(a.DataValidatorRegistryService)),O(2,o.IZenZoneService),O(3,(0,t.Inject)(i.SheetDataValidationModel)),O(4,(0,t.Inject)(r.SheetsSelectionsService)),O(5,(0,t.Inject)(l.ISheetCellDropdownManagerService)),O(6,(0,t.Inject)(i.SheetDataValidationModel)),O(7,t.ICommandService),O(8,l.IEditorBridgeService),O(9,(0,t.Inject)(t.Injector)),O(10,t.IConfigService)],I);let L=`DataValidationPanel`,R={id:`data-validation.operation.open-validation-panel`,type:t.CommandType.OPERATION,handler(e,n){if(!n)return!1;let{ruleId:i,isAdd:s}=n,c=e.get(A),l=e.get(a.DataValidationModel),u=e.get(t.IUniverInstanceService),d=e.get(o.ISidebarService),f=(0,r.getSheetCommandTarget)(u);if(!f)return!1;let{unitId:p,subUnitId:m}=f,h=i?l.getRuleById(p,m,i):void 0;c.open(),c.setActiveRule(h&&{unitId:p,subUnitId:m,rule:h});let g=d.open({id:L,header:{title:s?`dataValidation.panel.addTitle`:`dataValidation.panel.title`},children:{label:L},width:312,onClose:()=>c.close()});return c.setCloseDisposable(g),!0}},z={id:`data-validation.operation.close-validation-panel`,type:t.CommandType.OPERATION,handler(e){return e.get(A).close(),!0}},B={id:`data-validation.operation.toggle-validation-panel`,type:t.CommandType.OPERATION,handler(e){let n=e.get(t.ICommandService),r=e.get(A);return r.open(),r.isOpen?n.executeCommand(z.id):n.executeCommand(R.id),!0}},V={type:t.CommandType.OPERATION,id:`sheet.operation.show-data-validation-dropdown`,handler(e,t){if(!t)return!1;let n=e.get(I),{unitId:r,subUnitId:i,row:a,column:o}=t,s=n.activeDropdown,c=s==null?void 0:s.location;return c&&c.unitId===r&&c.subUnitId===i&&c.row===a&&c.col===o||n.showDataValidationDropdown(r,i,a,o),!0}},H={type:t.CommandType.OPERATION,id:`sheet.operation.hide-data-validation-dropdown`,handler(e,t){return t?(e.get(I).hideDropdown(),!0):!1}},U={type:t.CommandType.COMMAND,id:`data-validation.command.addRuleAndOpen`,handler(e){let n=(0,r.getSheetCommandTarget)(e.get(t.IUniverInstanceService));if(!n)return!1;let{workbook:a,worksheet:o}=n,s=(0,i.createDefaultNewRule)(e),c=e.get(t.ICommandService),l={rule:s,unitId:a.getUnitId(),subUnitId:o.getSheetId()};return c.syncExecuteCommand(i.AddSheetDataValidationCommand.id,l)?(c.syncExecuteCommand(R.id,{ruleId:s.uid,isAdd:!0}),!0):!1}},W=`SHEET_DATA_VALIDATION_ALERT`,G=class extends t.Disposable{constructor(e,t,n,r,i,a){super(),this._hoverManagerService=e,this._cellAlertManagerService=t,this._univerInstanceService=n,this._localeService=r,this._zenZoneService=i,this._dataValidationModel=a,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe((0,s.debounceTime)(100)).subscribe(e=>{if(e){let r=this._univerInstanceService.getUnit(e.location.unitId,t.UniverInstanceType.UNIVER_SHEET),i=r.getSheetBySheetId(e.location.subUnitId);if(!i)return;let a=this._dataValidationModel.getRuleByLocation(e.location.unitId,e.location.subUnitId,e.location.row,e.location.col);if(!a){this._cellAlertManagerService.removeAlert(W);return}if(this._dataValidationModel.validator(a,{...e.location,workbook:r,worksheet:i})===t.DataValidationStatus.INVALID){var n;let t=this._cellAlertManagerService.currentAlert.get(W),r=t==null||(n=t.alert)==null?void 0:n.location;if(r&&r.row===e.location.row&&r.col===e.location.col&&r.subUnitId===e.location.subUnitId&&r.unitId===e.location.unitId){this._cellAlertManagerService.removeAlert(W);return}let i=this._dataValidationModel.getValidator(a.type);if(!i){this._cellAlertManagerService.removeAlert(W);return}this._cellAlertManagerService.showAlert({type:l.CellAlertType.ERROR,title:this._localeService.t(`dataValidation.error.title`),message:i==null?void 0:i.getRuleFinalError(a,e.location),location:e.location,width:200,height:74,key:W});return}}this._cellAlertManagerService.removeAlert(W)}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._cellAlertManagerService.removeAlert(W)}))}};G=k([O(0,(0,t.Inject)(l.HoverManagerService)),O(1,(0,t.Inject)(l.CellAlertManagerService)),O(2,t.IUniverInstanceService),O(3,(0,t.Inject)(t.LocaleService)),O(4,o.IZenZoneService),O(5,(0,t.Inject)(i.SheetDataValidationModel))],G);let K=class extends t.Disposable{constructor(e,t,n){super(),this._autoFillService=e,this._sheetDataValidationModel=t,this._injector=n,this._initAutoFill()}_initAutoFill(){let e=()=>({redos:[],undos:[]}),n=(e,n)=>{let{source:a,target:o,unitId:s,subUnitId:c}=e,u=this._sheetDataValidationModel.getRuleObjectMatrix(s,c).clone(),d=(0,l.virtualizeDiscreteRanges)([a,o]),[f,p]=d.ranges,{mapFunc:m}=d,h={row:f.startRow,col:f.startColumn},g=r.AutoFillTools.getAutoFillRepeatRange(f,p),_=new t.ObjectMatrix,v=new Set;g.forEach(e=>{let n=e.repeatStartCell,r=e.relativeRange,i={startRow:h.row,startColumn:h.col,endColumn:h.col,endRow:h.row},a={startRow:n.row,startColumn:n.col,endColumn:n.col,endRow:n.row};t.Range.foreach(r,(e,n)=>{let r=t.Rectangle.getPositionRange({startRow:e,startColumn:n,endColumn:n,endRow:e},i),{row:o,col:l}=m(r.startRow,r.startColumn),u=this._sheetDataValidationModel.getRuleIdByLocation(s,c,o,l)||``,d=t.Rectangle.getPositionRange({startRow:e,startColumn:n,endColumn:n,endRow:e},a),{row:f,col:p}=m(d.startRow,d.startColumn);_.setValue(f,p,u),v.add(u)})});let y=Array.from(v).map(e=>({id:e,ranges:(0,t.queryObjectMatrix)(_,t=>t===e)}));u.addRangeRules(y);let{redoMutations:b,undoMutations:x}=(0,i.getDataValidationDiffMutations)(s,c,u.diff(this._sheetDataValidationModel.getRules(s,c)),this._injector,`patched`,n===r.AUTO_FILL_APPLY_TYPE.ONLY_FORMAT);return{undos:x,redos:b}},a={id:i.DATA_VALIDATION_PLUGIN_NAME,onBeforeFillData:e=>{let{source:n,unitId:i,subUnitId:a}=e;for(let e of n.rows)for(let o of n.cols){let n=this._sheetDataValidationModel.getRuleByLocation(i,a,e,o);if(n&&n.type===t.DataValidationType.CHECKBOX){this._autoFillService.setDisableApplyType(r.AUTO_FILL_APPLY_TYPE.SERIES,!0);return}}},onFillData:(t,i,a)=>a===r.AUTO_FILL_APPLY_TYPE.COPY||a===r.AUTO_FILL_APPLY_TYPE.ONLY_FORMAT||a===r.AUTO_FILL_APPLY_TYPE.SERIES?n(t,a):e(),onAfterFillData:()=>{}};this.disposeWithMe(this._autoFillService.addHook(a))}};K=k([O(0,r.IAutoFillService),O(1,(0,t.Inject)(i.SheetDataValidationModel)),O(2,(0,t.Inject)(t.Injector))],K);let q=class extends t.Disposable{constructor(e,t,n){super(),this._sheetClipboardService=e,this._sheetDataValidationModel=t,this._injector=n,D(this,`_copyInfo`,void 0),this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:i.DATA_VALIDATION_PLUGIN_NAME,onBeforeCopy:(e,t,n)=>this._collect(e,t,n),onPasteCells:(e,t,n,r)=>{let{copyType:i=l.COPY_TYPE.COPY,pasteType:a}=r,{range:o}=e||{},{range:s,unitId:c,subUnitId:u}=t;return this._generateMutations(s,{copyType:i,pasteType:a,copyRange:o,unitId:c,subUnitId:u})}})}_collect(e,n,i){let a=new t.ObjectMatrix;this._copyInfo={unitId:e,subUnitId:n,matrix:a};let o=this._injector.invoke(t=>(0,r.rangeToDiscreteRange)(i,t,e,n));if(!o)return;let{rows:s,cols:c}=o;s.forEach((t,r)=>{c.forEach((i,o)=>{let s=this._sheetDataValidationModel.getRuleIdByLocation(e,n,t,i);a.setValue(r,o,s==null?``:s)})})}_generateMutations(e,n){if(!this._copyInfo)return{redos:[],undos:[]};if(n.copyType===l.COPY_TYPE.CUT)return this._copyInfo=null,{redos:[],undos:[]};if(!this._copyInfo||!this._copyInfo.matrix.getSizeOf()||!n.copyRange||[l.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_COL_WIDTH,l.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_VALUE,l.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMAT,l.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMULA].includes(n.pasteType))return{redos:[],undos:[]};let{unitId:r,subUnitId:a}=this._copyInfo;if(n.unitId!==r||a!==n.subUnitId){let o=this._sheetDataValidationModel.getRuleObjectMatrix(n.unitId,n.subUnitId).clone(),s=new t.ObjectMatrix,c=new Set,{ranges:[u,d],mapFunc:f}=(0,l.virtualizeDiscreteRanges)([n.copyRange,e]),p=(0,l.getRepeatRange)(u,d,!0),m=new Map;p.forEach(({startRange:e})=>{var i;(i=this._copyInfo)==null||i.matrix.forValue((i,o,l)=>{let u=t.Rectangle.getPositionRange({startRow:i,endRow:i,startColumn:o,endColumn:o},e),d=`${a}-${l}`,p=this._sheetDataValidationModel.getRuleById(r,a,l);!this._sheetDataValidationModel.getRuleById(n.unitId,n.subUnitId,d)&&p&&m.set(d,{...p,uid:d});let{row:h,col:g}=f(u.startRow,u.startColumn);c.add(d),s.setValue(h,g,d)})});let h=Array.from(c).map(e=>({id:e,ranges:(0,t.queryObjectMatrix)(s,t=>t===e)}));o.addRangeRules(h);let{redoMutations:g,undoMutations:_}=(0,i.getDataValidationDiffMutations)(n.unitId,n.subUnitId,o.diffWithAddition(this._sheetDataValidationModel.getRules(n.unitId,n.subUnitId),m.values()),this._injector,`patched`,!1);return{redos:g,undos:_}}else{let o=this._sheetDataValidationModel.getRuleObjectMatrix(r,a).clone(),s=new t.ObjectMatrix,c=new Set,{ranges:[u,d],mapFunc:f}=(0,l.virtualizeDiscreteRanges)([n.copyRange,e]);(0,l.getRepeatRange)(u,d,!0).forEach(({startRange:e})=>{var n;(n=this._copyInfo)==null||n.matrix.forValue((n,r,i)=>{let a=t.Rectangle.getPositionRange({startRow:n,endRow:n,startColumn:r,endColumn:r},e),{row:o,col:l}=f(a.startRow,a.startColumn);s.setValue(o,l,i),c.add(i)})});let p=Array.from(c).map(e=>({id:e,ranges:(0,t.queryObjectMatrix)(s,t=>t===e)}));o.addRangeRules(p);let{redoMutations:m,undoMutations:h}=(0,i.getDataValidationDiffMutations)(r,a,o.diff(this._sheetDataValidationModel.getRules(r,a)),this._injector,`patched`,!1);return{redos:m,undos:h}}}};q=k([O(0,l.ISheetClipboardService),O(1,(0,t.Inject)(i.SheetDataValidationModel)),O(2,(0,t.Inject)(t.Injector))],q);let J=class extends t.Disposable{constructor(e,t,n){super(),this._localeService=e,this._commandService=t,this._sheetPermissionCheckController=n,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===i.AddSheetDataValidationCommand.id){let{unitId:t,subUnitId:n,rule:{ranges:i}}=e.params;this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[r.WorkbookEditablePermission],rangeTypes:[r.RangeProtectionPermissionEditPoint],worksheetTypes:[r.WorksheetEditPermission,r.WorksheetSetCellStylePermission]},i,t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.setStyleErr`))}if(e.id===i.UpdateSheetDataValidationRangeCommand.id){let{unitId:t,subUnitId:n,ranges:i}=e.params;this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[r.WorkbookEditablePermission],rangeTypes:[r.RangeProtectionPermissionEditPoint],worksheetTypes:[r.WorksheetEditPermission,r.WorksheetSetCellStylePermission]},i,t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.setStyleErr`))}}))}};J=k([O(0,(0,t.Inject)(t.LocaleService)),O(1,t.ICommandService),O(2,(0,t.Inject)(r.SheetPermissionCheckController))],J);let ee=`sheet.menu.data-validation`;function te(e){return{id:ee,type:o.MenuItemType.SUBITEMS,icon:`DataValidationIcon`,tooltip:`dataValidation.title`,hidden$:(0,o.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:(0,l.getCurrentRangeDisable$)(e,{workbookTypes:[r.WorkbookEditablePermission],worksheetTypes:[r.WorksheetSetCellStylePermission,r.WorksheetEditPermission],rangeTypes:[r.RangeProtectionPermissionEditPoint]})}}function ne(e){return{id:R.id,title:`dataValidation.panel.title`,type:o.MenuItemType.BUTTON}}function re(e){return{id:U.id,title:`dataValidation.panel.add`,type:o.MenuItemType.BUTTON}}let ie={[o.RibbonDataGroup.RULES]:{[ee]:{order:0,menuItemFactory:te,[R.id]:{order:0,menuItemFactory:ne},[U.id]:{order:1,menuItemFactory:re}}}},ae={tr:{size:6,color:`#fe4b4b`}},Y=class extends t.RxDisposable{constructor(e,t,n,r,i,a,o,s,c,l,u){super(),this._commandService=e,this._menuManagerService=t,this._renderManagerService=n,this._univerInstanceService=r,this._autoHeightController=i,this._dropdownManagerService=a,this._sheetDataValidationModel=o,this._dataValidatorRegistryService=s,this._sheetInterceptorService=c,this._dataValidationCacheService=l,this._editorBridgeService=u,this._initMenu(),this._initDropdown(),this._initViewModelIntercept(),this._initAutoHeight()}_initMenu(){this._menuManagerService.mergeMenu(ie)}_initDropdown(){this._editorBridgeService&&this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{if(!e.visible){var t;((t=this._dropdownManagerService.activeDropdown)==null?void 0:t.trigger)===`editor-bridge`&&this._dropdownManagerService.hideDropdown();return}let n=this._editorBridgeService.getEditCellState();if(n){let{unitId:e,sheetId:t,row:r,column:i}=n,a=this._univerInstanceService.getUniverSheetInstance(e);if(!a)return;let o=this._sheetDataValidationModel.getRuleByLocation(e,t,r,i);if(!o)return;let s=this._dataValidatorRegistryService.getValidatorItem(o.type);if(!(s!=null&&s.dropdownType))return;let c=a.getActiveSheet();if(!c)return;let l=this._dropdownManagerService.activeDropdown,u=l==null?void 0:l.location;if(u&&u.unitId===e&&u.subUnitId===t&&u.row===r&&u.col===i)return;this._dropdownManagerService.showDropdown({location:{unitId:e,subUnitId:t,row:r,col:i,workbook:a,worksheet:c},trigger:`editor-bridge`,closeOnOutSide:!1})}}))}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(r.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Style,priority:r.InterceptCellContentPriority.DATA_VALIDATION,handler:(e,n,r)=>{var a,o,s,c,u;let{row:d,col:f,unitId:p,subUnitId:m,workbook:h,worksheet:g}=n,_=this._sheetDataValidationModel.getRuleIdByLocation(p,m,d,f);if(!_)return r(e);let v=this._sheetDataValidationModel.getRuleById(p,m,_);if(!v)return r(e);let y=(a=this._dataValidationCacheService.getValue(p,m,d,f))==null?t.DataValidationStatus.VALID:a,b=this._dataValidatorRegistryService.getValidatorItem(v.type),x=n.rawData,S,C={get value(){var e;return S===void 0&&(S=(e=(0,i.getCellValueOrigin)(x))==null?null:e),S}},w={get value(){var e;return`${(e=C.value)==null?``:e}`}};return(!e||e===n.rawData)&&(e={...n.rawData}),e.markers={...e==null?void 0:e.markers,...y===t.DataValidationStatus.INVALID?ae:null},e.customRender=[...(o=e==null?void 0:e.customRender)==null?[]:o,...b!=null&&b.canvasRender?[b.canvasRender]:[]],e.fontRenderExtension={...e==null?void 0:e.fontRenderExtension,isSkip:(e==null||(s=e.fontRenderExtension)==null?void 0:s.isSkip)||(b==null||(c=b.skipDefaultFontRender)==null?void 0:c.call(b,v,C.value,n))},e.interceptorStyle={...e==null?void 0:e.interceptorStyle,...b==null?void 0:b.getExtraStyle(v,w.value,{get style(){let t=h.getStyles();return(typeof(e==null?void 0:e.s)==`string`?t.get(e==null?void 0:e.s):e==null?void 0:e.s)||{}}},d,f)},e.interceptorAutoHeight=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(p))==null||(t=t.with(l.SheetSkeletonManagerService).getSkeletonParam(m))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(d,f),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?d:n,(r=s==null?void 0:s.startColumn)==null?f:r),unitId:p,subUnitId:m,row:d,col:f,workbook:h,worksheet:g};return b==null||(i=b.canvasRender)==null||(a=i.calcCellAutoHeight)==null?void 0:a.call(i,c)},e.interceptorAutoWidth=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(p))==null||(t=t.with(l.SheetSkeletonManagerService).getSkeletonParam(m))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(d,f),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?d:n,(r=s==null?void 0:s.startColumn)==null?f:r),unitId:p,subUnitId:m,row:d,col:f,workbook:h,worksheet:g};return b==null||(i=b.canvasRender)==null||(a=i.calcCellAutoWidth)==null?void 0:a.call(i,c)},e.coverable=((u=e==null?void 0:e.coverable)==null?!0:u)&&!(v.type===t.DataValidationType.LIST||v.type===t.DataValidationType.LIST_MULTIPLE),r(e)}}))}_initAutoHeight(){this._sheetDataValidationModel.ruleChange$.pipe((0,s.filter)(e=>e.source===`command`),(0,s.bufferTime)(100)).subscribe(e=>{if(e.length===0)return;let n=[];e.forEach(e=>{if(e.rule.type===t.DataValidationType.LIST_MULTIPLE||e.rule.type===t.DataValidationType.LIST){var r;(r=e.rule)!=null&&r.ranges&&n.push(...e.rule.ranges)}}),n.length&&(0,t.sequenceExecute)(this._autoHeightController.getUndoRedoParamsOfAutoHeight(n).redos,this._commandService)})}};Y=k([O(0,t.ICommandService),O(1,o.IMenuManagerService),O(2,n.IRenderManagerService),O(3,t.IUniverInstanceService),O(4,(0,t.Inject)(l.AutoHeightController)),O(5,(0,t.Inject)(I)),O(6,(0,t.Inject)(i.SheetDataValidationModel)),O(7,(0,t.Inject)(a.DataValidatorRegistryService)),O(8,(0,t.Inject)(r.SheetInterceptorService)),O(9,(0,t.Inject)(i.DataValidationCacheService)),O(10,(0,t.Optional)(l.IEditorBridgeService))],Y);let oe=class extends t.RxDisposable{constructor(e,t,n,r,i,a,o){super(),this._commandService=e,this._renderManagerService=t,this._autoHeightController=n,this._dataValidatorRegistryService=r,this._sheetInterceptorService=i,this._sheetDataValidationModel=a,this._dataValidationCacheService=o,this._initViewModelIntercept(),this._initAutoHeight()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(r.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Style,priority:r.InterceptCellContentPriority.DATA_VALIDATION,handler:(e,n,r)=>{var a,o,s,c,u;let{row:d,col:f,unitId:p,subUnitId:m,workbook:h,worksheet:g}=n,_=this._sheetDataValidationModel.getRuleIdByLocation(p,m,d,f);if(!_)return r(e);let v=this._sheetDataValidationModel.getRuleById(p,m,_);if(!v)return r(e);let y=(a=this._dataValidationCacheService.getValue(p,m,d,f))==null?t.DataValidationStatus.VALID:a,b=this._dataValidatorRegistryService.getValidatorItem(v.type),x=(0,i.getCellValueOrigin)(g.getCellRaw(d,f)),S=`${x==null?``:x}`;return(!e||e===n.rawData)&&(e={...n.rawData}),e.markers={...e==null?void 0:e.markers,...y===t.DataValidationStatus.INVALID?ae:null},e.customRender=[...(o=e==null?void 0:e.customRender)==null?[]:o,...b!=null&&b.canvasRender?[b.canvasRender]:[]],e.fontRenderExtension={...e==null?void 0:e.fontRenderExtension,isSkip:(e==null||(s=e.fontRenderExtension)==null?void 0:s.isSkip)||(b==null||(c=b.skipDefaultFontRender)==null?void 0:c.call(b,v,x,n))},e.interceptorStyle={...e==null?void 0:e.interceptorStyle,...b==null?void 0:b.getExtraStyle(v,S,{get style(){let t=h.getStyles();return(typeof(e==null?void 0:e.s)==`string`?t.get(e==null?void 0:e.s):e==null?void 0:e.s)||{}}},d,f)},e.interceptorAutoHeight=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(p))==null||(t=t.with(l.SheetSkeletonManagerService).getSkeletonParam(m))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(d,f),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?d:n,(r=s==null?void 0:s.startColumn)==null?f:r),unitId:p,subUnitId:m,row:d,col:f,workbook:h,worksheet:g};return b==null||(i=b.canvasRender)==null||(a=i.calcCellAutoHeight)==null?void 0:a.call(i,c)},e.interceptorAutoWidth=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(p))==null||(t=t.with(l.SheetSkeletonManagerService).getSkeletonParam(m))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(d,f),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?d:n,(r=s==null?void 0:s.startColumn)==null?f:r),unitId:p,subUnitId:m,row:d,col:f,workbook:h,worksheet:g};return b==null||(i=b.canvasRender)==null||(a=i.calcCellAutoWidth)==null?void 0:a.call(i,c)},e.coverable=((u=e==null?void 0:e.coverable)==null?!0:u)&&!(v.type===t.DataValidationType.LIST||v.type===t.DataValidationType.LIST_MULTIPLE),r(e)}}))}_initAutoHeight(){this._sheetDataValidationModel.ruleChange$.pipe((0,s.filter)(e=>e.source===`command`),(0,s.bufferTime)(16)).subscribe(e=>{let n=[];e.forEach(e=>{if(e.rule.type===t.DataValidationType.LIST_MULTIPLE||e.rule.type===t.DataValidationType.LIST){var r;(r=e.rule)!=null&&r.ranges&&n.push(...e.rule.ranges)}}),n.length&&(0,t.sequenceExecute)(this._autoHeightController.getUndoRedoParamsOfAutoHeight(n).redos,this._commandService)})}};oe=k([O(0,t.ICommandService),O(1,n.IRenderManagerService),O(2,(0,t.Inject)(l.AutoHeightController)),O(3,(0,t.Inject)(a.DataValidatorRegistryService)),O(4,(0,t.Inject)(r.SheetInterceptorService)),O(5,(0,t.Inject)(i.SheetDataValidationModel)),O(6,(0,t.Inject)(i.DataValidationCacheService))],oe);let se=class extends t.Disposable{constructor(e,t,n){super(),this._context=e,this._sheetDataValidationModel=t,this._sheetSkeletonManagerService=n,this._initSkeletonChange()}_initSkeletonChange(){this.disposeWithMe(this._sheetDataValidationModel.validStatusChange$.pipe((0,t.bufferDebounceTime)(16)).subscribe(e=>{var t;if(!e.length)return;let n=new Set;e.forEach(e=>{n.add(e.subUnitId)}),n.forEach(e=>{var t;(t=this._sheetSkeletonManagerService.getSkeletonParam(e))==null||t.skeleton.makeDirty(!0)}),(t=this._context.mainComponent)==null||t.makeForceDirty()}))}};se=k([O(1,(0,t.Inject)(i.SheetDataValidationModel)),O(2,(0,t.Inject)(l.SheetSkeletonManagerService))],se);function X({ref:e,...t}){let{icon:n,id:r,className:i,extend:a,...o}=t,s=`univerjs-icon univerjs-icon-${r} ${i||``}`.trim(),c=(0,d.useRef)(`_${de()}`);return ce(n,`${r}`,{defIds:n.defIds,idSuffix:c.current},{ref:e,className:s,...o},a)}function ce(e,t,n,r,i){return(0,d.createElement)(e.tag,{key:t,...le(e,n,i),...r},(ue(e,n).children||[]).map((r,a)=>ce(r,`${t}-${e.tag}-${a}`,n,void 0,i)))}function le(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),e.tag===`mask`&&r.id&&(r.id+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{e===`mask`&&typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});let{defIds:i}=t;return!i||i.length===0?r:(e.tag===`use`&&r[`xlink:href`]&&(r[`xlink:href`]+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))}),r)}function ue(e,t){var n;let{defIds:r}=t;return!r||r.length===0?e:e.tag===`defs`&&(n=e.children)!=null&&n.length?{...e,children:e.children.map(e=>typeof e.attrs.id==`string`&&r&&r.includes(e.attrs.id)?{...e,attrs:{...e.attrs,id:e.attrs.id+t.idSuffix}}:e)}:e}function de(){return Math.random().toString(36).substring(2,8)}X.displayName=`UniverIcon`;let fe={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 17 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M1.4917 3.07803C1.4917 2.19437 2.20804 1.47803 3.0917 1.47803H5.6917C6.57536 1.47803 7.2917 2.19437 7.2917 3.07803V5.67803C7.2917 6.56168 6.57535 7.27803 5.6917 7.27803H3.0917C2.20804 7.27803 1.4917 6.56168 1.4917 5.67803V3.07803ZM3.0917 2.67803C2.87078 2.67803 2.6917 2.85711 2.6917 3.07803V5.67803C2.6917 5.89894 2.87079 6.07803 3.0917 6.07803H5.6917C5.91261 6.07803 6.0917 5.89894 6.0917 5.67803V3.07803C6.0917 2.85711 5.91261 2.67803 5.6917 2.67803H3.0917Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M14.6175 2.45279C14.8518 2.68711 14.8518 3.06701 14.6175 3.30132L11.6151 6.30365C11.3957 6.52307 11.0451 6.53897 10.8067 6.34031L8.80915 4.67566C8.55458 4.46352 8.52019 4.08518 8.73233 3.83062C8.94447 3.57605 9.32281 3.54166 9.57737 3.7538L11.154 5.06767L13.769 2.45278C14.0033 2.21847 14.3832 2.21848 14.6175 2.45279Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M14.1175 9.19746C14.3518 9.43178 14.3518 9.81168 14.1175 10.046L12.5418 11.6217L14.1175 13.1975C14.3518 13.4318 14.3518 13.8117 14.1175 14.046C13.8832 14.2803 13.5033 14.2803 13.269 14.046L11.6933 12.4703L10.1175 14.046C9.88321 14.2803 9.50331 14.2803 9.269 14.046C9.03468 13.8117 9.03468 13.4318 9.269 13.1975L10.8447 11.6217L9.269 10.046C9.03468 9.81168 9.03468 9.43178 9.269 9.19746C9.50331 8.96315 9.88321 8.96315 10.1175 9.19746L11.6933 10.7732L13.269 9.19746C13.5033 8.96315 13.8832 8.96315 14.1175 9.19746Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M3.0917 8.72168C2.20804 8.72168 1.4917 9.43802 1.4917 10.3217V12.9217C1.4917 13.8053 2.20804 14.5217 3.0917 14.5217H5.6917C6.57535 14.5217 7.2917 13.8053 7.2917 12.9217V10.3217C7.2917 9.43802 6.57536 8.72168 5.6917 8.72168H3.0917ZM2.6917 10.3217C2.6917 10.1008 2.87078 9.92168 3.0917 9.92168H5.6917C5.91261 9.92168 6.0917 10.1008 6.0917 10.3217V12.9217C6.0917 13.1426 5.91261 13.3217 5.6917 13.3217H3.0917C2.87079 13.3217 2.6917 13.1426 2.6917 12.9217V10.3217Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},pe=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(X,Object.assign({},e,{id:`data-validation-icon`,ref:t,icon:fe}))});pe.displayName=`DataValidationIcon`;let me={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M5.3313 1.4667C5.3313 1.13533 5.59993 0.866699 5.9313 0.866699H10.069C10.4004 0.866699 10.669 1.13533 10.669 1.4667C10.669 1.79807 10.4004 2.0667 10.069 2.0667H5.9313C5.59993 2.0667 5.3313 1.79807 5.3313 1.4667Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.09985 3.64443C1.09985 3.31306 1.36848 3.04443 1.69985 3.04443H14.2999C14.6312 3.04443 14.8999 3.31306 14.8999 3.64443C14.8999 3.9758 14.6312 4.24443 14.2999 4.24443H1.69985C1.36848 4.24443 1.09985 3.9758 1.09985 3.64443Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M6.12398 8.30171C6.35829 8.0674 6.73819 8.0674 6.97251 8.30171L8.00007 9.32928L9.02764 8.30171C9.26195 8.0674 9.64185 8.0674 9.87617 8.30171C10.1105 8.53603 10.1105 8.91593 9.87617 9.15024L8.8486 10.1778L9.87617 11.2054C10.1105 11.4397 10.1105 11.8196 9.87617 12.0539C9.64185 12.2882 9.26195 12.2882 9.02764 12.0539L8.00007 11.0263L6.97251 12.0539C6.73819 12.2882 6.35829 12.2882 6.12398 12.0539C5.88966 11.8196 5.88966 11.4397 6.12398 11.2054L7.15154 10.1778L6.12398 9.15024C5.88966 8.91593 5.88966 8.53603 6.12398 8.30171Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M4.75332 5.22217C3.86966 5.22217 3.15332 5.93851 3.15332 6.82217V12.5331C3.15332 13.9691 4.31738 15.1332 5.75332 15.1332H10.2465C11.6825 15.1332 12.8465 13.9691 12.8465 12.5331V6.82217C12.8465 5.93851 12.1302 5.22217 11.2465 5.22217H4.75332ZM4.35332 6.82217C4.35332 6.60125 4.53241 6.42217 4.75332 6.42217H11.2465C11.4674 6.42217 11.6465 6.60125 11.6465 6.82217V12.5331C11.6465 13.3063 11.0197 13.9332 10.2465 13.9332H5.75332C4.98012 13.9332 4.35332 13.3063 4.35332 12.5331V6.82217Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},he=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(X,Object.assign({},e,{id:`delete-icon`,ref:t,icon:me}))});he.displayName=`DeleteIcon`;let ge={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M8.6 1.99991C8.60001 1.66854 8.33138 1.39991 8.00001 1.3999C7.66864 1.3999 7.40001 1.66853 7.4 1.9999L7.39996 7.3999H1.9999C1.66853 7.3999 1.3999 7.66853 1.3999 7.9999C1.3999 8.33127 1.66853 8.5999 1.9999 8.5999H7.39995L7.3999 13.9999C7.3999 14.3313 7.66853 14.5999 7.9999 14.5999C8.33127 14.5999 8.5999 14.3313 8.5999 13.9999L8.59995 8.5999H13.9999C14.3313 8.5999 14.5999 8.33127 14.5999 7.9999C14.5999 7.66853 14.3313 7.3999 13.9999 7.3999H8.59996L8.6 1.99991Z`}}]},_e=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(X,Object.assign({},e,{id:`increase-icon`,ref:t,icon:ge}))});_e.displayName=`IncreaseIcon`;let ve={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M11.3536 6.14645C11.5488 6.34171 11.5488 6.65829 11.3536 6.85355L8.35355 9.85355C8.15829 10.0488 7.84171 10.0488 7.64645 9.85355L4.64645 6.85355C4.45118 6.65829 4.45118 6.34171 4.64645 6.14645C4.84171 5.95118 5.15829 5.95118 5.35355 6.14645L8 8.79289L10.6464 6.14645C10.8417 5.95118 11.1583 5.95118 11.3536 6.14645Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},ye=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(X,Object.assign({},e,{id:`more-down-icon`,ref:t,icon:ve}))});ye.displayName=`MoreDownIcon`;let be={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M4.64645 9.85355C4.45118 9.65829 4.45118 9.34171 4.64645 9.14645L7.64645 6.14645C7.84171 5.95118 8.15829 5.95118 8.35355 6.14645L11.3536 9.14645C11.5488 9.34171 11.5488 9.65829 11.3536 9.85355C11.1583 10.0488 10.8417 10.0488 10.6464 9.85355L8 7.20711L5.35355 9.85355C5.15829 10.0488 4.84171 10.0488 4.64645 9.85355Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},xe=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(X,Object.assign({},e,{id:`more-up-icon`,ref:t,icon:be}))});xe.displayName=`MoreUpIcon`;let Se={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M6 5C6.55228 5 7 4.55228 7 4C7 3.44772 6.55228 3 6 3C5.44772 3 5 3.44772 5 4C5 4.55228 5.44772 5 6 5Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M6 9C6.55228 9 7 8.55229 7 8C7 7.44772 6.55228 7 6 7C5.44772 7 5 7.44772 5 8C5 8.55229 5.44772 9 6 9Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M7 12C7 12.5523 6.55228 13 6 13C5.44772 13 5 12.5523 5 12C5 11.4477 5.44772 11 6 11C6.55228 11 7 11.4477 7 12Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M10 5C10.5523 5 11 4.55228 11 4C11 3.44772 10.5523 3 10 3C9.44771 3 9 3.44772 9 4C9 4.55228 9.44771 5 10 5Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M11 8C11 8.55229 10.5523 9 10 9C9.44771 9 9 8.55229 9 8C9 7.44772 9.44771 7 10 7C10.5523 7 11 7.44772 11 8Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M10 13C10.5523 13 11 12.5523 11 12C11 11.4477 10.5523 11 10 11C9.44771 11 9 11.4477 9 12C9 12.5523 9.44771 13 10 13Z`}}]},Ce=(0,d.forwardRef)(function(e,t){return(0,d.createElement)(X,Object.assign({},e,{id:`sequence-icon`,ref:t,icon:Se}))});Ce.displayName=`SequenceIcon`;function we(e){var n;let r=(0,o.useDependency)(t.LocaleService),i=(0,o.useDependency)(o.ComponentManager),{value:a,onChange:s,extraComponent:c}=e,[l,f]=(0,d.useState)(!1),p=c?i.get(c):null;return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsxs)(`div`,{className:`
|
|
2
2
|
univer-mb-3 univer-flex univer-cursor-pointer univer-items-center univer-text-sm univer-text-gray-900
|
|
3
3
|
dark:!univer-text-white
|
|
4
4
|
`,onClick:()=>f(!l),children:[r.t(`dataValidation.panel.options`),l?(0,m.jsx)(xe,{className:`univer-ml-1`}):(0,m.jsx)(ye,{className:`univer-ml-1`})]}),l&&(0,m.jsxs)(m.Fragment,{children:[p?(0,m.jsx)(p,{value:a,onChange:s}):null,(0,m.jsx)(u.FormLayout,{label:r.t(`dataValidation.panel.invalid`),children:(0,m.jsxs)(u.RadioGroup,{value:`${(n=a.errorStyle)==null?t.DataValidationErrorStyle.WARNING:n}`,onChange:e=>s({...a,errorStyle:+e}),children:[(0,m.jsx)(u.Radio,{value:`${t.DataValidationErrorStyle.WARNING}`,children:r.t(`dataValidation.panel.showWarning`)}),(0,m.jsx)(u.Radio,{value:`${t.DataValidationErrorStyle.STOP}`,children:r.t(`dataValidation.panel.rejectInput`)})]})}),(0,m.jsx)(u.FormLayout,{label:r.t(`dataValidation.panel.messageInfo`),children:(0,m.jsx)(u.Checkbox,{checked:a.showErrorMessage,onChange:()=>s({...a,showErrorMessage:!a.showErrorMessage}),children:r.t(`dataValidation.panel.showInfo`)})}),a.showErrorMessage?(0,m.jsx)(u.FormLayout,{children:(0,m.jsx)(u.Input,{value:a.error,onChange:e=>s({...a,error:e})})}):null]})]})}let Te=e=>(0,t.debounce)(async(t,n,r,i)=>{let a=await e.executeCommand(t,n,r);i==null||i(a)},1e3);function Ee(e,n,r){var i;if(n){var a;return((a=e.getUnit(n))==null||(a=a.getSheetBySheetName(r))==null?void 0:a.getSheetId())||``}return((i=e.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET))==null||(i=i.getSheetBySheetName(r))==null?void 0:i.getSheetId())||``}function De(){var e,n;let[c,l]=(0,d.useState)(0),h=(0,o.useDependency)(A),{unitId:g,subUnitId:_,rule:v}=(0,o.useObservable)(h.activeRule$,h.activeRule)||{},y=v.uid,b=(0,o.useDependency)(a.DataValidatorRegistryService),x=(0,o.useDependency)(t.IUniverInstanceService),S=(0,o.useDependency)(o.ComponentManager),C=(0,o.useDependency)(t.ICommandService),w=(0,o.useDependency)(a.DataValidationModel),T=(0,o.useDependency)(t.LocaleService),E=(0,o.useObservable)(()=>x.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET),void 0,void 0,[]),D=(0,o.useObservable)(()=>{var e;return(e=E==null?void 0:E.activeSheet$)==null?(0,s.of)(null):e},void 0,void 0,[]),[O,k]=(0,d.useState)(v),j=b.getValidatorItem(O.type),[M,N]=(0,d.useState)(!1),P=b.getValidatorsByScope(a.DataValidatorRegistryScope.SHEET),[F,I]=(0,d.useState)(()=>O.ranges.map(e=>({unitId:``,sheetId:``,range:e}))),L=(0,d.useMemo)(()=>Te(C),[C]),[R,z]=(0,d.useState)(!1),[B,V]=(0,d.useState)(!1),H=(0,d.useRef)(null),U=(0,o.useDependency)(r.SheetsSelectionsService);if((0,d.useEffect)(()=>()=>{let e=U.getCurrentLastSelection();e&&U.setSelections([e])},[U]),(0,d.useEffect)(()=>{C.onCommandExecuted(e=>{(e.id===t.UndoCommand.id||e.id===t.RedoCommand.id)&&setTimeout(()=>{let e=w.getRuleById(g,_,y);l(e=>e+1),e&&(k(e),I(e.ranges.map(e=>({unitId:``,sheetId:``,range:e}))))},20)})},[C,w,y,_,g]),!j)return null;let W=j.operators,G=j.operatorNames,K=O.operator?a.TWO_FORMULA_OPERATOR_COUNT.includes(O.operator):!1,q=()=>{(D==null?void 0:D.getSheetId())!==_&&C.syncExecuteCommand(r.SetWorksheetActiveOperation.id,{unitId:g,subUnitId:_})},J=()=>{var e;if(!((e=H.current)==null||(e=e.editor)==null)&&e.isFocus()){var t;ee((t=H.current)==null?void 0:t.getValue())}!O.ranges.length||R||(j.validatorFormula(O,g,_).success?h.setActiveRule(null):N(!0),q())},ee=(0,o.useEvent)(e=>{let n=e.split(`,`).filter(Boolean).map(f.deserializeRangeWithSheet).map(e=>{let t=e.sheetName;if(t){let n=Ee(x,e.unitId,t);return{...e,sheetId:n}}return{...e,sheetId:``}});if((0,t.isUnitRangesEqual)(n,F))return;I(n);let r=n.filter(e=>(!e.unitId||e.unitId===g)&&(!e.sheetId||e.sheetId===_)).map(e=>e.range);if(k({...O,ranges:r}),r.length===0)return;let a={unitId:g,subUnitId:_,ruleId:y,ranges:r};L(i.UpdateSheetDataValidationRangeCommand.id,a)}),te=e=>{if((0,t.shallowEqual)(e,(0,a.getRuleSetting)(O)))return;k({...O,...e});let n={unitId:g,subUnitId:_,ruleId:y,setting:e};L(i.UpdateSheetDataValidationSettingCommand.id,n,void 0)},ne=async()=>{await C.executeCommand(i.RemoveSheetDataValidationCommand.id,{ruleId:y,unitId:g,subUnitId:_}),h.setActiveRule(null),q()},re={type:O.type,operator:O.operator,formula1:O.formula1,formula2:O.formula2,allowBlank:O.allowBlank},ie=e=>{let t=b.getValidatorItem(e);if(!t)return;let n=t.operators,r=w.getRuleById(g,_,y),o=e===(r==null?void 0:r.type)||e.includes(`list`)&&r!=null&&r.type.includes(`list`)?{...r,type:e}:{...O,type:e,operator:n[0],formula1:void 0,formula2:void 0};k(o),C.executeCommand(i.UpdateSheetDataValidationSettingCommand.id,{unitId:g,subUnitId:_,ruleId:O.uid,setting:(0,a.getRuleSetting)(o)})},ae=S.get(j.formulaInput),Y=(0,d.useMemo)(()=>F.map(e=>(0,f.serializeRange)(e.range)).join(`,`),[]),oe=(0,a.getRuleOptions)(O),se=e=>{(0,t.shallowEqual)(e,(0,a.getRuleOptions)(O))||(k({...O,...e}),L(i.UpdateSheetDataValidationOptionsCommand.id,{unitId:g,subUnitId:_,ruleId:y,options:e}))},X=W.length&&!O.operator;return(0,m.jsxs)(`div`,{"data-u-comp":`data-validation-detail`,className:`univer-py-2`,children:[(0,m.jsx)(u.FormLayout,{label:T.t(`dataValidation.panel.range`),error:!O.ranges.length||R?T.t(`dataValidation.panel.rangeError`):``,children:(0,m.jsx)(p.RangeSelector,{selectorRef:H,unitId:g,subUnitId:_,initialValue:Y,onChange:(e,t)=>{var n;!B&&(n=H.current)!=null&&n.verify()&&ee(t)},onFocusChange:(e,t)=>{var n;V(e),!e&&t&&(n=H.current)!=null&&n.verify()&&ee(t)},onVerify:e=>z(!e)})}),(0,m.jsx)(u.FormLayout,{label:T.t(`dataValidation.panel.type`),children:(0,m.jsx)(u.Select,{className:`univer-w-full`,value:O.type,options:P==null||(e=P.sort((e,t)=>e.order-t.order))==null?void 0:e.map(e=>({label:T.t(e.title),value:e.id})),onChange:ie})}),W!=null&&W.length?(0,m.jsx)(u.FormLayout,{label:T.t(`dataValidation.panel.operator`),children:(0,m.jsx)(u.Select,{className:`univer-w-full`,value:`${O.operator}`,options:[{value:``,label:T.t(`dataValidation.operators.legal`)},...W.map((e,t)=>({value:`${e}`,label:G[t]}))],onChange:e=>{te({...re,operator:e})}})}):null,ae&&!X?(0,m.jsx)(ae,{isTwoFormula:K,value:{formula1:O.formula1,formula2:O.formula2},onChange:e=>{te({...re,...e})},showError:M,validResult:j.validatorFormula(O,g,_),unitId:g,subUnitId:_,ruleId:y},c+O.type):null,(0,m.jsx)(u.FormLayout,{children:(0,m.jsx)(u.Checkbox,{checked:(n=O.allowBlank)==null?!0:n,onChange:()=>{var e;return te({...re,allowBlank:!((e=O.allowBlank)==null||e)})},children:T.t(`dataValidation.panel.allowBlank`)})}),(0,m.jsx)(we,{value:oe,onChange:se,extraComponent:j.optionsInput}),(0,m.jsxs)(`div`,{className:`univer-mt-5 univer-flex univer-flex-row univer-justify-end`,children:[(0,m.jsx)(u.Button,{className:`univer-ml-3`,onClick:ne,children:T.t(`dataValidation.panel.removeRule`)}),(0,m.jsx)(u.Button,{className:`univer-ml-3`,variant:`primary`,onClick:J,children:T.t(`dataValidation.panel.done`)})]})]})}let Oe=e=>{let{rule:n,onClick:r,unitId:s,subUnitId:c,disable:p}=e,h=(0,o.useDependency)(a.DataValidatorRegistryService),g=(0,o.useDependency)(t.ICommandService),_=(0,o.useDependency)(l.IMarkSelectionService),v=h.getValidatorItem(n.type),y=(0,d.useRef)(void 0),[b,x]=(0,d.useState)(!1),S=(0,o.useDependency)(t.ThemeService),C=(0,d.useMemo)(()=>{var e;let n=S.getColorFromTheme(`primary.600`),r=S.getColorFromTheme(`loop-color.2`),i=(e=S.getColorFromTheme(r))==null?n:e,a=new t.ColorKit(i).toRgb();return{fill:`rgba(${a.r}, ${a.g}, ${a.b}, 0.1)`,stroke:i}},[(0,o.useObservable)(S.currentTheme$)]),w=e=>{g.executeCommand(i.RemoveSheetDataValidationCommand.id,{ruleId:n.uid,unitId:s,subUnitId:c}),e.stopPropagation()};return(0,d.useEffect)(()=>()=>{if(y.current){var e;(e=y.current)==null||e.forEach(e=>{e&&_.removeShape(e)})}},[_]),(0,m.jsxs)(`div`,{className:(0,u.clsx)(`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-data-validation-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Data validation UI for Univer Sheets",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -55,17 +55,17 @@
|
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"@univerjs/icons": "^1.1.1",
|
|
58
|
-
"@univerjs/core": "0.
|
|
59
|
-
"@univerjs/
|
|
60
|
-
"@univerjs/engine-formula": "0.
|
|
61
|
-
"@univerjs/
|
|
62
|
-
"@univerjs/sheets
|
|
63
|
-
"@univerjs/
|
|
64
|
-
"@univerjs/sheets": "0.
|
|
65
|
-
"@univerjs/sheets-
|
|
66
|
-
"@univerjs/
|
|
67
|
-
"@univerjs/
|
|
68
|
-
"@univerjs/
|
|
58
|
+
"@univerjs/core": "0.18.0",
|
|
59
|
+
"@univerjs/design": "0.18.0",
|
|
60
|
+
"@univerjs/engine-formula": "0.18.0",
|
|
61
|
+
"@univerjs/data-validation": "0.18.0",
|
|
62
|
+
"@univerjs/sheets": "0.18.0",
|
|
63
|
+
"@univerjs/engine-render": "0.18.0",
|
|
64
|
+
"@univerjs/sheets-data-validation": "0.18.0",
|
|
65
|
+
"@univerjs/sheets-formula-ui": "0.18.0",
|
|
66
|
+
"@univerjs/sheets-ui": "0.18.0",
|
|
67
|
+
"@univerjs/ui": "0.18.0",
|
|
68
|
+
"@univerjs/sheets-numfmt": "0.18.0"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"postcss": "^8.5.8",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"tailwindcss": "3.4.18",
|
|
75
75
|
"typescript": "^5.9.3",
|
|
76
76
|
"vitest": "^4.1.0",
|
|
77
|
-
"@univerjs-infra/shared": "0.
|
|
77
|
+
"@univerjs-infra/shared": "0.18.0"
|
|
78
78
|
},
|
|
79
79
|
"scripts": {
|
|
80
80
|
"dev": "vite",
|