@univerjs/data-validation 0.6.0-nightly.202502151605 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +176 -0
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +124 -124
- package/lib/umd/index.js +1 -1
- package/package.json +4 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var P=Object.defineProperty;var B=(i,a,e)=>a in i?P(i,a,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[a]=e;var p=(i,a,e)=>B(i,typeof a!="symbol"?a+"":a,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),D=require("rxjs");function N(i){return{type:i.type,operator:i.operator,formula1:i.formula1,formula2:i.formula2,allowBlank:i.allowBlank}}function M(i){return{error:i.error,errorStyle:i.errorStyle,errorTitle:i.errorTitle,imeMode:i.imeMode,prompt:i.prompt,promptTitle:i.promptTitle,showDropDown:i.showDropDown,showErrorMessage:i.showErrorMessage,showInputMessage:i.showInputMessage,renderMode:i.renderMode,bizInfo:i.bizInfo}}var m=(i=>(i[i.SETTING=0]="SETTING",i[i.RANGE=1]="RANGE",i[i.OPTIONS=2]="OPTIONS",i[i.ALL=3]="ALL",i))(m||{}),x=Object.defineProperty,$=Object.getOwnPropertyDescriptor,j=(i,a,e,r)=>{for(var t=r>1?void 0:r?$(a,e):a,n=i.length-1,d;n>=0;n--)(d=i[n])&&(t=(r?d(a,e,t):d(t))||t);return r&&t&&x(a,e,t),t},q=(i,a)=>(e,r)=>a(e,r,i);exports.DataValidationModel=class extends o.Disposable{constructor(e){super();p(this,"_model",new Map);p(this,"_ruleChange$",new D.Subject);p(this,"ruleChange$",this._ruleChange$.asObservable());p(this,"ruleChangeDebounce$",this.ruleChange$.pipe(D.debounceTime(20)));this._logService=e,this.disposeWithMe({dispose:()=>{this._ruleChange$.complete()}})}_ensureMap(e,r){this._model.has(e)||this._model.set(e,new Map);const t=this._model.get(e);if(t.has(r))return t.get(r);const n={map:new Map,list:[]};return t.set(r,n),n}_addSubUnitRule(e,r,t){const{map:n,list:d}=e,u=(Array.isArray(r)?r:[r]).filter(l=>!n.has(l.uid));typeof t=="number"&&t<d.length?d.splice(t,0,...u):d.push(...u),u.forEach(l=>{n.set(l.uid,l)})}_removeSubUnitRule(e,r){const{map:t,list:n}=e,d=n.findIndex(s=>s.uid===r);d>-1&&(n.splice(d,1),t.delete(r))}_updateSubUnitRule(e,r,t){const{map:n,list:d}=e,s=n.get(r),u=d.findIndex(c=>r===c.uid);if(!s)throw new Error(`Data validation rule is not found, ruleId: ${r}.`);const l={...s};switch(t.type){case m.RANGE:{l.ranges=t.payload;break}case m.SETTING:{Object.assign(l,N(t.payload));break}case m.OPTIONS:{Object.assign(l,M(t.payload));break}case m.ALL:{Object.assign(l,t.payload);break}}return d[u]=l,n.set(r,l),l}_addRuleSideEffect(e,r,t,n){if(!this._ensureMap(e,r).map.get(t.uid))return{rule:t,type:"add",unitId:e,subUnitId:r,source:n}}addRule(e,r,t,n,d){try{const s=this._ensureMap(e,r),l=(Array.isArray(t)?t:[t]).map(c=>this._addRuleSideEffect(e,r,c,n));this._addSubUnitRule(s,t,d),l.forEach(c=>{c&&this._ruleChange$.next(c)})}catch(s){this._logService.error(s)}}updateRule(e,r,t,n,d){try{const s=this._ensureMap(e,r),u=o.Tools.deepClone(s.map.get(t));if(!u)throw new Error(`Data validation rule is not found, ruleId: ${t}.`);const l=this._updateSubUnitRule(s,t,n);this._ruleChange$.next({rule:l,type:"update",unitId:e,subUnitId:r,source:d,updatePayload:n,oldRule:u})}catch(s){this._logService.error(s)}}removeRule(e,r,t,n){try{const d=this._ensureMap(e,r),s=d.map.get(t);s&&(this._removeSubUnitRule(d,t),this._ruleChange$.next({rule:s,type:"remove",unitId:e,subUnitId:r,source:n}))}catch(d){this._logService.error(d)}}getRuleById(e,r,t){return this._ensureMap(e,r).map.get(t)}getRuleIndex(e,r,t){return this._ensureMap(e,r).list.findIndex(d=>d.uid===t)}getRules(e,r){return[...this._ensureMap(e,r).list]}getUnitRules(e){const r=this._model.get(e);if(!r)return[];const t=[];return r.forEach((n,d)=>{t.push([d,n.list])}),t}deleteUnitRules(e){this._model.delete(e)}getSubUnitIds(e){var r,t;return Array.from((t=(r=this._model.get(e))==null?void 0:r.keys())!=null?t:[])}getAll(){return Array.from(this._model.keys()).map(e=>[e,this.getUnitRules(e)])}};exports.DataValidationModel=j([q(0,o.ILogService)],exports.DataValidationModel);var G=Object.defineProperty,H=Object.getOwnPropertyDescriptor,Q=(i,a,e,r)=>{for(var t=r>1?void 0:r?H(a,e):a,n=i.length-1,d;n>=0;n--)(d=i[n])&&(t=(r?d(a,e,t):d(t))||t);return r&&t&&G(a,e,t),t},T=(i,a)=>(e,r)=>a(e,r,i);const F="SHEET_DATA_VALIDATION_PLUGIN";exports.DataValidationResourceController=class extends o.Disposable{constructor(a,e,r){super(),this._resourceManagerService=a,this._univerInstanceService=e,this._dataValidationModel=r,this._initSnapshot()}_initSnapshot(){const a=r=>{const t=this._dataValidationModel.getUnitRules(r),n={};return t?(t.forEach(([d,s])=>{n[d]=s}),JSON.stringify(n)):""},e=r=>{if(!r)return{};try{return JSON.parse(r)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:F,businesses:[o.UniverInstanceType.UNIVER_SHEET],toJson:r=>a(r),parseJson:r=>e(r),onUnLoad:r=>{this._dataValidationModel.deleteUnitRules(r)},onLoad:(r,t)=>{Object.keys(t).forEach(n=>{t[n].forEach(s=>{this._dataValidationModel.addRule(r,n,s,"patched")})})}}))}};exports.DataValidationResourceController=Q([T(0,o.IResourceManagerService),T(1,o.IUniverInstanceService),T(2,o.Inject(exports.DataValidationModel))],exports.DataValidationResourceController);var L=(i=>(i.SHEET="sheet",i))(L||{});class R{constructor(){p(this,"_validatorByScopes",new Map);p(this,"_validatorMap",new Map);p(this,"_validatorsChange$",new D.BehaviorSubject(void 0));p(this,"validatorsChange$",this._validatorsChange$.asObservable())}_addValidatorToScope(a,e){this._validatorByScopes.has(e)||this._validatorByScopes.set(e,[]);const r=this._validatorByScopes.get(e);if(r.findIndex(t=>t.id===a.id)>-1)throw new Error(`Validator item with the same id ${a.id} has already been added!`);r.push(a)}_removeValidatorFromScope(a,e){const r=this._validatorByScopes.get(e);if(!r)return;const t=r.findIndex(n=>n.id===a.id);t>-1&&r.splice(t,1)}register(a){return this._validatorMap.set(a.id,a),Array.isArray(a.scopes)?a.scopes.forEach(e=>{this._addValidatorToScope(a,e)}):this._addValidatorToScope(a,a.scopes),this._validatorsChange$.next(),o.toDisposable(()=>{this._validatorMap.delete(a.id),Array.isArray(a.scopes)?a.scopes.forEach(e=>{this._removeValidatorFromScope(a,e)}):this._removeValidatorFromScope(a,a.scopes),this._validatorsChange$.next()})}getValidatorItem(a){return this._validatorMap.get(a)}getValidatorsByScope(a){return this._validatorByScopes.get(a)}}const E={type:o.CommandType.MUTATION,id:"data-validation.mutation.addRule",handler(i,a){if(!a)return!1;const{unitId:e,subUnitId:r,rule:t,index:n,source:d="command"}=a;return i.get(exports.DataValidationModel).addRule(e,r,t,d,n),!0}},V={type:o.CommandType.MUTATION,id:"data-validation.mutation.removeRule",handler(i,a){if(!a)return!1;const{unitId:e,subUnitId:r,ruleId:t,source:n="command"}=a,d=i.get(exports.DataValidationModel);return Array.isArray(t)?t.forEach(s=>{d.removeRule(e,r,s,n)}):d.removeRule(e,r,t,n),!0}},_={type:o.CommandType.MUTATION,id:"data-validation.mutation.updateRule",handler(i,a){if(!a)return!1;const{unitId:e,subUnitId:r,ruleId:t,payload:n,source:d="command"}=a;return i.get(exports.DataValidationModel).updateRule(e,r,t,n,d),!0}},W={type:o.CommandType.COMMAND,id:"data-validation.command.addRule",async handler(i,a){if(i.get(o.ILogService).error("[Deprecated]: `AddDataValidationCommand` is deprecated, please use `AddSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"),!a)return!1;const{rule:r,unitId:t,subUnitId:n}=a,d=i.get(o.ICommandService),s=i.get(o.IUndoRedoService),u={...a,rule:{...a.rule,ranges:[a.rule.range]}},l=[{id:E.id,params:u}],c=[{id:V.id,params:{unitId:t,subUnitId:n,ruleId:r.uid}}];return s.pushUndoRedo({unitID:t,redoMutations:l,undoMutations:c}),await d.executeCommand(E.id,u),!0}},J={type:o.CommandType.COMMAND,id:"data-validation.command.removeRule",handler(i,a){if(i.get(o.ILogService).error("[Deprecated]: `RemoveDataValidationCommand` is deprecated, please use `RemoveSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"),!a)return!1;const{unitId:r,subUnitId:t,ruleId:n}=a,d=i.get(o.ICommandService),s=i.get(o.IUndoRedoService),u=i.get(exports.DataValidationModel),l=[{id:V.id,params:a}],c=[{id:E.id,params:{unitId:r,subUnitId:t,rule:{...u.getRuleById(r,t,n)},index:u.getRuleIndex(r,t,n)}}];return s.pushUndoRedo({undoMutations:c,redoMutations:l,unitID:a.unitId}),d.executeCommand(V.id,a),!0}},z={type:o.CommandType.COMMAND,id:"data-validation.command.updateDataValidationSetting",handler(i,a){if(i.get(o.ILogService).warn("[Deprecated]: `UpdateDataValidationOptionsCommand` is deprecated, please use `UpdateSheetDataValidationOptionsCommand` in `@univerjs/sheets-data-validation` instead!"),!a)return!1;const r=i.get(o.ICommandService),t=i.get(o.IUndoRedoService),n=i.get(exports.DataValidationModel),{unitId:d,subUnitId:s,ruleId:u,options:l}=a,c=n.getRuleById(d,s,u);if(!c)return!1;const h={unitId:d,subUnitId:s,ruleId:u,payload:{type:m.OPTIONS,payload:l}},g=[{id:_.id,params:h}],v={unitId:d,subUnitId:s,ruleId:u,payload:{type:m.OPTIONS,payload:M(c)}},f=[{id:_.id,params:v}];return t.pushUndoRedo({unitID:d,redoMutations:g,undoMutations:f}),r.executeCommand(_.id,h),!0}},K={type:o.CommandType.COMMAND,id:"data-validation.command.updateDataValidationOptions",handler(i,a){if(i.get(o.ILogService).error("[Deprecated]: `UpdateDataValidationSettingCommand` is deprecated, please use `UpdateSheetDataValidationSettingCommand` in `@univerjs/sheets-data-validation` instead!"),!a)return!1;const r=i.get(o.ICommandService),t=i.get(o.IUndoRedoService),n=i.get(exports.DataValidationModel),d=i.get(R),{unitId:s,subUnitId:u,ruleId:l,setting:c}=a,h=d.getValidatorItem(c.type);if(!h)return!1;const g=n.getRuleById(s,u,l);if(!g)return!1;const v={...g,...c};if(!h.validatorFormula(v,s,u).success)return!1;const f={unitId:s,subUnitId:u,ruleId:l,payload:{type:m.SETTING,payload:{...c,...h.normalizeFormula(v,s,u)}}},C=[{id:_.id,params:f}],b={unitId:s,subUnitId:u,ruleId:l,payload:{type:m.SETTING,payload:N(g)}},w=[{id:_.id,params:b}];return t.pushUndoRedo({unitID:s,redoMutations:C,undoMutations:w}),r.executeCommand(_.id,f),!0}},Y={type:o.CommandType.COMMAND,id:"data-validation.command.removeAll",handler(i,a){if(i.get(o.ILogService).error("[Deprecated]: `RemoveAllDataValidationCommand` is deprecated, please use `RemoveSheetAllDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"),!a)return!1;const{unitId:r,subUnitId:t}=a,n=i.get(o.ICommandService),d=i.get(exports.DataValidationModel),s=i.get(o.IUndoRedoService),u=[...d.getRules(r,t)],l={unitId:r,subUnitId:t,ruleId:u.map(g=>g.uid)},c=[{id:V.id,params:l}],h=[{id:E.id,params:{unitId:r,subUnitId:t,rule:u}}];return s.pushUndoRedo({redoMutations:c,undoMutations:h,unitID:r}),n.executeCommand(V.id,l),!0}},X="data-validation.config",A={};var Z=Object.defineProperty,k=Object.getOwnPropertyDescriptor,aa=(i,a,e,r)=>{for(var t=r>1?void 0:r?k(a,e):a,n=i.length-1,d;n>=0;n--)(d=i[n])&&(t=(r?d(a,e,t):d(t))||t);return r&&t&&Z(a,e,t),t},S=(i,a)=>(e,r)=>a(e,r,i);const ta="UNIVER_DATA_VALIDATION_PLUGIN";var O;exports.UniverDataValidationPlugin=(O=class extends o.Plugin{constructor(a=A,e,r,t){super(),this._config=a,this._injector=e,this._commandService=r,this._configService=t;const{...n}=o.merge({},A,this._config);this._configService.setConfig(X,n)}onStarting(){[[exports.DataValidationModel],[R],[exports.DataValidationResourceController]].forEach(a=>this._injector.add(a)),[W,Y,z,K,J,E,_,V].forEach(a=>{this._commandService.registerCommand(a)})}onReady(){this._injector.get(exports.DataValidationResourceController)}},p(O,"pluginName",ta),p(O,"type",o.UniverInstanceType.UNIVER_SHEET),O);exports.UniverDataValidationPlugin=aa([S(1,o.Inject(o.Injector)),S(2,o.ICommandService),S(3,o.IConfigService)],exports.UniverDataValidationPlugin);o.DataValidationOperator.BETWEEN+"",o.DataValidationOperator.EQUAL+"",o.DataValidationOperator.GREATER_THAN+"",o.DataValidationOperator.GREATER_THAN_OR_EQUAL+"",o.DataValidationOperator.LESS_THAN+"",o.DataValidationOperator.LESS_THAN_OR_EQUAL+"",o.DataValidationOperator.NOT_BETWEEN+"",o.DataValidationOperator.NOT_EQUAL+"";const ea={[o.DataValidationOperator.BETWEEN]:"dataValidation.ruleName.between",[o.DataValidationOperator.EQUAL]:"dataValidation.ruleName.equal",[o.DataValidationOperator.GREATER_THAN]:"dataValidation.ruleName.greaterThan",[o.DataValidationOperator.GREATER_THAN_OR_EQUAL]:"dataValidation.ruleName.greaterThanOrEqual",[o.DataValidationOperator.LESS_THAN]:"dataValidation.ruleName.lessThan",[o.DataValidationOperator.LESS_THAN_OR_EQUAL]:"dataValidation.ruleName.lessThanOrEqual",[o.DataValidationOperator.NOT_BETWEEN]:"dataValidation.ruleName.notBetween",[o.DataValidationOperator.NOT_EQUAL]:"dataValidation.ruleName.notEqual"},ra={[o.DataValidationOperator.BETWEEN]:"dataValidation.errorMsg.between",[o.DataValidationOperator.EQUAL]:"dataValidation.errorMsg.equal",[o.DataValidationOperator.GREATER_THAN]:"dataValidation.errorMsg.greaterThan",[o.DataValidationOperator.GREATER_THAN_OR_EQUAL]:"dataValidation.errorMsg.greaterThanOrEqual",[o.DataValidationOperator.LESS_THAN]:"dataValidation.errorMsg.lessThan",[o.DataValidationOperator.LESS_THAN_OR_EQUAL]:"dataValidation.errorMsg.lessThanOrEqual",[o.DataValidationOperator.NOT_BETWEEN]:"dataValidation.errorMsg.notBetween",[o.DataValidationOperator.NOT_EQUAL]:"dataValidation.errorMsg.notEqual"},oa={[o.DataValidationOperator.BETWEEN]:"dataValidation.textLength.errorMsg.between",[o.DataValidationOperator.EQUAL]:"dataValidation.textLength.errorMsg.equal",[o.DataValidationOperator.GREATER_THAN]:"dataValidation.textLength.errorMsg.greaterThan",[o.DataValidationOperator.GREATER_THAN_OR_EQUAL]:"dataValidation.textLength.errorMsg.greaterThanOrEqual",[o.DataValidationOperator.LESS_THAN]:"dataValidation.textLength.errorMsg.lessThan",[o.DataValidationOperator.LESS_THAN_OR_EQUAL]:"dataValidation.textLength.errorMsg.lessThanOrEqual",[o.DataValidationOperator.NOT_BETWEEN]:"dataValidation.textLength.errorMsg.notBetween",[o.DataValidationOperator.NOT_EQUAL]:"dataValidation.textLength.errorMsg.notEqual"},ia=[o.DataValidationOperator.BETWEEN,o.DataValidationOperator.NOT_BETWEEN];var na=Object.defineProperty,da=Object.getOwnPropertyDescriptor,sa=(i,a,e,r)=>{for(var t=r>1?void 0:r?da(a,e):a,n=i.length-1,d;n>=0;n--)(d=i[n])&&(t=(r?d(a,e,t):d(t))||t);return r&&t&&na(a,e,t),t},I=(i,a)=>(e,r)=>a(e,r,i);const y="{FORMULA1}",U="{FORMULA2}",la={[o.DataValidationOperator.BETWEEN]:"dataValidation.operators.between",[o.DataValidationOperator.EQUAL]:"dataValidation.operators.equal",[o.DataValidationOperator.GREATER_THAN]:"dataValidation.operators.greaterThan",[o.DataValidationOperator.GREATER_THAN_OR_EQUAL]:"dataValidation.operators.greaterThanOrEqual",[o.DataValidationOperator.LESS_THAN]:"dataValidation.operators.lessThan",[o.DataValidationOperator.LESS_THAN_OR_EQUAL]:"dataValidation.operators.lessThanOrEqual",[o.DataValidationOperator.NOT_BETWEEN]:"dataValidation.operators.notBetween",[o.DataValidationOperator.NOT_EQUAL]:"dataValidation.operators.notEqual"};exports.BaseDataValidator=class{constructor(a,e){p(this,"offsetFormulaByRange",!0);p(this,"formulaInput");p(this,"canvasRender",null);p(this,"dropdown");p(this,"optionsInput");p(this,"skipDefaultFontRender");this.localeService=a,this.injector=e}get operatorNames(){return this.operators.map(a=>this.localeService.t(la[a]))}get titleStr(){return this.localeService.t(this.title)}generateRuleName(a){var r,t;if(!a.operator)return this.titleStr;const e=this.localeService.t(ea[a.operator]).replace(y,(r=a.formula1)!=null?r:"").replace(U,(t=a.formula2)!=null?t:"");return`${this.titleStr} ${e}`}generateRuleErrorMessage(a,e){var t,n;return a.operator?`${this.localeService.t(ra[a.operator]).replace(y,(t=a.formula1)!=null?t:"").replace(U,(n=a.formula2)!=null?n:"")}`:this.titleStr}getExtraStyle(a,e,r,t,n){}getRuleFinalError(a,e){return a.showErrorMessage&&a.error?a.error:this.generateRuleErrorMessage(a,e)}isEmptyCellValue(a){return a===""||a===void 0||a===null}normalizeFormula(a,e,r){return{formula1:a.formula1,formula2:a.formula2}}async isValidType(a,e,r){return!0}transform(a,e,r){return a}async validatorIsEqual(a,e,r){const{formula1:t}=e,{value:n}=a;return Number.isNaN(t)?!0:n===t}async validatorIsNotEqual(a,e,r){const{formula1:t}=e;return Number.isNaN(t)?!0:a.value!==t}async validatorIsBetween(a,e,r){const{formula1:t,formula2:n}=e;if(Number.isNaN(t)||Number.isNaN(n))return!0;const d=Math.min(t,n),s=Math.max(t,n);return a.value>=d&&a.value<=s}async validatorIsNotBetween(a,e,r){const{formula1:t,formula2:n}=e;if(Number.isNaN(t)||Number.isNaN(n))return!0;const d=Math.min(t,n),s=Math.max(t,n);return a.value<d||a.value>s}async validatorIsGreaterThan(a,e,r){const{formula1:t}=e;return Number.isNaN(t)?!0:a.value>t}async validatorIsGreaterThanOrEqual(a,e,r){const{formula1:t}=e;return Number.isNaN(t)?!0:a.value>=t}async validatorIsLessThan(a,e,r){const{formula1:t}=e;return Number.isNaN(t)?!0:a.value<t}async validatorIsLessThanOrEqual(a,e,r){const{formula1:t}=e;return Number.isNaN(t)?!0:a.value<=t}async validator(a,e){const{value:r,unitId:t,subUnitId:n}=a,d=this.isEmptyCellValue(r),{allowBlank:s=!0,operator:u}=e;if(d)return s;const l=await this.parseFormula(e,t,n,a.row,a.column);if(!l.isFormulaValid||!await this.isValidType(a,l,e))return!1;if(!o.Tools.isDefine(u))return!0;const c=this.transform(a,l,e);switch(u){case o.DataValidationOperator.BETWEEN:return this.validatorIsBetween(c,l,e);case o.DataValidationOperator.EQUAL:return this.validatorIsEqual(c,l,e);case o.DataValidationOperator.GREATER_THAN:return this.validatorIsGreaterThan(c,l,e);case o.DataValidationOperator.GREATER_THAN_OR_EQUAL:return this.validatorIsGreaterThanOrEqual(c,l,e);case o.DataValidationOperator.LESS_THAN:return this.validatorIsLessThan(c,l,e);case o.DataValidationOperator.LESS_THAN_OR_EQUAL:return this.validatorIsLessThanOrEqual(c,l,e);case o.DataValidationOperator.NOT_BETWEEN:return this.validatorIsNotBetween(c,l,e);case o.DataValidationOperator.NOT_EQUAL:return this.validatorIsNotEqual(c,l,e);default:throw new Error("Unknown operator.")}}};exports.BaseDataValidator=sa([I(0,o.Inject(o.LocaleService)),I(1,o.Inject(o.Injector))],exports.BaseDataValidator);exports.AddDataValidationMutation=E;exports.DataValidatorRegistryScope=L;exports.DataValidatorRegistryService=R;exports.RemoveDataValidationMutation=V;exports.TWO_FORMULA_OPERATOR_COUNT=ia;exports.TextLengthErrorTitleMap=oa;exports.UpdateDataValidationMutation=_;exports.UpdateRuleType=m;exports.getRuleOptions=M;exports.getRuleSetting=N;
|
|
1
|
+
"use strict";var B=Object.defineProperty;var P=(i,a,e)=>a in i?B(i,a,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[a]=e;var p=(i,a,e)=>P(i,typeof a!="symbol"?a+"":a,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),f=require("rxjs");function N(i){return{type:i.type,operator:i.operator,formula1:i.formula1,formula2:i.formula2,allowBlank:i.allowBlank}}function M(i){return{error:i.error,errorStyle:i.errorStyle,errorTitle:i.errorTitle,imeMode:i.imeMode,prompt:i.prompt,promptTitle:i.promptTitle,showDropDown:i.showDropDown,showErrorMessage:i.showErrorMessage,showInputMessage:i.showInputMessage,renderMode:i.renderMode,bizInfo:i.bizInfo}}var m=(i=>(i[i.SETTING=0]="SETTING",i[i.RANGE=1]="RANGE",i[i.OPTIONS=2]="OPTIONS",i[i.ALL=3]="ALL",i))(m||{}),x=Object.getOwnPropertyDescriptor,q=(i,a,e,r)=>{for(var t=r>1?void 0:r?x(a,e):a,n=i.length-1,d;n>=0;n--)(d=i[n])&&(t=d(t)||t);return t},G=(i,a)=>(e,r)=>a(e,r,i);exports.DataValidationModel=class extends o.Disposable{constructor(e){super();p(this,"_model",new Map);p(this,"_ruleChange$",new f.Subject);p(this,"ruleChange$",this._ruleChange$.asObservable());p(this,"ruleChangeDebounce$",this.ruleChange$.pipe(f.debounceTime(20)));this._logService=e,this.disposeWithMe({dispose:()=>{this._ruleChange$.complete()}})}_ensureMap(e,r){this._model.has(e)||this._model.set(e,new Map);const t=this._model.get(e);if(t.has(r))return t.get(r);const n={map:new Map,list:[]};return t.set(r,n),n}_addSubUnitRule(e,r,t){const{map:n,list:d}=e,u=(Array.isArray(r)?r:[r]).filter(l=>!n.has(l.uid));typeof t=="number"&&t<d.length?d.splice(t,0,...u):d.push(...u),u.forEach(l=>{n.set(l.uid,l)})}_removeSubUnitRule(e,r){const{map:t,list:n}=e,d=n.findIndex(s=>s.uid===r);d>-1&&(n.splice(d,1),t.delete(r))}_updateSubUnitRule(e,r,t){const{map:n,list:d}=e,s=n.get(r),u=d.findIndex(c=>r===c.uid);if(!s)throw new Error(`Data validation rule is not found, ruleId: ${r}.`);const l={...s};switch(t.type){case m.RANGE:{l.ranges=t.payload;break}case m.SETTING:{Object.assign(l,N(t.payload));break}case m.OPTIONS:{Object.assign(l,M(t.payload));break}case m.ALL:{Object.assign(l,t.payload);break}}return d[u]=l,n.set(r,l),l}_addRuleSideEffect(e,r,t,n){if(!this._ensureMap(e,r).map.get(t.uid))return{rule:t,type:"add",unitId:e,subUnitId:r,source:n}}addRule(e,r,t,n,d){try{const s=this._ensureMap(e,r),l=(Array.isArray(t)?t:[t]).map(c=>this._addRuleSideEffect(e,r,c,n));this._addSubUnitRule(s,t,d),l.forEach(c=>{c&&this._ruleChange$.next(c)})}catch(s){this._logService.error(s)}}updateRule(e,r,t,n,d){try{const s=this._ensureMap(e,r),u=o.Tools.deepClone(s.map.get(t));if(!u)throw new Error(`Data validation rule is not found, ruleId: ${t}.`);const l=this._updateSubUnitRule(s,t,n);this._ruleChange$.next({rule:l,type:"update",unitId:e,subUnitId:r,source:d,updatePayload:n,oldRule:u})}catch(s){this._logService.error(s)}}removeRule(e,r,t,n){try{const d=this._ensureMap(e,r),s=d.map.get(t);s&&(this._removeSubUnitRule(d,t),this._ruleChange$.next({rule:s,type:"remove",unitId:e,subUnitId:r,source:n}))}catch(d){this._logService.error(d)}}getRuleById(e,r,t){return this._ensureMap(e,r).map.get(t)}getRuleIndex(e,r,t){return this._ensureMap(e,r).list.findIndex(d=>d.uid===t)}getRules(e,r){return[...this._ensureMap(e,r).list]}getUnitRules(e){const r=this._model.get(e);if(!r)return[];const t=[];return r.forEach((n,d)=>{t.push([d,n.list])}),t}deleteUnitRules(e){this._model.delete(e)}getSubUnitIds(e){var r,t;return Array.from((t=(r=this._model.get(e))==null?void 0:r.keys())!=null?t:[])}getAll(){return Array.from(this._model.keys()).map(e=>[e,this.getUnitRules(e)])}};exports.DataValidationModel=q([G(0,o.ILogService)],exports.DataValidationModel);var $=Object.getOwnPropertyDescriptor,H=(i,a,e,r)=>{for(var t=r>1?void 0:r?$(a,e):a,n=i.length-1,d;n>=0;n--)(d=i[n])&&(t=d(t)||t);return t},S=(i,a)=>(e,r)=>a(e,r,i);const j="SHEET_DATA_VALIDATION_PLUGIN";exports.DataValidationResourceController=class extends o.Disposable{constructor(a,e,r){super(),this._resourceManagerService=a,this._univerInstanceService=e,this._dataValidationModel=r,this._initSnapshot()}_initSnapshot(){const a=r=>{const t=this._dataValidationModel.getUnitRules(r),n={};return t?(t.forEach(([d,s])=>{n[d]=s}),JSON.stringify(n)):""},e=r=>{if(!r)return{};try{return JSON.parse(r)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:j,businesses:[o.UniverInstanceType.UNIVER_SHEET],toJson:r=>a(r),parseJson:r=>e(r),onUnLoad:r=>{this._dataValidationModel.deleteUnitRules(r)},onLoad:(r,t)=>{Object.keys(t).forEach(n=>{t[n].forEach(s=>{this._dataValidationModel.addRule(r,n,s,"patched")})})}}))}};exports.DataValidationResourceController=H([S(0,o.IResourceManagerService),S(1,o.IUniverInstanceService),S(2,o.Inject(exports.DataValidationModel))],exports.DataValidationResourceController);var L=(i=>(i.SHEET="sheet",i))(L||{});class R{constructor(){p(this,"_validatorByScopes",new Map);p(this,"_validatorMap",new Map);p(this,"_validatorsChange$",new f.BehaviorSubject(void 0));p(this,"validatorsChange$",this._validatorsChange$.asObservable())}_addValidatorToScope(a,e){this._validatorByScopes.has(e)||this._validatorByScopes.set(e,[]);const r=this._validatorByScopes.get(e);if(r.findIndex(t=>t.id===a.id)>-1)throw new Error(`Validator item with the same id ${a.id} has already been added!`);r.push(a)}_removeValidatorFromScope(a,e){const r=this._validatorByScopes.get(e);if(!r)return;const t=r.findIndex(n=>n.id===a.id);t>-1&&r.splice(t,1)}register(a){return this._validatorMap.set(a.id,a),Array.isArray(a.scopes)?a.scopes.forEach(e=>{this._addValidatorToScope(a,e)}):this._addValidatorToScope(a,a.scopes),this._validatorsChange$.next(),o.toDisposable(()=>{this._validatorMap.delete(a.id),Array.isArray(a.scopes)?a.scopes.forEach(e=>{this._removeValidatorFromScope(a,e)}):this._removeValidatorFromScope(a,a.scopes),this._validatorsChange$.next()})}getValidatorItem(a){return this._validatorMap.get(a)}getValidatorsByScope(a){return this._validatorByScopes.get(a)}}const E={type:o.CommandType.MUTATION,id:"data-validation.mutation.addRule",handler(i,a){if(!a)return!1;const{unitId:e,subUnitId:r,rule:t,index:n,source:d="command"}=a;return i.get(exports.DataValidationModel).addRule(e,r,t,d,n),!0}},V={type:o.CommandType.MUTATION,id:"data-validation.mutation.removeRule",handler(i,a){if(!a)return!1;const{unitId:e,subUnitId:r,ruleId:t,source:n="command"}=a,d=i.get(exports.DataValidationModel);return Array.isArray(t)?t.forEach(s=>{d.removeRule(e,r,s,n)}):d.removeRule(e,r,t,n),!0}},g={type:o.CommandType.MUTATION,id:"data-validation.mutation.updateRule",handler(i,a){if(!a)return!1;const{unitId:e,subUnitId:r,ruleId:t,payload:n,source:d="command"}=a;return i.get(exports.DataValidationModel).updateRule(e,r,t,n,d),!0}},Q={type:o.CommandType.COMMAND,id:"data-validation.command.addRule",async handler(i,a){if(i.get(o.ILogService).error("[Deprecated]: `AddDataValidationCommand` is deprecated, please use `AddSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"),!a)return!1;const{rule:r,unitId:t,subUnitId:n}=a,d=i.get(o.ICommandService),s=i.get(o.IUndoRedoService),u={...a,rule:{...a.rule,ranges:[a.rule.range]}},l=[{id:E.id,params:u}],c=[{id:V.id,params:{unitId:t,subUnitId:n,ruleId:r.uid}}];return s.pushUndoRedo({unitID:t,redoMutations:l,undoMutations:c}),await d.executeCommand(E.id,u),!0}},F={type:o.CommandType.COMMAND,id:"data-validation.command.removeRule",handler(i,a){if(i.get(o.ILogService).error("[Deprecated]: `RemoveDataValidationCommand` is deprecated, please use `RemoveSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"),!a)return!1;const{unitId:r,subUnitId:t,ruleId:n}=a,d=i.get(o.ICommandService),s=i.get(o.IUndoRedoService),u=i.get(exports.DataValidationModel),l=[{id:V.id,params:a}],c=[{id:E.id,params:{unitId:r,subUnitId:t,rule:{...u.getRuleById(r,t,n)},index:u.getRuleIndex(r,t,n)}}];return s.pushUndoRedo({undoMutations:c,redoMutations:l,unitID:a.unitId}),d.executeCommand(V.id,a),!0}},W={type:o.CommandType.COMMAND,id:"data-validation.command.updateDataValidationSetting",handler(i,a){if(i.get(o.ILogService).warn("[Deprecated]: `UpdateDataValidationOptionsCommand` is deprecated, please use `UpdateSheetDataValidationOptionsCommand` in `@univerjs/sheets-data-validation` instead!"),!a)return!1;const r=i.get(o.ICommandService),t=i.get(o.IUndoRedoService),n=i.get(exports.DataValidationModel),{unitId:d,subUnitId:s,ruleId:u,options:l}=a,c=n.getRuleById(d,s,u);if(!c)return!1;const h={unitId:d,subUnitId:s,ruleId:u,payload:{type:m.OPTIONS,payload:l}},_=[{id:g.id,params:h}],v={unitId:d,subUnitId:s,ruleId:u,payload:{type:m.OPTIONS,payload:M(c)}},O=[{id:g.id,params:v}];return t.pushUndoRedo({unitID:d,redoMutations:_,undoMutations:O}),r.executeCommand(g.id,h),!0}},k={type:o.CommandType.COMMAND,id:"data-validation.command.updateDataValidationOptions",handler(i,a){if(i.get(o.ILogService).error("[Deprecated]: `UpdateDataValidationSettingCommand` is deprecated, please use `UpdateSheetDataValidationSettingCommand` in `@univerjs/sheets-data-validation` instead!"),!a)return!1;const r=i.get(o.ICommandService),t=i.get(o.IUndoRedoService),n=i.get(exports.DataValidationModel),d=i.get(R),{unitId:s,subUnitId:u,ruleId:l,setting:c}=a,h=d.getValidatorItem(c.type);if(!h)return!1;const _=n.getRuleById(s,u,l);if(!_)return!1;const v={..._,...c};if(!h.validatorFormula(v,s,u).success)return!1;const O={unitId:s,subUnitId:u,ruleId:l,payload:{type:m.SETTING,payload:{...c,...h.normalizeFormula(v,s,u)}}},C=[{id:g.id,params:O}],w={unitId:s,subUnitId:u,ruleId:l,payload:{type:m.SETTING,payload:N(_)}},b=[{id:g.id,params:w}];return t.pushUndoRedo({unitID:s,redoMutations:C,undoMutations:b}),r.executeCommand(g.id,O),!0}},J={type:o.CommandType.COMMAND,id:"data-validation.command.removeAll",handler(i,a){if(i.get(o.ILogService).error("[Deprecated]: `RemoveAllDataValidationCommand` is deprecated, please use `RemoveSheetAllDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"),!a)return!1;const{unitId:r,subUnitId:t}=a,n=i.get(o.ICommandService),d=i.get(exports.DataValidationModel),s=i.get(o.IUndoRedoService),u=[...d.getRules(r,t)],l={unitId:r,subUnitId:t,ruleId:u.map(_=>_.uid)},c=[{id:V.id,params:l}],h=[{id:E.id,params:{unitId:r,subUnitId:t,rule:u}}];return s.pushUndoRedo({redoMutations:c,undoMutations:h,unitID:r}),n.executeCommand(V.id,l),!0}},z="data-validation.config",A={};var K=Object.getOwnPropertyDescriptor,Y=(i,a,e,r)=>{for(var t=r>1?void 0:r?K(a,e):a,n=i.length-1,d;n>=0;n--)(d=i[n])&&(t=d(t)||t);return t},D=(i,a)=>(e,r)=>a(e,r,i);const X="UNIVER_DATA_VALIDATION_PLUGIN";var T;exports.UniverDataValidationPlugin=(T=class extends o.Plugin{constructor(a=A,e,r,t){super(),this._config=a,this._injector=e,this._commandService=r,this._configService=t;const{...n}=o.merge({},A,this._config);this._configService.setConfig(z,n)}onStarting(){[[exports.DataValidationModel],[R],[exports.DataValidationResourceController]].forEach(a=>this._injector.add(a)),[Q,J,W,k,F,E,g,V].forEach(a=>{this._commandService.registerCommand(a)})}onReady(){this._injector.get(exports.DataValidationResourceController)}},p(T,"pluginName",X),p(T,"type",o.UniverInstanceType.UNIVER_SHEET),T);exports.UniverDataValidationPlugin=Y([D(1,o.Inject(o.Injector)),D(2,o.ICommandService),D(3,o.IConfigService)],exports.UniverDataValidationPlugin);o.DataValidationOperator.BETWEEN+"",o.DataValidationOperator.EQUAL+"",o.DataValidationOperator.GREATER_THAN+"",o.DataValidationOperator.GREATER_THAN_OR_EQUAL+"",o.DataValidationOperator.LESS_THAN+"",o.DataValidationOperator.LESS_THAN_OR_EQUAL+"",o.DataValidationOperator.NOT_BETWEEN+"",o.DataValidationOperator.NOT_EQUAL+"";const Z={[o.DataValidationOperator.BETWEEN]:"dataValidation.ruleName.between",[o.DataValidationOperator.EQUAL]:"dataValidation.ruleName.equal",[o.DataValidationOperator.GREATER_THAN]:"dataValidation.ruleName.greaterThan",[o.DataValidationOperator.GREATER_THAN_OR_EQUAL]:"dataValidation.ruleName.greaterThanOrEqual",[o.DataValidationOperator.LESS_THAN]:"dataValidation.ruleName.lessThan",[o.DataValidationOperator.LESS_THAN_OR_EQUAL]:"dataValidation.ruleName.lessThanOrEqual",[o.DataValidationOperator.NOT_BETWEEN]:"dataValidation.ruleName.notBetween",[o.DataValidationOperator.NOT_EQUAL]:"dataValidation.ruleName.notEqual"},aa={[o.DataValidationOperator.BETWEEN]:"dataValidation.errorMsg.between",[o.DataValidationOperator.EQUAL]:"dataValidation.errorMsg.equal",[o.DataValidationOperator.GREATER_THAN]:"dataValidation.errorMsg.greaterThan",[o.DataValidationOperator.GREATER_THAN_OR_EQUAL]:"dataValidation.errorMsg.greaterThanOrEqual",[o.DataValidationOperator.LESS_THAN]:"dataValidation.errorMsg.lessThan",[o.DataValidationOperator.LESS_THAN_OR_EQUAL]:"dataValidation.errorMsg.lessThanOrEqual",[o.DataValidationOperator.NOT_BETWEEN]:"dataValidation.errorMsg.notBetween",[o.DataValidationOperator.NOT_EQUAL]:"dataValidation.errorMsg.notEqual"},ta={[o.DataValidationOperator.BETWEEN]:"dataValidation.textLength.errorMsg.between",[o.DataValidationOperator.EQUAL]:"dataValidation.textLength.errorMsg.equal",[o.DataValidationOperator.GREATER_THAN]:"dataValidation.textLength.errorMsg.greaterThan",[o.DataValidationOperator.GREATER_THAN_OR_EQUAL]:"dataValidation.textLength.errorMsg.greaterThanOrEqual",[o.DataValidationOperator.LESS_THAN]:"dataValidation.textLength.errorMsg.lessThan",[o.DataValidationOperator.LESS_THAN_OR_EQUAL]:"dataValidation.textLength.errorMsg.lessThanOrEqual",[o.DataValidationOperator.NOT_BETWEEN]:"dataValidation.textLength.errorMsg.notBetween",[o.DataValidationOperator.NOT_EQUAL]:"dataValidation.textLength.errorMsg.notEqual"},ea=[o.DataValidationOperator.BETWEEN,o.DataValidationOperator.NOT_BETWEEN];var ra=Object.getOwnPropertyDescriptor,oa=(i,a,e,r)=>{for(var t=r>1?void 0:r?ra(a,e):a,n=i.length-1,d;n>=0;n--)(d=i[n])&&(t=d(t)||t);return t},I=(i,a)=>(e,r)=>a(e,r,i);const y="{FORMULA1}",U="{FORMULA2}",ia={[o.DataValidationOperator.BETWEEN]:"dataValidation.operators.between",[o.DataValidationOperator.EQUAL]:"dataValidation.operators.equal",[o.DataValidationOperator.GREATER_THAN]:"dataValidation.operators.greaterThan",[o.DataValidationOperator.GREATER_THAN_OR_EQUAL]:"dataValidation.operators.greaterThanOrEqual",[o.DataValidationOperator.LESS_THAN]:"dataValidation.operators.lessThan",[o.DataValidationOperator.LESS_THAN_OR_EQUAL]:"dataValidation.operators.lessThanOrEqual",[o.DataValidationOperator.NOT_BETWEEN]:"dataValidation.operators.notBetween",[o.DataValidationOperator.NOT_EQUAL]:"dataValidation.operators.notEqual"};exports.BaseDataValidator=class{constructor(a,e){p(this,"offsetFormulaByRange",!0);p(this,"formulaInput");p(this,"canvasRender",null);p(this,"dropdown");p(this,"optionsInput");p(this,"skipDefaultFontRender");this.localeService=a,this.injector=e}get operatorNames(){return this.operators.map(a=>this.localeService.t(ia[a]))}get titleStr(){return this.localeService.t(this.title)}generateRuleName(a){var r,t;if(!a.operator)return this.titleStr;const e=this.localeService.t(Z[a.operator]).replace(y,(r=a.formula1)!=null?r:"").replace(U,(t=a.formula2)!=null?t:"");return`${this.titleStr} ${e}`}generateRuleErrorMessage(a,e){var t,n;return a.operator?`${this.localeService.t(aa[a.operator]).replace(y,(t=a.formula1)!=null?t:"").replace(U,(n=a.formula2)!=null?n:"")}`:this.titleStr}getExtraStyle(a,e,r,t,n){}getRuleFinalError(a,e){return a.showErrorMessage&&a.error?a.error:this.generateRuleErrorMessage(a,e)}isEmptyCellValue(a){return a===""||a===void 0||a===null}normalizeFormula(a,e,r){return{formula1:a.formula1,formula2:a.formula2}}async isValidType(a,e,r){return!0}transform(a,e,r){return a}async validatorIsEqual(a,e,r){const{formula1:t}=e,{value:n}=a;return Number.isNaN(t)?!0:n===t}async validatorIsNotEqual(a,e,r){const{formula1:t}=e;return Number.isNaN(t)?!0:a.value!==t}async validatorIsBetween(a,e,r){const{formula1:t,formula2:n}=e;if(Number.isNaN(t)||Number.isNaN(n))return!0;const d=Math.min(t,n),s=Math.max(t,n);return a.value>=d&&a.value<=s}async validatorIsNotBetween(a,e,r){const{formula1:t,formula2:n}=e;if(Number.isNaN(t)||Number.isNaN(n))return!0;const d=Math.min(t,n),s=Math.max(t,n);return a.value<d||a.value>s}async validatorIsGreaterThan(a,e,r){const{formula1:t}=e;return Number.isNaN(t)?!0:a.value>t}async validatorIsGreaterThanOrEqual(a,e,r){const{formula1:t}=e;return Number.isNaN(t)?!0:a.value>=t}async validatorIsLessThan(a,e,r){const{formula1:t}=e;return Number.isNaN(t)?!0:a.value<t}async validatorIsLessThanOrEqual(a,e,r){const{formula1:t}=e;return Number.isNaN(t)?!0:a.value<=t}async validator(a,e){const{value:r,unitId:t,subUnitId:n}=a,d=this.isEmptyCellValue(r),{allowBlank:s=!0,operator:u}=e;if(d)return s;const l=await this.parseFormula(e,t,n,a.row,a.column);if(!l.isFormulaValid||!await this.isValidType(a,l,e))return!1;if(!o.Tools.isDefine(u))return!0;const c=this.transform(a,l,e);switch(u){case o.DataValidationOperator.BETWEEN:return this.validatorIsBetween(c,l,e);case o.DataValidationOperator.EQUAL:return this.validatorIsEqual(c,l,e);case o.DataValidationOperator.GREATER_THAN:return this.validatorIsGreaterThan(c,l,e);case o.DataValidationOperator.GREATER_THAN_OR_EQUAL:return this.validatorIsGreaterThanOrEqual(c,l,e);case o.DataValidationOperator.LESS_THAN:return this.validatorIsLessThan(c,l,e);case o.DataValidationOperator.LESS_THAN_OR_EQUAL:return this.validatorIsLessThanOrEqual(c,l,e);case o.DataValidationOperator.NOT_BETWEEN:return this.validatorIsNotBetween(c,l,e);case o.DataValidationOperator.NOT_EQUAL:return this.validatorIsNotEqual(c,l,e);default:throw new Error("Unknown operator.")}}};exports.BaseDataValidator=oa([I(0,o.Inject(o.LocaleService)),I(1,o.Inject(o.Injector))],exports.BaseDataValidator);exports.AddDataValidationMutation=E;exports.DataValidatorRegistryScope=L;exports.DataValidatorRegistryService=R;exports.RemoveDataValidationMutation=V;exports.TWO_FORMULA_OPERATOR_COUNT=ea;exports.TextLengthErrorTitleMap=ta;exports.UpdateDataValidationMutation=g;exports.UpdateRuleType=m;exports.getRuleOptions=M;exports.getRuleSetting=N;
|
package/lib/es/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var c = (t, e, r) =>
|
|
4
|
-
import { Disposable as
|
|
1
|
+
var k = Object.defineProperty;
|
|
2
|
+
var J = (t, e, r) => e in t ? k(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
|
|
3
|
+
var c = (t, e, r) => J(t, typeof e != "symbol" ? e + "" : e, r);
|
|
4
|
+
import { Disposable as x, Tools as P, ILogService as N, IResourceManagerService as z, IUniverInstanceService as K, Inject as O, UniverInstanceType as G, toDisposable as Y, CommandType as g, ICommandService as T, IUndoRedoService as A, Plugin as X, merge as Z, Injector as $, IConfigService as ee, DataValidationOperator as s, LocaleService as te } from "@univerjs/core";
|
|
5
5
|
import { Subject as ae, debounceTime as re, BehaviorSubject as oe } from "rxjs";
|
|
6
6
|
function q(t) {
|
|
7
7
|
return {
|
|
@@ -27,12 +27,12 @@ function H(t) {
|
|
|
27
27
|
bizInfo: t.bizInfo
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
|
-
var h = /* @__PURE__ */ ((t) => (t[t.SETTING = 0] = "SETTING", t[t.RANGE = 1] = "RANGE", t[t.OPTIONS = 2] = "OPTIONS", t[t.ALL = 3] = "ALL", t))(h || {}), ne = Object.
|
|
31
|
-
for (var o = a > 1 ? void 0 : a ?
|
|
32
|
-
(i = t[n]) && (o =
|
|
33
|
-
return
|
|
34
|
-
},
|
|
35
|
-
let
|
|
30
|
+
var h = /* @__PURE__ */ ((t) => (t[t.SETTING = 0] = "SETTING", t[t.RANGE = 1] = "RANGE", t[t.OPTIONS = 2] = "OPTIONS", t[t.ALL = 3] = "ALL", t))(h || {}), ne = Object.getOwnPropertyDescriptor, ie = (t, e, r, a) => {
|
|
31
|
+
for (var o = a > 1 ? void 0 : a ? ne(e, r) : e, n = t.length - 1, i; n >= 0; n--)
|
|
32
|
+
(i = t[n]) && (o = i(o) || o);
|
|
33
|
+
return o;
|
|
34
|
+
}, se = (t, e) => (r, a) => e(r, a, t);
|
|
35
|
+
let p = class extends x {
|
|
36
36
|
constructor(e) {
|
|
37
37
|
super();
|
|
38
38
|
c(this, "_model", /* @__PURE__ */ new Map());
|
|
@@ -110,7 +110,7 @@ let m = class extends B {
|
|
|
110
110
|
}
|
|
111
111
|
updateRule(e, r, a, o, n) {
|
|
112
112
|
try {
|
|
113
|
-
const i = this._ensureMap(e, r), l =
|
|
113
|
+
const i = this._ensureMap(e, r), l = P.deepClone(i.map.get(a));
|
|
114
114
|
if (!l)
|
|
115
115
|
throw new Error(`Data validation rule is not found, ruleId: ${a}.`);
|
|
116
116
|
const d = this._updateSubUnitRule(i, a, o);
|
|
@@ -170,16 +170,16 @@ let m = class extends B {
|
|
|
170
170
|
return Array.from(this._model.keys()).map((e) => [e, this.getUnitRules(e)]);
|
|
171
171
|
}
|
|
172
172
|
};
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
],
|
|
176
|
-
var
|
|
177
|
-
for (var o = a > 1 ? void 0 : a ?
|
|
178
|
-
(i = t[n]) && (o =
|
|
179
|
-
return
|
|
173
|
+
p = ie([
|
|
174
|
+
se(0, N)
|
|
175
|
+
], p);
|
|
176
|
+
var de = Object.getOwnPropertyDescriptor, le = (t, e, r, a) => {
|
|
177
|
+
for (var o = a > 1 ? void 0 : a ? de(e, r) : e, n = t.length - 1, i; n >= 0; n--)
|
|
178
|
+
(i = t[n]) && (o = i(o) || o);
|
|
179
|
+
return o;
|
|
180
180
|
}, y = (t, e) => (r, a) => e(r, a, t);
|
|
181
|
-
const
|
|
182
|
-
let I = class extends
|
|
181
|
+
const ue = "SHEET_DATA_VALIDATION_PLUGIN";
|
|
182
|
+
let I = class extends x {
|
|
183
183
|
constructor(t, e, r) {
|
|
184
184
|
super(), this._resourceManagerService = t, this._univerInstanceService = e, this._dataValidationModel = r, this._initSnapshot();
|
|
185
185
|
}
|
|
@@ -200,8 +200,8 @@ let I = class extends B {
|
|
|
200
200
|
};
|
|
201
201
|
this.disposeWithMe(
|
|
202
202
|
this._resourceManagerService.registerPluginResource({
|
|
203
|
-
pluginName:
|
|
204
|
-
businesses: [
|
|
203
|
+
pluginName: ue,
|
|
204
|
+
businesses: [G.UNIVER_SHEET],
|
|
205
205
|
toJson: (r) => t(r),
|
|
206
206
|
parseJson: (r) => e(r),
|
|
207
207
|
onUnLoad: (r) => {
|
|
@@ -218,13 +218,13 @@ let I = class extends B {
|
|
|
218
218
|
);
|
|
219
219
|
}
|
|
220
220
|
};
|
|
221
|
-
I =
|
|
222
|
-
y(0,
|
|
223
|
-
y(1,
|
|
224
|
-
y(2, O(
|
|
221
|
+
I = le([
|
|
222
|
+
y(0, z),
|
|
223
|
+
y(1, K),
|
|
224
|
+
y(2, O(p))
|
|
225
225
|
], I);
|
|
226
|
-
var
|
|
227
|
-
class
|
|
226
|
+
var ce = /* @__PURE__ */ ((t) => (t.SHEET = "sheet", t))(ce || {});
|
|
227
|
+
class Q {
|
|
228
228
|
constructor() {
|
|
229
229
|
c(this, "_validatorByScopes", /* @__PURE__ */ new Map());
|
|
230
230
|
c(this, "_validatorMap", /* @__PURE__ */ new Map());
|
|
@@ -248,7 +248,7 @@ class j {
|
|
|
248
248
|
register(e) {
|
|
249
249
|
return this._validatorMap.set(e.id, e), Array.isArray(e.scopes) ? e.scopes.forEach((r) => {
|
|
250
250
|
this._addValidatorToScope(e, r);
|
|
251
|
-
}) : this._addValidatorToScope(e, e.scopes), this._validatorsChange$.next(),
|
|
251
|
+
}) : this._addValidatorToScope(e, e.scopes), this._validatorsChange$.next(), Y(() => {
|
|
252
252
|
this._validatorMap.delete(e.id), Array.isArray(e.scopes) ? e.scopes.forEach((r) => {
|
|
253
253
|
this._removeValidatorFromScope(e, r);
|
|
254
254
|
}) : this._removeValidatorFromScope(e, e.scopes), this._validatorsChange$.next();
|
|
@@ -262,36 +262,36 @@ class j {
|
|
|
262
262
|
}
|
|
263
263
|
}
|
|
264
264
|
const S = {
|
|
265
|
-
type:
|
|
265
|
+
type: g.MUTATION,
|
|
266
266
|
id: "data-validation.mutation.addRule",
|
|
267
267
|
handler(t, e) {
|
|
268
268
|
if (!e)
|
|
269
269
|
return !1;
|
|
270
270
|
const { unitId: r, subUnitId: a, rule: o, index: n, source: i = "command" } = e;
|
|
271
|
-
return t.get(
|
|
271
|
+
return t.get(p).addRule(r, a, o, i, n), !0;
|
|
272
272
|
}
|
|
273
|
-
},
|
|
274
|
-
type:
|
|
273
|
+
}, f = {
|
|
274
|
+
type: g.MUTATION,
|
|
275
275
|
id: "data-validation.mutation.removeRule",
|
|
276
276
|
handler(t, e) {
|
|
277
277
|
if (!e)
|
|
278
278
|
return !1;
|
|
279
|
-
const { unitId: r, subUnitId: a, ruleId: o, source: n = "command" } = e, i = t.get(
|
|
279
|
+
const { unitId: r, subUnitId: a, ruleId: o, source: n = "command" } = e, i = t.get(p);
|
|
280
280
|
return Array.isArray(o) ? o.forEach((l) => {
|
|
281
281
|
i.removeRule(r, a, l, n);
|
|
282
282
|
}) : i.removeRule(r, a, o, n), !0;
|
|
283
283
|
}
|
|
284
|
-
},
|
|
285
|
-
type:
|
|
284
|
+
}, v = {
|
|
285
|
+
type: g.MUTATION,
|
|
286
286
|
id: "data-validation.mutation.updateRule",
|
|
287
287
|
handler(t, e) {
|
|
288
288
|
if (!e)
|
|
289
289
|
return !1;
|
|
290
290
|
const { unitId: r, subUnitId: a, ruleId: o, payload: n, source: i = "command" } = e;
|
|
291
|
-
return t.get(
|
|
291
|
+
return t.get(p).updateRule(r, a, o, n, i), !0;
|
|
292
292
|
}
|
|
293
|
-
},
|
|
294
|
-
type:
|
|
293
|
+
}, me = {
|
|
294
|
+
type: g.COMMAND,
|
|
295
295
|
id: "data-validation.command.addRule",
|
|
296
296
|
async handler(t, e) {
|
|
297
297
|
if (t.get(N).error("[Deprecated]: `AddDataValidationCommand` is deprecated, please use `AddSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"), !e)
|
|
@@ -305,8 +305,8 @@ const S = {
|
|
|
305
305
|
}, u = [{
|
|
306
306
|
id: S.id,
|
|
307
307
|
params: d
|
|
308
|
-
}],
|
|
309
|
-
id:
|
|
308
|
+
}], m = [{
|
|
309
|
+
id: f.id,
|
|
310
310
|
params: {
|
|
311
311
|
unitId: o,
|
|
312
312
|
subUnitId: n,
|
|
@@ -316,19 +316,19 @@ const S = {
|
|
|
316
316
|
return l.pushUndoRedo({
|
|
317
317
|
unitID: o,
|
|
318
318
|
redoMutations: u,
|
|
319
|
-
undoMutations:
|
|
319
|
+
undoMutations: m
|
|
320
320
|
}), await i.executeCommand(S.id, d), !0;
|
|
321
321
|
}
|
|
322
|
-
},
|
|
323
|
-
type:
|
|
322
|
+
}, pe = {
|
|
323
|
+
type: g.COMMAND,
|
|
324
324
|
id: "data-validation.command.removeRule",
|
|
325
325
|
handler(t, e) {
|
|
326
326
|
if (t.get(N).error("[Deprecated]: `RemoveDataValidationCommand` is deprecated, please use `RemoveSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"), !e)
|
|
327
327
|
return !1;
|
|
328
|
-
const { unitId: a, subUnitId: o, ruleId: n } = e, i = t.get(T), l = t.get(A), d = t.get(
|
|
329
|
-
id:
|
|
328
|
+
const { unitId: a, subUnitId: o, ruleId: n } = e, i = t.get(T), l = t.get(A), d = t.get(p), u = [{
|
|
329
|
+
id: f.id,
|
|
330
330
|
params: e
|
|
331
|
-
}],
|
|
331
|
+
}], m = [{
|
|
332
332
|
id: S.id,
|
|
333
333
|
params: {
|
|
334
334
|
unitId: a,
|
|
@@ -340,19 +340,19 @@ const S = {
|
|
|
340
340
|
}
|
|
341
341
|
}];
|
|
342
342
|
return l.pushUndoRedo({
|
|
343
|
-
undoMutations:
|
|
343
|
+
undoMutations: m,
|
|
344
344
|
redoMutations: u,
|
|
345
345
|
unitID: e.unitId
|
|
346
|
-
}), i.executeCommand(
|
|
346
|
+
}), i.executeCommand(f.id, e), !0;
|
|
347
347
|
}
|
|
348
|
-
},
|
|
349
|
-
type:
|
|
348
|
+
}, he = {
|
|
349
|
+
type: g.COMMAND,
|
|
350
350
|
id: "data-validation.command.updateDataValidationSetting",
|
|
351
351
|
handler(t, e) {
|
|
352
352
|
if (t.get(N).warn("[Deprecated]: `UpdateDataValidationOptionsCommand` is deprecated, please use `UpdateSheetDataValidationOptionsCommand` in `@univerjs/sheets-data-validation` instead!"), !e)
|
|
353
353
|
return !1;
|
|
354
|
-
const a = t.get(T), o = t.get(A), n = t.get(
|
|
355
|
-
if (!
|
|
354
|
+
const a = t.get(T), o = t.get(A), n = t.get(p), { unitId: i, subUnitId: l, ruleId: d, options: u } = e, m = n.getRuleById(i, l, d);
|
|
355
|
+
if (!m)
|
|
356
356
|
return !1;
|
|
357
357
|
const _ = {
|
|
358
358
|
unitId: i,
|
|
@@ -362,8 +362,8 @@ const S = {
|
|
|
362
362
|
type: h.OPTIONS,
|
|
363
363
|
payload: u
|
|
364
364
|
}
|
|
365
|
-
},
|
|
366
|
-
id:
|
|
365
|
+
}, E = [{
|
|
366
|
+
id: v.id,
|
|
367
367
|
params: _
|
|
368
368
|
}], M = {
|
|
369
369
|
unitId: i,
|
|
@@ -371,31 +371,31 @@ const S = {
|
|
|
371
371
|
ruleId: d,
|
|
372
372
|
payload: {
|
|
373
373
|
type: h.OPTIONS,
|
|
374
|
-
payload: H(
|
|
374
|
+
payload: H(m)
|
|
375
375
|
}
|
|
376
376
|
}, R = [{
|
|
377
|
-
id:
|
|
377
|
+
id: v.id,
|
|
378
378
|
params: M
|
|
379
379
|
}];
|
|
380
380
|
return o.pushUndoRedo({
|
|
381
381
|
unitID: i,
|
|
382
|
-
redoMutations:
|
|
382
|
+
redoMutations: E,
|
|
383
383
|
undoMutations: R
|
|
384
|
-
}), a.executeCommand(
|
|
384
|
+
}), a.executeCommand(v.id, _), !0;
|
|
385
385
|
}
|
|
386
|
-
},
|
|
387
|
-
type:
|
|
386
|
+
}, _e = {
|
|
387
|
+
type: g.COMMAND,
|
|
388
388
|
id: "data-validation.command.updateDataValidationOptions",
|
|
389
389
|
handler(t, e) {
|
|
390
390
|
if (t.get(N).error("[Deprecated]: `UpdateDataValidationSettingCommand` is deprecated, please use `UpdateSheetDataValidationSettingCommand` in `@univerjs/sheets-data-validation` instead!"), !e)
|
|
391
391
|
return !1;
|
|
392
|
-
const a = t.get(T), o = t.get(A), n = t.get(
|
|
392
|
+
const a = t.get(T), o = t.get(A), n = t.get(p), i = t.get(Q), { unitId: l, subUnitId: d, ruleId: u, setting: m } = e, _ = i.getValidatorItem(m.type);
|
|
393
393
|
if (!_)
|
|
394
394
|
return !1;
|
|
395
|
-
const
|
|
396
|
-
if (!
|
|
395
|
+
const E = n.getRuleById(l, d, u);
|
|
396
|
+
if (!E)
|
|
397
397
|
return !1;
|
|
398
|
-
const M = { ...
|
|
398
|
+
const M = { ...E, ...m };
|
|
399
399
|
if (!_.validatorFormula(M, l, d).success)
|
|
400
400
|
return !1;
|
|
401
401
|
const R = {
|
|
@@ -405,12 +405,12 @@ const S = {
|
|
|
405
405
|
payload: {
|
|
406
406
|
type: h.SETTING,
|
|
407
407
|
payload: {
|
|
408
|
-
...
|
|
408
|
+
...m,
|
|
409
409
|
..._.normalizeFormula(M, l, d)
|
|
410
410
|
}
|
|
411
411
|
}
|
|
412
|
-
},
|
|
413
|
-
id:
|
|
412
|
+
}, j = [{
|
|
413
|
+
id: v.id,
|
|
414
414
|
params: R
|
|
415
415
|
}], F = {
|
|
416
416
|
unitId: l,
|
|
@@ -418,30 +418,30 @@ const S = {
|
|
|
418
418
|
ruleId: u,
|
|
419
419
|
payload: {
|
|
420
420
|
type: h.SETTING,
|
|
421
|
-
payload: q(
|
|
421
|
+
payload: q(E)
|
|
422
422
|
}
|
|
423
423
|
}, W = [{
|
|
424
|
-
id:
|
|
424
|
+
id: v.id,
|
|
425
425
|
params: F
|
|
426
426
|
}];
|
|
427
427
|
return o.pushUndoRedo({
|
|
428
428
|
unitID: l,
|
|
429
|
-
redoMutations:
|
|
429
|
+
redoMutations: j,
|
|
430
430
|
undoMutations: W
|
|
431
|
-
}), a.executeCommand(
|
|
431
|
+
}), a.executeCommand(v.id, R), !0;
|
|
432
432
|
}
|
|
433
|
-
},
|
|
434
|
-
type:
|
|
433
|
+
}, ge = {
|
|
434
|
+
type: g.COMMAND,
|
|
435
435
|
id: "data-validation.command.removeAll",
|
|
436
436
|
handler(t, e) {
|
|
437
437
|
if (t.get(N).error("[Deprecated]: `RemoveAllDataValidationCommand` is deprecated, please use `RemoveSheetAllDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"), !e)
|
|
438
438
|
return !1;
|
|
439
|
-
const { unitId: a, subUnitId: o } = e, n = t.get(T), i = t.get(
|
|
439
|
+
const { unitId: a, subUnitId: o } = e, n = t.get(T), i = t.get(p), l = t.get(A), d = [...i.getRules(a, o)], u = {
|
|
440
440
|
unitId: a,
|
|
441
441
|
subUnitId: o,
|
|
442
|
-
ruleId: d.map((
|
|
443
|
-
},
|
|
444
|
-
id:
|
|
442
|
+
ruleId: d.map((E) => E.uid)
|
|
443
|
+
}, m = [{
|
|
444
|
+
id: f.id,
|
|
445
445
|
params: u
|
|
446
446
|
}], _ = [{
|
|
447
447
|
id: S.id,
|
|
@@ -452,45 +452,45 @@ const S = {
|
|
|
452
452
|
}
|
|
453
453
|
}];
|
|
454
454
|
return l.pushUndoRedo({
|
|
455
|
-
redoMutations:
|
|
455
|
+
redoMutations: m,
|
|
456
456
|
undoMutations: _,
|
|
457
457
|
unitID: a
|
|
458
|
-
}), n.executeCommand(
|
|
458
|
+
}), n.executeCommand(f.id, u), !0;
|
|
459
459
|
}
|
|
460
|
-
},
|
|
461
|
-
var
|
|
462
|
-
for (var o = a > 1 ? void 0 : a ?
|
|
463
|
-
(i = t[n]) && (o =
|
|
464
|
-
return
|
|
460
|
+
}, Ee = "data-validation.config", U = {};
|
|
461
|
+
var ve = Object.getOwnPropertyDescriptor, fe = (t, e, r, a) => {
|
|
462
|
+
for (var o = a > 1 ? void 0 : a ? ve(e, r) : e, n = t.length - 1, i; n >= 0; n--)
|
|
463
|
+
(i = t[n]) && (o = i(o) || o);
|
|
464
|
+
return o;
|
|
465
465
|
}, L = (t, e) => (r, a) => e(r, a, t);
|
|
466
|
-
const
|
|
466
|
+
const Ne = "UNIVER_DATA_VALIDATION_PLUGIN";
|
|
467
467
|
var V;
|
|
468
|
-
let D = (V = class extends
|
|
468
|
+
let D = (V = class extends X {
|
|
469
469
|
constructor(t = U, e, r, a) {
|
|
470
470
|
super(), this._config = t, this._injector = e, this._commandService = r, this._configService = a;
|
|
471
|
-
const { ...o } =
|
|
471
|
+
const { ...o } = Z(
|
|
472
472
|
{},
|
|
473
473
|
U,
|
|
474
474
|
this._config
|
|
475
475
|
);
|
|
476
|
-
this._configService.setConfig(
|
|
476
|
+
this._configService.setConfig(Ee, o);
|
|
477
477
|
}
|
|
478
478
|
onStarting() {
|
|
479
479
|
[
|
|
480
|
-
[
|
|
481
|
-
[
|
|
480
|
+
[p],
|
|
481
|
+
[Q],
|
|
482
482
|
[I]
|
|
483
483
|
].forEach((t) => this._injector.add(t)), [
|
|
484
484
|
// command
|
|
485
|
-
|
|
486
|
-
fe,
|
|
487
|
-
Ee,
|
|
485
|
+
me,
|
|
488
486
|
ge,
|
|
487
|
+
he,
|
|
489
488
|
_e,
|
|
489
|
+
pe,
|
|
490
490
|
// mutation
|
|
491
491
|
S,
|
|
492
|
-
|
|
493
|
-
|
|
492
|
+
v,
|
|
493
|
+
f
|
|
494
494
|
].forEach((t) => {
|
|
495
495
|
this._commandService.registerCommand(t);
|
|
496
496
|
});
|
|
@@ -498,14 +498,14 @@ let D = (V = class extends Z {
|
|
|
498
498
|
onReady() {
|
|
499
499
|
this._injector.get(I);
|
|
500
500
|
}
|
|
501
|
-
}, c(V, "pluginName",
|
|
502
|
-
D =
|
|
503
|
-
L(1, O(
|
|
501
|
+
}, c(V, "pluginName", Ne), c(V, "type", G.UNIVER_SHEET), V);
|
|
502
|
+
D = fe([
|
|
503
|
+
L(1, O($)),
|
|
504
504
|
L(2, T),
|
|
505
505
|
L(3, ee)
|
|
506
506
|
], D);
|
|
507
507
|
s.BETWEEN + "", s.EQUAL + "", s.GREATER_THAN + "", s.GREATER_THAN_OR_EQUAL + "", s.LESS_THAN + "", s.LESS_THAN_OR_EQUAL + "", s.NOT_BETWEEN + "", s.NOT_EQUAL + "";
|
|
508
|
-
const
|
|
508
|
+
const Te = {
|
|
509
509
|
[s.BETWEEN]: "dataValidation.ruleName.between",
|
|
510
510
|
[s.EQUAL]: "dataValidation.ruleName.equal",
|
|
511
511
|
[s.GREATER_THAN]: "dataValidation.ruleName.greaterThan",
|
|
@@ -514,7 +514,7 @@ const Me = {
|
|
|
514
514
|
[s.LESS_THAN_OR_EQUAL]: "dataValidation.ruleName.lessThanOrEqual",
|
|
515
515
|
[s.NOT_BETWEEN]: "dataValidation.ruleName.notBetween",
|
|
516
516
|
[s.NOT_EQUAL]: "dataValidation.ruleName.notEqual"
|
|
517
|
-
},
|
|
517
|
+
}, Se = {
|
|
518
518
|
[s.BETWEEN]: "dataValidation.errorMsg.between",
|
|
519
519
|
[s.EQUAL]: "dataValidation.errorMsg.equal",
|
|
520
520
|
[s.GREATER_THAN]: "dataValidation.errorMsg.greaterThan",
|
|
@@ -523,7 +523,7 @@ const Me = {
|
|
|
523
523
|
[s.LESS_THAN_OR_EQUAL]: "dataValidation.errorMsg.lessThanOrEqual",
|
|
524
524
|
[s.NOT_BETWEEN]: "dataValidation.errorMsg.notBetween",
|
|
525
525
|
[s.NOT_EQUAL]: "dataValidation.errorMsg.notEqual"
|
|
526
|
-
},
|
|
526
|
+
}, ye = {
|
|
527
527
|
[s.BETWEEN]: "dataValidation.textLength.errorMsg.between",
|
|
528
528
|
[s.EQUAL]: "dataValidation.textLength.errorMsg.equal",
|
|
529
529
|
[s.GREATER_THAN]: "dataValidation.textLength.errorMsg.greaterThan",
|
|
@@ -532,16 +532,16 @@ const Me = {
|
|
|
532
532
|
[s.LESS_THAN_OR_EQUAL]: "dataValidation.textLength.errorMsg.lessThanOrEqual",
|
|
533
533
|
[s.NOT_BETWEEN]: "dataValidation.textLength.errorMsg.notBetween",
|
|
534
534
|
[s.NOT_EQUAL]: "dataValidation.textLength.errorMsg.notEqual"
|
|
535
|
-
},
|
|
535
|
+
}, Le = [
|
|
536
536
|
s.BETWEEN,
|
|
537
537
|
s.NOT_BETWEEN
|
|
538
538
|
];
|
|
539
|
-
var
|
|
540
|
-
for (var o = a > 1 ? void 0 : a ?
|
|
541
|
-
(i = t[n]) && (o =
|
|
542
|
-
return
|
|
539
|
+
var Ae = Object.getOwnPropertyDescriptor, Me = (t, e, r, a) => {
|
|
540
|
+
for (var o = a > 1 ? void 0 : a ? Ae(e, r) : e, n = t.length - 1, i; n >= 0; n--)
|
|
541
|
+
(i = t[n]) && (o = i(o) || o);
|
|
542
|
+
return o;
|
|
543
543
|
}, w = (t, e) => (r, a) => e(r, a, t);
|
|
544
|
-
const b = "{FORMULA1}", C = "{FORMULA2}",
|
|
544
|
+
const b = "{FORMULA1}", C = "{FORMULA2}", Re = {
|
|
545
545
|
[s.BETWEEN]: "dataValidation.operators.between",
|
|
546
546
|
[s.EQUAL]: "dataValidation.operators.equal",
|
|
547
547
|
[s.GREATER_THAN]: "dataValidation.operators.greaterThan",
|
|
@@ -551,7 +551,7 @@ const b = "{FORMULA1}", C = "{FORMULA2}", ye = {
|
|
|
551
551
|
[s.NOT_BETWEEN]: "dataValidation.operators.notBetween",
|
|
552
552
|
[s.NOT_EQUAL]: "dataValidation.operators.notEqual"
|
|
553
553
|
};
|
|
554
|
-
let
|
|
554
|
+
let B = class {
|
|
555
555
|
// #endregion
|
|
556
556
|
constructor(t, e) {
|
|
557
557
|
c(this, "offsetFormulaByRange", !0);
|
|
@@ -564,7 +564,7 @@ let P = class {
|
|
|
564
564
|
this.localeService = t, this.injector = e;
|
|
565
565
|
}
|
|
566
566
|
get operatorNames() {
|
|
567
|
-
return this.operators.map((t) => this.localeService.t(
|
|
567
|
+
return this.operators.map((t) => this.localeService.t(Re[t]));
|
|
568
568
|
}
|
|
569
569
|
get titleStr() {
|
|
570
570
|
return this.localeService.t(this.title);
|
|
@@ -573,12 +573,12 @@ let P = class {
|
|
|
573
573
|
var r, a;
|
|
574
574
|
if (!t.operator)
|
|
575
575
|
return this.titleStr;
|
|
576
|
-
const e = this.localeService.t(
|
|
576
|
+
const e = this.localeService.t(Te[t.operator]).replace(b, (r = t.formula1) != null ? r : "").replace(C, (a = t.formula2) != null ? a : "");
|
|
577
577
|
return `${this.titleStr} ${e}`;
|
|
578
578
|
}
|
|
579
579
|
generateRuleErrorMessage(t, e) {
|
|
580
580
|
var a, o;
|
|
581
|
-
return t.operator ? `${this.localeService.t(
|
|
581
|
+
return t.operator ? `${this.localeService.t(Se[t.operator]).replace(b, (a = t.formula1) != null ? a : "").replace(C, (o = t.formula2) != null ? o : "")}` : this.titleStr;
|
|
582
582
|
}
|
|
583
583
|
getExtraStyle(t, e, r, a, o) {
|
|
584
584
|
}
|
|
@@ -645,7 +645,7 @@ let P = class {
|
|
|
645
645
|
const d = await this.parseFormula(e, a, o, t.row, t.column);
|
|
646
646
|
if (!d.isFormulaValid || !await this.isValidType(t, d, e))
|
|
647
647
|
return !1;
|
|
648
|
-
if (!
|
|
648
|
+
if (!P.isDefine(l))
|
|
649
649
|
return !0;
|
|
650
650
|
const u = this.transform(t, d, e);
|
|
651
651
|
switch (l) {
|
|
@@ -670,22 +670,22 @@ let P = class {
|
|
|
670
670
|
}
|
|
671
671
|
}
|
|
672
672
|
};
|
|
673
|
-
|
|
673
|
+
B = Me([
|
|
674
674
|
w(0, O(te)),
|
|
675
|
-
w(1, O(
|
|
676
|
-
],
|
|
675
|
+
w(1, O($))
|
|
676
|
+
], B);
|
|
677
677
|
export {
|
|
678
678
|
S as AddDataValidationMutation,
|
|
679
|
-
|
|
680
|
-
|
|
679
|
+
B as BaseDataValidator,
|
|
680
|
+
p as DataValidationModel,
|
|
681
681
|
I as DataValidationResourceController,
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
682
|
+
ce as DataValidatorRegistryScope,
|
|
683
|
+
Q as DataValidatorRegistryService,
|
|
684
|
+
f as RemoveDataValidationMutation,
|
|
685
|
+
Le as TWO_FORMULA_OPERATOR_COUNT,
|
|
686
|
+
ye as TextLengthErrorTitleMap,
|
|
687
687
|
D as UniverDataValidationPlugin,
|
|
688
|
-
|
|
688
|
+
v as UpdateDataValidationMutation,
|
|
689
689
|
h as UpdateRuleType,
|
|
690
690
|
H as getRuleOptions,
|
|
691
691
|
q as getRuleSetting
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(l,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("@univerjs/core"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs"],n):(l=typeof globalThis<"u"?globalThis:l||self,n(l.UniverDataValidation={},l.UniverCore,l.rxjs))})(this,function(l,n,_){"use strict";var la=Object.defineProperty;var ua=(l,n,_)=>n in l?la(l,n,{enumerable:!0,configurable:!0,writable:!0,value:_}):l[n]=_;var c=(l,n,_)=>ua(l,typeof n!="symbol"?n+"":n,_);var O;function D(r){return{type:r.type,operator:r.operator,formula1:r.formula1,formula2:r.formula2,allowBlank:r.allowBlank}}function N(r){return{error:r.error,errorStyle:r.errorStyle,errorTitle:r.errorTitle,imeMode:r.imeMode,prompt:r.prompt,promptTitle:r.promptTitle,showDropDown:r.showDropDown,showErrorMessage:r.showErrorMessage,showInputMessage:r.showInputMessage,renderMode:r.renderMode,bizInfo:r.bizInfo}}var h=(r=>(r[r.SETTING=0]="SETTING",r[r.RANGE=1]="RANGE",r[r.OPTIONS=2]="OPTIONS",r[r.ALL=3]="ALL",r))(h||{}),b=Object.defineProperty,w=Object.getOwnPropertyDescriptor,P=(r,a,i,e)=>{for(var t=e>1?void 0:e?w(a,i):a,o=r.length-1,d;o>=0;o--)(d=r[o])&&(t=(e?d(a,i,t):d(t))||t);return e&&t&&b(a,i,t),t},B=(r,a)=>(i,e)=>a(i,e,r);l.DataValidationModel=class extends n.Disposable{constructor(i){super();c(this,"_model",new Map);c(this,"_ruleChange$",new _.Subject);c(this,"ruleChange$",this._ruleChange$.asObservable());c(this,"ruleChangeDebounce$",this.ruleChange$.pipe(_.debounceTime(20)));this._logService=i,this.disposeWithMe({dispose:()=>{this._ruleChange$.complete()}})}_ensureMap(i,e){this._model.has(i)||this._model.set(i,new Map);const t=this._model.get(i);if(t.has(e))return t.get(e);const o={map:new Map,list:[]};return t.set(e,o),o}_addSubUnitRule(i,e,t){const{map:o,list:d}=i,p=(Array.isArray(e)?e:[e]).filter(u=>!o.has(u.uid));typeof t=="number"&&t<d.length?d.splice(t,0,...p):d.push(...p),p.forEach(u=>{o.set(u.uid,u)})}_removeSubUnitRule(i,e){const{map:t,list:o}=i,d=o.findIndex(s=>s.uid===e);d>-1&&(o.splice(d,1),t.delete(e))}_updateSubUnitRule(i,e,t){const{map:o,list:d}=i,s=o.get(e),p=d.findIndex(m=>e===m.uid);if(!s)throw new Error(`Data validation rule is not found, ruleId: ${e}.`);const u={...s};switch(t.type){case h.RANGE:{u.ranges=t.payload;break}case h.SETTING:{Object.assign(u,D(t.payload));break}case h.OPTIONS:{Object.assign(u,N(t.payload));break}case h.ALL:{Object.assign(u,t.payload);break}}return d[p]=u,o.set(e,u),u}_addRuleSideEffect(i,e,t,o){if(!this._ensureMap(i,e).map.get(t.uid))return{rule:t,type:"add",unitId:i,subUnitId:e,source:o}}addRule(i,e,t,o,d){try{const s=this._ensureMap(i,e),u=(Array.isArray(t)?t:[t]).map(m=>this._addRuleSideEffect(i,e,m,o));this._addSubUnitRule(s,t,d),u.forEach(m=>{m&&this._ruleChange$.next(m)})}catch(s){this._logService.error(s)}}updateRule(i,e,t,o,d){try{const s=this._ensureMap(i,e),p=n.Tools.deepClone(s.map.get(t));if(!p)throw new Error(`Data validation rule is not found, ruleId: ${t}.`);const u=this._updateSubUnitRule(s,t,o);this._ruleChange$.next({rule:u,type:"update",unitId:i,subUnitId:e,source:d,updatePayload:o,oldRule:p})}catch(s){this._logService.error(s)}}removeRule(i,e,t,o){try{const d=this._ensureMap(i,e),s=d.map.get(t);s&&(this._removeSubUnitRule(d,t),this._ruleChange$.next({rule:s,type:"remove",unitId:i,subUnitId:e,source:o}))}catch(d){this._logService.error(d)}}getRuleById(i,e,t){return this._ensureMap(i,e).map.get(t)}getRuleIndex(i,e,t){return this._ensureMap(i,e).list.findIndex(d=>d.uid===t)}getRules(i,e){return[...this._ensureMap(i,e).list]}getUnitRules(i){const e=this._model.get(i);if(!e)return[];const t=[];return e.forEach((o,d)=>{t.push([d,o.list])}),t}deleteUnitRules(i){this._model.delete(i)}getSubUnitIds(i){var e,t;return Array.from((t=(e=this._model.get(i))==null?void 0:e.keys())!=null?t:[])}getAll(){return Array.from(this._model.keys()).map(i=>[i,this.getUnitRules(i)])}},l.DataValidationModel=P([B(0,n.ILogService)],l.DataValidationModel);var j=Object.defineProperty,$=Object.getOwnPropertyDescriptor,q=(r,a,i,e)=>{for(var t=e>1?void 0:e?$(a,i):a,o=r.length-1,d;o>=0;o--)(d=r[o])&&(t=(e?d(a,i,t):d(t))||t);return e&&t&&j(a,i,t),t},M=(r,a)=>(i,e)=>a(i,e,r);const G="SHEET_DATA_VALIDATION_PLUGIN";l.DataValidationResourceController=class extends n.Disposable{constructor(a,i,e){super(),this._resourceManagerService=a,this._univerInstanceService=i,this._dataValidationModel=e,this._initSnapshot()}_initSnapshot(){const a=e=>{const t=this._dataValidationModel.getUnitRules(e),o={};return t?(t.forEach(([d,s])=>{o[d]=s}),JSON.stringify(o)):""},i=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:G,businesses:[n.UniverInstanceType.UNIVER_SHEET],toJson:e=>a(e),parseJson:e=>i(e),onUnLoad:e=>{this._dataValidationModel.deleteUnitRules(e)},onLoad:(e,t)=>{Object.keys(t).forEach(o=>{t[o].forEach(s=>{this._dataValidationModel.addRule(e,o,s,"patched")})})}}))}},l.DataValidationResourceController=q([M(0,n.IResourceManagerService),M(1,n.IUniverInstanceService),M(2,n.Inject(l.DataValidationModel))],l.DataValidationResourceController);var I=(r=>(r.SHEET="sheet",r))(I||{});class R{constructor(){c(this,"_validatorByScopes",new Map);c(this,"_validatorMap",new Map);c(this,"_validatorsChange$",new _.BehaviorSubject(void 0));c(this,"validatorsChange$",this._validatorsChange$.asObservable())}_addValidatorToScope(a,i){this._validatorByScopes.has(i)||this._validatorByScopes.set(i,[]);const e=this._validatorByScopes.get(i);if(e.findIndex(t=>t.id===a.id)>-1)throw new Error(`Validator item with the same id ${a.id} has already been added!`);e.push(a)}_removeValidatorFromScope(a,i){const e=this._validatorByScopes.get(i);if(!e)return;const t=e.findIndex(o=>o.id===a.id);t>-1&&e.splice(t,1)}register(a){return this._validatorMap.set(a.id,a),Array.isArray(a.scopes)?a.scopes.forEach(i=>{this._addValidatorToScope(a,i)}):this._addValidatorToScope(a,a.scopes),this._validatorsChange$.next(),n.toDisposable(()=>{this._validatorMap.delete(a.id),Array.isArray(a.scopes)?a.scopes.forEach(i=>{this._removeValidatorFromScope(a,i)}):this._removeValidatorFromScope(a,a.scopes),this._validatorsChange$.next()})}getValidatorItem(a){return this._validatorMap.get(a)}getValidatorsByScope(a){return this._validatorByScopes.get(a)}}const f={type:n.CommandType.MUTATION,id:"data-validation.mutation.addRule",handler(r,a){if(!a)return!1;const{unitId:i,subUnitId:e,rule:t,index:o,source:d="command"}=a;return r.get(l.DataValidationModel).addRule(i,e,t,d,o),!0}},E={type:n.CommandType.MUTATION,id:"data-validation.mutation.removeRule",handler(r,a){if(!a)return!1;const{unitId:i,subUnitId:e,ruleId:t,source:o="command"}=a,d=r.get(l.DataValidationModel);return Array.isArray(t)?t.forEach(s=>{d.removeRule(i,e,s,o)}):d.removeRule(i,e,t,o),!0}},g={type:n.CommandType.MUTATION,id:"data-validation.mutation.updateRule",handler(r,a){if(!a)return!1;const{unitId:i,subUnitId:e,ruleId:t,payload:o,source:d="command"}=a;return r.get(l.DataValidationModel).updateRule(i,e,t,o,d),!0}},H={type:n.CommandType.COMMAND,id:"data-validation.command.addRule",async handler(r,a){if(r.get(n.ILogService).error("[Deprecated]: `AddDataValidationCommand` is deprecated, please use `AddSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"),!a)return!1;const{rule:e,unitId:t,subUnitId:o}=a,d=r.get(n.ICommandService),s=r.get(n.IUndoRedoService),p={...a,rule:{...a.rule,ranges:[a.rule.range]}},u=[{id:f.id,params:p}],m=[{id:E.id,params:{unitId:t,subUnitId:o,ruleId:e.uid}}];return s.pushUndoRedo({unitID:t,redoMutations:u,undoMutations:m}),await d.executeCommand(f.id,p),!0}},Q={type:n.CommandType.COMMAND,id:"data-validation.command.removeRule",handler(r,a){if(r.get(n.ILogService).error("[Deprecated]: `RemoveDataValidationCommand` is deprecated, please use `RemoveSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"),!a)return!1;const{unitId:e,subUnitId:t,ruleId:o}=a,d=r.get(n.ICommandService),s=r.get(n.IUndoRedoService),p=r.get(l.DataValidationModel),u=[{id:E.id,params:a}],m=[{id:f.id,params:{unitId:e,subUnitId:t,rule:{...p.getRuleById(e,t,o)},index:p.getRuleIndex(e,t,o)}}];return s.pushUndoRedo({undoMutations:m,redoMutations:u,unitID:a.unitId}),d.executeCommand(E.id,a),!0}},F={type:n.CommandType.COMMAND,id:"data-validation.command.updateDataValidationSetting",handler(r,a){if(r.get(n.ILogService).warn("[Deprecated]: `UpdateDataValidationOptionsCommand` is deprecated, please use `UpdateSheetDataValidationOptionsCommand` in `@univerjs/sheets-data-validation` instead!"),!a)return!1;const e=r.get(n.ICommandService),t=r.get(n.IUndoRedoService),o=r.get(l.DataValidationModel),{unitId:d,subUnitId:s,ruleId:p,options:u}=a,m=o.getRuleById(d,s,p);if(!m)return!1;const V={unitId:d,subUnitId:s,ruleId:p,payload:{type:h.OPTIONS,payload:u}},v=[{id:g.id,params:V}],T={unitId:d,subUnitId:s,ruleId:p,payload:{type:h.OPTIONS,payload:N(m)}},S=[{id:g.id,params:T}];return t.pushUndoRedo({unitID:d,redoMutations:v,undoMutations:S}),e.executeCommand(g.id,V),!0}},W={type:n.CommandType.COMMAND,id:"data-validation.command.updateDataValidationOptions",handler(r,a){if(r.get(n.ILogService).error("[Deprecated]: `UpdateDataValidationSettingCommand` is deprecated, please use `UpdateSheetDataValidationSettingCommand` in `@univerjs/sheets-data-validation` instead!"),!a)return!1;const e=r.get(n.ICommandService),t=r.get(n.IUndoRedoService),o=r.get(l.DataValidationModel),d=r.get(R),{unitId:s,subUnitId:p,ruleId:u,setting:m}=a,V=d.getValidatorItem(m.type);if(!V)return!1;const v=o.getRuleById(s,p,u);if(!v)return!1;const T={...v,...m};if(!V.validatorFormula(T,s,p).success)return!1;const S={unitId:s,subUnitId:p,ruleId:u,payload:{type:h.SETTING,payload:{...m,...V.normalizeFormula(T,s,p)}}},oa=[{id:g.id,params:S}],da={unitId:s,subUnitId:p,ruleId:u,payload:{type:h.SETTING,payload:D(v)}},sa=[{id:g.id,params:da}];return t.pushUndoRedo({unitID:s,redoMutations:oa,undoMutations:sa}),e.executeCommand(g.id,S),!0}},x={type:n.CommandType.COMMAND,id:"data-validation.command.removeAll",handler(r,a){if(r.get(n.ILogService).error("[Deprecated]: `RemoveAllDataValidationCommand` is deprecated, please use `RemoveSheetAllDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"),!a)return!1;const{unitId:e,subUnitId:t}=a,o=r.get(n.ICommandService),d=r.get(l.DataValidationModel),s=r.get(n.IUndoRedoService),p=[...d.getRules(e,t)],u={unitId:e,subUnitId:t,ruleId:p.map(v=>v.uid)},m=[{id:E.id,params:u}],V=[{id:f.id,params:{unitId:e,subUnitId:t,rule:p}}];return s.pushUndoRedo({redoMutations:m,undoMutations:V,unitID:e}),o.executeCommand(E.id,u),!0}},J="data-validation.config",y={};var z=Object.defineProperty,K=Object.getOwnPropertyDescriptor,Y=(r,a,i,e)=>{for(var t=e>1?void 0:e?K(a,i):a,o=r.length-1,d;o>=0;o--)(d=r[o])&&(t=(e?d(a,i,t):d(t))||t);return e&&t&&z(a,i,t),t},A=(r,a)=>(i,e)=>a(i,e,r);const X="UNIVER_DATA_VALIDATION_PLUGIN";l.UniverDataValidationPlugin=(O=class extends n.Plugin{constructor(a=y,i,e,t){super(),this._config=a,this._injector=i,this._commandService=e,this._configService=t;const{...o}=n.merge({},y,this._config);this._configService.setConfig(J,o)}onStarting(){[[l.DataValidationModel],[R],[l.DataValidationResourceController]].forEach(a=>this._injector.add(a)),[H,x,F,W,Q,f,g,E].forEach(a=>{this._commandService.registerCommand(a)})}onReady(){this._injector.get(l.DataValidationResourceController)}},c(O,"pluginName",X),c(O,"type",n.UniverInstanceType.UNIVER_SHEET),O),l.UniverDataValidationPlugin=Y([A(1,n.Inject(n.Injector)),A(2,n.ICommandService),A(3,n.IConfigService)],l.UniverDataValidationPlugin),n.DataValidationOperator.BETWEEN+"",n.DataValidationOperator.EQUAL+"",n.DataValidationOperator.GREATER_THAN+"",n.DataValidationOperator.GREATER_THAN_OR_EQUAL+"",n.DataValidationOperator.LESS_THAN+"",n.DataValidationOperator.LESS_THAN_OR_EQUAL+"",n.DataValidationOperator.NOT_BETWEEN+"",n.DataValidationOperator.NOT_EQUAL+"";const Z={[n.DataValidationOperator.BETWEEN]:"dataValidation.ruleName.between",[n.DataValidationOperator.EQUAL]:"dataValidation.ruleName.equal",[n.DataValidationOperator.GREATER_THAN]:"dataValidation.ruleName.greaterThan",[n.DataValidationOperator.GREATER_THAN_OR_EQUAL]:"dataValidation.ruleName.greaterThanOrEqual",[n.DataValidationOperator.LESS_THAN]:"dataValidation.ruleName.lessThan",[n.DataValidationOperator.LESS_THAN_OR_EQUAL]:"dataValidation.ruleName.lessThanOrEqual",[n.DataValidationOperator.NOT_BETWEEN]:"dataValidation.ruleName.notBetween",[n.DataValidationOperator.NOT_EQUAL]:"dataValidation.ruleName.notEqual"},k={[n.DataValidationOperator.BETWEEN]:"dataValidation.errorMsg.between",[n.DataValidationOperator.EQUAL]:"dataValidation.errorMsg.equal",[n.DataValidationOperator.GREATER_THAN]:"dataValidation.errorMsg.greaterThan",[n.DataValidationOperator.GREATER_THAN_OR_EQUAL]:"dataValidation.errorMsg.greaterThanOrEqual",[n.DataValidationOperator.LESS_THAN]:"dataValidation.errorMsg.lessThan",[n.DataValidationOperator.LESS_THAN_OR_EQUAL]:"dataValidation.errorMsg.lessThanOrEqual",[n.DataValidationOperator.NOT_BETWEEN]:"dataValidation.errorMsg.notBetween",[n.DataValidationOperator.NOT_EQUAL]:"dataValidation.errorMsg.notEqual"},aa={[n.DataValidationOperator.BETWEEN]:"dataValidation.textLength.errorMsg.between",[n.DataValidationOperator.EQUAL]:"dataValidation.textLength.errorMsg.equal",[n.DataValidationOperator.GREATER_THAN]:"dataValidation.textLength.errorMsg.greaterThan",[n.DataValidationOperator.GREATER_THAN_OR_EQUAL]:"dataValidation.textLength.errorMsg.greaterThanOrEqual",[n.DataValidationOperator.LESS_THAN]:"dataValidation.textLength.errorMsg.lessThan",[n.DataValidationOperator.LESS_THAN_OR_EQUAL]:"dataValidation.textLength.errorMsg.lessThanOrEqual",[n.DataValidationOperator.NOT_BETWEEN]:"dataValidation.textLength.errorMsg.notBetween",[n.DataValidationOperator.NOT_EQUAL]:"dataValidation.textLength.errorMsg.notEqual"},ta=[n.DataValidationOperator.BETWEEN,n.DataValidationOperator.NOT_BETWEEN];var ea=Object.defineProperty,ia=Object.getOwnPropertyDescriptor,na=(r,a,i,e)=>{for(var t=e>1?void 0:e?ia(a,i):a,o=r.length-1,d;o>=0;o--)(d=r[o])&&(t=(e?d(a,i,t):d(t))||t);return e&&t&&ea(a,i,t),t},U=(r,a)=>(i,e)=>a(i,e,r);const L="{FORMULA1}",C="{FORMULA2}",ra={[n.DataValidationOperator.BETWEEN]:"dataValidation.operators.between",[n.DataValidationOperator.EQUAL]:"dataValidation.operators.equal",[n.DataValidationOperator.GREATER_THAN]:"dataValidation.operators.greaterThan",[n.DataValidationOperator.GREATER_THAN_OR_EQUAL]:"dataValidation.operators.greaterThanOrEqual",[n.DataValidationOperator.LESS_THAN]:"dataValidation.operators.lessThan",[n.DataValidationOperator.LESS_THAN_OR_EQUAL]:"dataValidation.operators.lessThanOrEqual",[n.DataValidationOperator.NOT_BETWEEN]:"dataValidation.operators.notBetween",[n.DataValidationOperator.NOT_EQUAL]:"dataValidation.operators.notEqual"};l.BaseDataValidator=class{constructor(a,i){c(this,"offsetFormulaByRange",!0);c(this,"formulaInput");c(this,"canvasRender",null);c(this,"dropdown");c(this,"optionsInput");c(this,"skipDefaultFontRender");this.localeService=a,this.injector=i}get operatorNames(){return this.operators.map(a=>this.localeService.t(ra[a]))}get titleStr(){return this.localeService.t(this.title)}generateRuleName(a){var e,t;if(!a.operator)return this.titleStr;const i=this.localeService.t(Z[a.operator]).replace(L,(e=a.formula1)!=null?e:"").replace(C,(t=a.formula2)!=null?t:"");return`${this.titleStr} ${i}`}generateRuleErrorMessage(a,i){var t,o;return a.operator?`${this.localeService.t(k[a.operator]).replace(L,(t=a.formula1)!=null?t:"").replace(C,(o=a.formula2)!=null?o:"")}`:this.titleStr}getExtraStyle(a,i,e,t,o){}getRuleFinalError(a,i){return a.showErrorMessage&&a.error?a.error:this.generateRuleErrorMessage(a,i)}isEmptyCellValue(a){return a===""||a===void 0||a===null}normalizeFormula(a,i,e){return{formula1:a.formula1,formula2:a.formula2}}async isValidType(a,i,e){return!0}transform(a,i,e){return a}async validatorIsEqual(a,i,e){const{formula1:t}=i,{value:o}=a;return Number.isNaN(t)?!0:o===t}async validatorIsNotEqual(a,i,e){const{formula1:t}=i;return Number.isNaN(t)?!0:a.value!==t}async validatorIsBetween(a,i,e){const{formula1:t,formula2:o}=i;if(Number.isNaN(t)||Number.isNaN(o))return!0;const d=Math.min(t,o),s=Math.max(t,o);return a.value>=d&&a.value<=s}async validatorIsNotBetween(a,i,e){const{formula1:t,formula2:o}=i;if(Number.isNaN(t)||Number.isNaN(o))return!0;const d=Math.min(t,o),s=Math.max(t,o);return a.value<d||a.value>s}async validatorIsGreaterThan(a,i,e){const{formula1:t}=i;return Number.isNaN(t)?!0:a.value>t}async validatorIsGreaterThanOrEqual(a,i,e){const{formula1:t}=i;return Number.isNaN(t)?!0:a.value>=t}async validatorIsLessThan(a,i,e){const{formula1:t}=i;return Number.isNaN(t)?!0:a.value<t}async validatorIsLessThanOrEqual(a,i,e){const{formula1:t}=i;return Number.isNaN(t)?!0:a.value<=t}async validator(a,i){const{value:e,unitId:t,subUnitId:o}=a,d=this.isEmptyCellValue(e),{allowBlank:s=!0,operator:p}=i;if(d)return s;const u=await this.parseFormula(i,t,o,a.row,a.column);if(!u.isFormulaValid||!await this.isValidType(a,u,i))return!1;if(!n.Tools.isDefine(p))return!0;const m=this.transform(a,u,i);switch(p){case n.DataValidationOperator.BETWEEN:return this.validatorIsBetween(m,u,i);case n.DataValidationOperator.EQUAL:return this.validatorIsEqual(m,u,i);case n.DataValidationOperator.GREATER_THAN:return this.validatorIsGreaterThan(m,u,i);case n.DataValidationOperator.GREATER_THAN_OR_EQUAL:return this.validatorIsGreaterThanOrEqual(m,u,i);case n.DataValidationOperator.LESS_THAN:return this.validatorIsLessThan(m,u,i);case n.DataValidationOperator.LESS_THAN_OR_EQUAL:return this.validatorIsLessThanOrEqual(m,u,i);case n.DataValidationOperator.NOT_BETWEEN:return this.validatorIsNotBetween(m,u,i);case n.DataValidationOperator.NOT_EQUAL:return this.validatorIsNotEqual(m,u,i);default:throw new Error("Unknown operator.")}}},l.BaseDataValidator=na([U(0,n.Inject(n.LocaleService)),U(1,n.Inject(n.Injector))],l.BaseDataValidator),l.AddDataValidationMutation=f,l.DataValidatorRegistryScope=I,l.DataValidatorRegistryService=R,l.RemoveDataValidationMutation=E,l.TWO_FORMULA_OPERATOR_COUNT=ta,l.TextLengthErrorTitleMap=aa,l.UpdateDataValidationMutation=g,l.UpdateRuleType=h,l.getRuleOptions=N,l.getRuleSetting=D,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(l,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("@univerjs/core"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs"],r):(l=typeof globalThis<"u"?globalThis:l||self,r(l.UniverDataValidation={},l.UniverCore,l.rxjs))})(this,function(l,r,g){"use strict";var na=Object.defineProperty;var oa=(l,r,g)=>r in l?na(l,r,{enumerable:!0,configurable:!0,writable:!0,value:g}):l[r]=g;var c=(l,r,g)=>oa(l,typeof r!="symbol"?r+"":r,g);var T;function D(n){return{type:n.type,operator:n.operator,formula1:n.formula1,formula2:n.formula2,allowBlank:n.allowBlank}}function N(n){return{error:n.error,errorStyle:n.errorStyle,errorTitle:n.errorTitle,imeMode:n.imeMode,prompt:n.prompt,promptTitle:n.promptTitle,showDropDown:n.showDropDown,showErrorMessage:n.showErrorMessage,showInputMessage:n.showInputMessage,renderMode:n.renderMode,bizInfo:n.bizInfo}}var h=(n=>(n[n.SETTING=0]="SETTING",n[n.RANGE=1]="RANGE",n[n.OPTIONS=2]="OPTIONS",n[n.ALL=3]="ALL",n))(h||{}),w=Object.getOwnPropertyDescriptor,b=(n,a,i,e)=>{for(var t=e>1?void 0:e?w(a,i):a,o=n.length-1,d;o>=0;o--)(d=n[o])&&(t=d(t)||t);return t},B=(n,a)=>(i,e)=>a(i,e,n);l.DataValidationModel=class extends r.Disposable{constructor(i){super();c(this,"_model",new Map);c(this,"_ruleChange$",new g.Subject);c(this,"ruleChange$",this._ruleChange$.asObservable());c(this,"ruleChangeDebounce$",this.ruleChange$.pipe(g.debounceTime(20)));this._logService=i,this.disposeWithMe({dispose:()=>{this._ruleChange$.complete()}})}_ensureMap(i,e){this._model.has(i)||this._model.set(i,new Map);const t=this._model.get(i);if(t.has(e))return t.get(e);const o={map:new Map,list:[]};return t.set(e,o),o}_addSubUnitRule(i,e,t){const{map:o,list:d}=i,p=(Array.isArray(e)?e:[e]).filter(u=>!o.has(u.uid));typeof t=="number"&&t<d.length?d.splice(t,0,...p):d.push(...p),p.forEach(u=>{o.set(u.uid,u)})}_removeSubUnitRule(i,e){const{map:t,list:o}=i,d=o.findIndex(s=>s.uid===e);d>-1&&(o.splice(d,1),t.delete(e))}_updateSubUnitRule(i,e,t){const{map:o,list:d}=i,s=o.get(e),p=d.findIndex(m=>e===m.uid);if(!s)throw new Error(`Data validation rule is not found, ruleId: ${e}.`);const u={...s};switch(t.type){case h.RANGE:{u.ranges=t.payload;break}case h.SETTING:{Object.assign(u,D(t.payload));break}case h.OPTIONS:{Object.assign(u,N(t.payload));break}case h.ALL:{Object.assign(u,t.payload);break}}return d[p]=u,o.set(e,u),u}_addRuleSideEffect(i,e,t,o){if(!this._ensureMap(i,e).map.get(t.uid))return{rule:t,type:"add",unitId:i,subUnitId:e,source:o}}addRule(i,e,t,o,d){try{const s=this._ensureMap(i,e),u=(Array.isArray(t)?t:[t]).map(m=>this._addRuleSideEffect(i,e,m,o));this._addSubUnitRule(s,t,d),u.forEach(m=>{m&&this._ruleChange$.next(m)})}catch(s){this._logService.error(s)}}updateRule(i,e,t,o,d){try{const s=this._ensureMap(i,e),p=r.Tools.deepClone(s.map.get(t));if(!p)throw new Error(`Data validation rule is not found, ruleId: ${t}.`);const u=this._updateSubUnitRule(s,t,o);this._ruleChange$.next({rule:u,type:"update",unitId:i,subUnitId:e,source:d,updatePayload:o,oldRule:p})}catch(s){this._logService.error(s)}}removeRule(i,e,t,o){try{const d=this._ensureMap(i,e),s=d.map.get(t);s&&(this._removeSubUnitRule(d,t),this._ruleChange$.next({rule:s,type:"remove",unitId:i,subUnitId:e,source:o}))}catch(d){this._logService.error(d)}}getRuleById(i,e,t){return this._ensureMap(i,e).map.get(t)}getRuleIndex(i,e,t){return this._ensureMap(i,e).list.findIndex(d=>d.uid===t)}getRules(i,e){return[...this._ensureMap(i,e).list]}getUnitRules(i){const e=this._model.get(i);if(!e)return[];const t=[];return e.forEach((o,d)=>{t.push([d,o.list])}),t}deleteUnitRules(i){this._model.delete(i)}getSubUnitIds(i){var e,t;return Array.from((t=(e=this._model.get(i))==null?void 0:e.keys())!=null?t:[])}getAll(){return Array.from(this._model.keys()).map(i=>[i,this.getUnitRules(i)])}},l.DataValidationModel=b([B(0,r.ILogService)],l.DataValidationModel);var P=Object.getOwnPropertyDescriptor,q=(n,a,i,e)=>{for(var t=e>1?void 0:e?P(a,i):a,o=n.length-1,d;o>=0;o--)(d=n[o])&&(t=d(t)||t);return t},M=(n,a)=>(i,e)=>a(i,e,n);const G="SHEET_DATA_VALIDATION_PLUGIN";l.DataValidationResourceController=class extends r.Disposable{constructor(a,i,e){super(),this._resourceManagerService=a,this._univerInstanceService=i,this._dataValidationModel=e,this._initSnapshot()}_initSnapshot(){const a=e=>{const t=this._dataValidationModel.getUnitRules(e),o={};return t?(t.forEach(([d,s])=>{o[d]=s}),JSON.stringify(o)):""},i=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:G,businesses:[r.UniverInstanceType.UNIVER_SHEET],toJson:e=>a(e),parseJson:e=>i(e),onUnLoad:e=>{this._dataValidationModel.deleteUnitRules(e)},onLoad:(e,t)=>{Object.keys(t).forEach(o=>{t[o].forEach(s=>{this._dataValidationModel.addRule(e,o,s,"patched")})})}}))}},l.DataValidationResourceController=q([M(0,r.IResourceManagerService),M(1,r.IUniverInstanceService),M(2,r.Inject(l.DataValidationModel))],l.DataValidationResourceController);var I=(n=>(n.SHEET="sheet",n))(I||{});class R{constructor(){c(this,"_validatorByScopes",new Map);c(this,"_validatorMap",new Map);c(this,"_validatorsChange$",new g.BehaviorSubject(void 0));c(this,"validatorsChange$",this._validatorsChange$.asObservable())}_addValidatorToScope(a,i){this._validatorByScopes.has(i)||this._validatorByScopes.set(i,[]);const e=this._validatorByScopes.get(i);if(e.findIndex(t=>t.id===a.id)>-1)throw new Error(`Validator item with the same id ${a.id} has already been added!`);e.push(a)}_removeValidatorFromScope(a,i){const e=this._validatorByScopes.get(i);if(!e)return;const t=e.findIndex(o=>o.id===a.id);t>-1&&e.splice(t,1)}register(a){return this._validatorMap.set(a.id,a),Array.isArray(a.scopes)?a.scopes.forEach(i=>{this._addValidatorToScope(a,i)}):this._addValidatorToScope(a,a.scopes),this._validatorsChange$.next(),r.toDisposable(()=>{this._validatorMap.delete(a.id),Array.isArray(a.scopes)?a.scopes.forEach(i=>{this._removeValidatorFromScope(a,i)}):this._removeValidatorFromScope(a,a.scopes),this._validatorsChange$.next()})}getValidatorItem(a){return this._validatorMap.get(a)}getValidatorsByScope(a){return this._validatorByScopes.get(a)}}const O={type:r.CommandType.MUTATION,id:"data-validation.mutation.addRule",handler(n,a){if(!a)return!1;const{unitId:i,subUnitId:e,rule:t,index:o,source:d="command"}=a;return n.get(l.DataValidationModel).addRule(i,e,t,d,o),!0}},v={type:r.CommandType.MUTATION,id:"data-validation.mutation.removeRule",handler(n,a){if(!a)return!1;const{unitId:i,subUnitId:e,ruleId:t,source:o="command"}=a,d=n.get(l.DataValidationModel);return Array.isArray(t)?t.forEach(s=>{d.removeRule(i,e,s,o)}):d.removeRule(i,e,t,o),!0}},_={type:r.CommandType.MUTATION,id:"data-validation.mutation.updateRule",handler(n,a){if(!a)return!1;const{unitId:i,subUnitId:e,ruleId:t,payload:o,source:d="command"}=a;return n.get(l.DataValidationModel).updateRule(i,e,t,o,d),!0}},j={type:r.CommandType.COMMAND,id:"data-validation.command.addRule",async handler(n,a){if(n.get(r.ILogService).error("[Deprecated]: `AddDataValidationCommand` is deprecated, please use `AddSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"),!a)return!1;const{rule:e,unitId:t,subUnitId:o}=a,d=n.get(r.ICommandService),s=n.get(r.IUndoRedoService),p={...a,rule:{...a.rule,ranges:[a.rule.range]}},u=[{id:O.id,params:p}],m=[{id:v.id,params:{unitId:t,subUnitId:o,ruleId:e.uid}}];return s.pushUndoRedo({unitID:t,redoMutations:u,undoMutations:m}),await d.executeCommand(O.id,p),!0}},$={type:r.CommandType.COMMAND,id:"data-validation.command.removeRule",handler(n,a){if(n.get(r.ILogService).error("[Deprecated]: `RemoveDataValidationCommand` is deprecated, please use `RemoveSheetDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"),!a)return!1;const{unitId:e,subUnitId:t,ruleId:o}=a,d=n.get(r.ICommandService),s=n.get(r.IUndoRedoService),p=n.get(l.DataValidationModel),u=[{id:v.id,params:a}],m=[{id:O.id,params:{unitId:e,subUnitId:t,rule:{...p.getRuleById(e,t,o)},index:p.getRuleIndex(e,t,o)}}];return s.pushUndoRedo({undoMutations:m,redoMutations:u,unitID:a.unitId}),d.executeCommand(v.id,a),!0}},H={type:r.CommandType.COMMAND,id:"data-validation.command.updateDataValidationSetting",handler(n,a){if(n.get(r.ILogService).warn("[Deprecated]: `UpdateDataValidationOptionsCommand` is deprecated, please use `UpdateSheetDataValidationOptionsCommand` in `@univerjs/sheets-data-validation` instead!"),!a)return!1;const e=n.get(r.ICommandService),t=n.get(r.IUndoRedoService),o=n.get(l.DataValidationModel),{unitId:d,subUnitId:s,ruleId:p,options:u}=a,m=o.getRuleById(d,s,p);if(!m)return!1;const V={unitId:d,subUnitId:s,ruleId:p,payload:{type:h.OPTIONS,payload:u}},E=[{id:_.id,params:V}],f={unitId:d,subUnitId:s,ruleId:p,payload:{type:h.OPTIONS,payload:N(m)}},S=[{id:_.id,params:f}];return t.pushUndoRedo({unitID:d,redoMutations:E,undoMutations:S}),e.executeCommand(_.id,V),!0}},Q={type:r.CommandType.COMMAND,id:"data-validation.command.updateDataValidationOptions",handler(n,a){if(n.get(r.ILogService).error("[Deprecated]: `UpdateDataValidationSettingCommand` is deprecated, please use `UpdateSheetDataValidationSettingCommand` in `@univerjs/sheets-data-validation` instead!"),!a)return!1;const e=n.get(r.ICommandService),t=n.get(r.IUndoRedoService),o=n.get(l.DataValidationModel),d=n.get(R),{unitId:s,subUnitId:p,ruleId:u,setting:m}=a,V=d.getValidatorItem(m.type);if(!V)return!1;const E=o.getRuleById(s,p,u);if(!E)return!1;const f={...E,...m};if(!V.validatorFormula(f,s,p).success)return!1;const S={unitId:s,subUnitId:p,ruleId:u,payload:{type:h.SETTING,payload:{...m,...V.normalizeFormula(f,s,p)}}},ea=[{id:_.id,params:S}],ia={unitId:s,subUnitId:p,ruleId:u,payload:{type:h.SETTING,payload:D(E)}},ra=[{id:_.id,params:ia}];return t.pushUndoRedo({unitID:s,redoMutations:ea,undoMutations:ra}),e.executeCommand(_.id,S),!0}},F={type:r.CommandType.COMMAND,id:"data-validation.command.removeAll",handler(n,a){if(n.get(r.ILogService).error("[Deprecated]: `RemoveAllDataValidationCommand` is deprecated, please use `RemoveSheetAllDataValidationCommand` in `@univerjs/sheets-data-validation` instead!"),!a)return!1;const{unitId:e,subUnitId:t}=a,o=n.get(r.ICommandService),d=n.get(l.DataValidationModel),s=n.get(r.IUndoRedoService),p=[...d.getRules(e,t)],u={unitId:e,subUnitId:t,ruleId:p.map(E=>E.uid)},m=[{id:v.id,params:u}],V=[{id:O.id,params:{unitId:e,subUnitId:t,rule:p}}];return s.pushUndoRedo({redoMutations:m,undoMutations:V,unitID:e}),o.executeCommand(v.id,u),!0}},W="data-validation.config",y={};var k=Object.getOwnPropertyDescriptor,x=(n,a,i,e)=>{for(var t=e>1?void 0:e?k(a,i):a,o=n.length-1,d;o>=0;o--)(d=n[o])&&(t=d(t)||t);return t},A=(n,a)=>(i,e)=>a(i,e,n);const J="UNIVER_DATA_VALIDATION_PLUGIN";l.UniverDataValidationPlugin=(T=class extends r.Plugin{constructor(a=y,i,e,t){super(),this._config=a,this._injector=i,this._commandService=e,this._configService=t;const{...o}=r.merge({},y,this._config);this._configService.setConfig(W,o)}onStarting(){[[l.DataValidationModel],[R],[l.DataValidationResourceController]].forEach(a=>this._injector.add(a)),[j,F,H,Q,$,O,_,v].forEach(a=>{this._commandService.registerCommand(a)})}onReady(){this._injector.get(l.DataValidationResourceController)}},c(T,"pluginName",J),c(T,"type",r.UniverInstanceType.UNIVER_SHEET),T),l.UniverDataValidationPlugin=x([A(1,r.Inject(r.Injector)),A(2,r.ICommandService),A(3,r.IConfigService)],l.UniverDataValidationPlugin),r.DataValidationOperator.BETWEEN+"",r.DataValidationOperator.EQUAL+"",r.DataValidationOperator.GREATER_THAN+"",r.DataValidationOperator.GREATER_THAN_OR_EQUAL+"",r.DataValidationOperator.LESS_THAN+"",r.DataValidationOperator.LESS_THAN_OR_EQUAL+"",r.DataValidationOperator.NOT_BETWEEN+"",r.DataValidationOperator.NOT_EQUAL+"";const z={[r.DataValidationOperator.BETWEEN]:"dataValidation.ruleName.between",[r.DataValidationOperator.EQUAL]:"dataValidation.ruleName.equal",[r.DataValidationOperator.GREATER_THAN]:"dataValidation.ruleName.greaterThan",[r.DataValidationOperator.GREATER_THAN_OR_EQUAL]:"dataValidation.ruleName.greaterThanOrEqual",[r.DataValidationOperator.LESS_THAN]:"dataValidation.ruleName.lessThan",[r.DataValidationOperator.LESS_THAN_OR_EQUAL]:"dataValidation.ruleName.lessThanOrEqual",[r.DataValidationOperator.NOT_BETWEEN]:"dataValidation.ruleName.notBetween",[r.DataValidationOperator.NOT_EQUAL]:"dataValidation.ruleName.notEqual"},K={[r.DataValidationOperator.BETWEEN]:"dataValidation.errorMsg.between",[r.DataValidationOperator.EQUAL]:"dataValidation.errorMsg.equal",[r.DataValidationOperator.GREATER_THAN]:"dataValidation.errorMsg.greaterThan",[r.DataValidationOperator.GREATER_THAN_OR_EQUAL]:"dataValidation.errorMsg.greaterThanOrEqual",[r.DataValidationOperator.LESS_THAN]:"dataValidation.errorMsg.lessThan",[r.DataValidationOperator.LESS_THAN_OR_EQUAL]:"dataValidation.errorMsg.lessThanOrEqual",[r.DataValidationOperator.NOT_BETWEEN]:"dataValidation.errorMsg.notBetween",[r.DataValidationOperator.NOT_EQUAL]:"dataValidation.errorMsg.notEqual"},Y={[r.DataValidationOperator.BETWEEN]:"dataValidation.textLength.errorMsg.between",[r.DataValidationOperator.EQUAL]:"dataValidation.textLength.errorMsg.equal",[r.DataValidationOperator.GREATER_THAN]:"dataValidation.textLength.errorMsg.greaterThan",[r.DataValidationOperator.GREATER_THAN_OR_EQUAL]:"dataValidation.textLength.errorMsg.greaterThanOrEqual",[r.DataValidationOperator.LESS_THAN]:"dataValidation.textLength.errorMsg.lessThan",[r.DataValidationOperator.LESS_THAN_OR_EQUAL]:"dataValidation.textLength.errorMsg.lessThanOrEqual",[r.DataValidationOperator.NOT_BETWEEN]:"dataValidation.textLength.errorMsg.notBetween",[r.DataValidationOperator.NOT_EQUAL]:"dataValidation.textLength.errorMsg.notEqual"},X=[r.DataValidationOperator.BETWEEN,r.DataValidationOperator.NOT_BETWEEN];var Z=Object.getOwnPropertyDescriptor,aa=(n,a,i,e)=>{for(var t=e>1?void 0:e?Z(a,i):a,o=n.length-1,d;o>=0;o--)(d=n[o])&&(t=d(t)||t);return t},U=(n,a)=>(i,e)=>a(i,e,n);const L="{FORMULA1}",C="{FORMULA2}",ta={[r.DataValidationOperator.BETWEEN]:"dataValidation.operators.between",[r.DataValidationOperator.EQUAL]:"dataValidation.operators.equal",[r.DataValidationOperator.GREATER_THAN]:"dataValidation.operators.greaterThan",[r.DataValidationOperator.GREATER_THAN_OR_EQUAL]:"dataValidation.operators.greaterThanOrEqual",[r.DataValidationOperator.LESS_THAN]:"dataValidation.operators.lessThan",[r.DataValidationOperator.LESS_THAN_OR_EQUAL]:"dataValidation.operators.lessThanOrEqual",[r.DataValidationOperator.NOT_BETWEEN]:"dataValidation.operators.notBetween",[r.DataValidationOperator.NOT_EQUAL]:"dataValidation.operators.notEqual"};l.BaseDataValidator=class{constructor(a,i){c(this,"offsetFormulaByRange",!0);c(this,"formulaInput");c(this,"canvasRender",null);c(this,"dropdown");c(this,"optionsInput");c(this,"skipDefaultFontRender");this.localeService=a,this.injector=i}get operatorNames(){return this.operators.map(a=>this.localeService.t(ta[a]))}get titleStr(){return this.localeService.t(this.title)}generateRuleName(a){var e,t;if(!a.operator)return this.titleStr;const i=this.localeService.t(z[a.operator]).replace(L,(e=a.formula1)!=null?e:"").replace(C,(t=a.formula2)!=null?t:"");return`${this.titleStr} ${i}`}generateRuleErrorMessage(a,i){var t,o;return a.operator?`${this.localeService.t(K[a.operator]).replace(L,(t=a.formula1)!=null?t:"").replace(C,(o=a.formula2)!=null?o:"")}`:this.titleStr}getExtraStyle(a,i,e,t,o){}getRuleFinalError(a,i){return a.showErrorMessage&&a.error?a.error:this.generateRuleErrorMessage(a,i)}isEmptyCellValue(a){return a===""||a===void 0||a===null}normalizeFormula(a,i,e){return{formula1:a.formula1,formula2:a.formula2}}async isValidType(a,i,e){return!0}transform(a,i,e){return a}async validatorIsEqual(a,i,e){const{formula1:t}=i,{value:o}=a;return Number.isNaN(t)?!0:o===t}async validatorIsNotEqual(a,i,e){const{formula1:t}=i;return Number.isNaN(t)?!0:a.value!==t}async validatorIsBetween(a,i,e){const{formula1:t,formula2:o}=i;if(Number.isNaN(t)||Number.isNaN(o))return!0;const d=Math.min(t,o),s=Math.max(t,o);return a.value>=d&&a.value<=s}async validatorIsNotBetween(a,i,e){const{formula1:t,formula2:o}=i;if(Number.isNaN(t)||Number.isNaN(o))return!0;const d=Math.min(t,o),s=Math.max(t,o);return a.value<d||a.value>s}async validatorIsGreaterThan(a,i,e){const{formula1:t}=i;return Number.isNaN(t)?!0:a.value>t}async validatorIsGreaterThanOrEqual(a,i,e){const{formula1:t}=i;return Number.isNaN(t)?!0:a.value>=t}async validatorIsLessThan(a,i,e){const{formula1:t}=i;return Number.isNaN(t)?!0:a.value<t}async validatorIsLessThanOrEqual(a,i,e){const{formula1:t}=i;return Number.isNaN(t)?!0:a.value<=t}async validator(a,i){const{value:e,unitId:t,subUnitId:o}=a,d=this.isEmptyCellValue(e),{allowBlank:s=!0,operator:p}=i;if(d)return s;const u=await this.parseFormula(i,t,o,a.row,a.column);if(!u.isFormulaValid||!await this.isValidType(a,u,i))return!1;if(!r.Tools.isDefine(p))return!0;const m=this.transform(a,u,i);switch(p){case r.DataValidationOperator.BETWEEN:return this.validatorIsBetween(m,u,i);case r.DataValidationOperator.EQUAL:return this.validatorIsEqual(m,u,i);case r.DataValidationOperator.GREATER_THAN:return this.validatorIsGreaterThan(m,u,i);case r.DataValidationOperator.GREATER_THAN_OR_EQUAL:return this.validatorIsGreaterThanOrEqual(m,u,i);case r.DataValidationOperator.LESS_THAN:return this.validatorIsLessThan(m,u,i);case r.DataValidationOperator.LESS_THAN_OR_EQUAL:return this.validatorIsLessThanOrEqual(m,u,i);case r.DataValidationOperator.NOT_BETWEEN:return this.validatorIsNotBetween(m,u,i);case r.DataValidationOperator.NOT_EQUAL:return this.validatorIsNotEqual(m,u,i);default:throw new Error("Unknown operator.")}}},l.BaseDataValidator=aa([U(0,r.Inject(r.LocaleService)),U(1,r.Inject(r.Injector))],l.BaseDataValidator),l.AddDataValidationMutation=O,l.DataValidatorRegistryScope=I,l.DataValidatorRegistryService=R,l.RemoveDataValidationMutation=v,l.TWO_FORMULA_OPERATOR_COUNT=X,l.TextLengthErrorTitleMap=Y,l.UpdateDataValidationMutation=_,l.UpdateRuleType=h,l.getRuleOptions=N,l.getRuleSetting=D,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/data-validation",
|
|
3
|
-
"version": "0.6.0
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Data validation library for Univer",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"rxjs": ">=7.0.0"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@univerjs/core": "0.6.0
|
|
51
|
+
"@univerjs/core": "0.6.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@univerjs/protocol": "0.1.43",
|
|
@@ -57,8 +57,8 @@
|
|
|
57
57
|
"vite": "^6.1.0",
|
|
58
58
|
"vitest": "^3.0.5",
|
|
59
59
|
"@univerjs-infra/shared": "0.6.0",
|
|
60
|
-
"@univerjs/core": "0.6.0
|
|
61
|
-
"@univerjs/sheets": "0.6.0
|
|
60
|
+
"@univerjs/core": "0.6.0",
|
|
61
|
+
"@univerjs/sheets": "0.6.0"
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|
|
64
64
|
"dev": "vite",
|