@univerjs/sheets-data-validation 0.5.0 → 0.5.1-nightly.202411301606
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +1407 -1914
- package/lib/types/controllers/config.schema.d.ts +1 -1
- package/lib/types/controllers/dv-formula-ref-range.controller.d.ts +3 -1
- package/lib/types/controllers/dv-ref-range.controller.d.ts +3 -3
- package/lib/types/facade/f-data-validation-builder.d.ts +2 -2
- package/lib/types/facade/f-data-validation.d.ts +1 -1
- package/lib/types/models/rule-matrix.d.ts +2 -0
- package/lib/types/models/sheet-data-validation-model.d.ts +1 -1
- package/lib/types/services/dv-cache.service.d.ts +4 -4
- package/lib/types/services/dv-custom-formula.service.d.ts +3 -2
- package/lib/types/services/dv-formula.service.d.ts +3 -2
- package/lib/types/utils/formula.d.ts +2 -1
- package/lib/types/validators/any-validator.d.ts +1 -0
- package/lib/types/validators/checkbox-validator.d.ts +1 -0
- package/lib/types/validators/date-validator.d.ts +1 -9
- package/lib/types/validators/decimal-validator.d.ts +1 -9
- package/lib/types/validators/list-multiple-validator.d.ts +1 -0
- package/lib/types/validators/list-validator.d.ts +2 -1
- package/lib/types/validators/text-length-validator.d.ts +4 -13
- package/lib/types/validators/whole-validator.d.ts +4 -12
- package/lib/umd/index.js +1 -1
- package/package.json +12 -13
- package/LICENSE +0 -176
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(h,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("@univerjs/core"),require("@univerjs/data-validation"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/sheets-formula"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/data-validation","@univerjs/sheets","rxjs","@univerjs/sheets-formula","@univerjs/engine-formula"],s):(h=typeof globalThis<"u"?globalThis:h||self,s(h.UniverSheetsDataValidation={},h.UniverCore,h.UniverDataValidation,h.UniverSheets,h.rxjs,h.UniverSheetsFormula,h.UniverEngineFormula))})(this,function(h,s,p,D,b,Y,O){"use strict";var Wt=Object.defineProperty;var xt=(h,s,p)=>s in h?Wt(h,s,{enumerable:!0,configurable:!0,writable:!0,value:p}):h[s]=p;var _=(h,s,p)=>xt(h,typeof s!="symbol"?s+"":s,p);const Se="SHEET_DATA_VALIDATION_PLUGIN";var $e=Object.defineProperty,We=Object.getOwnPropertyDescriptor,xe=(o,i,e,t)=>{for(var a=t>1?void 0:t?We(i,e):i,r=o.length-1,n;r>=0;r--)(n=o[r])&&(a=(t?n(i,e,a):n(a))||a);return t&&a&&$e(i,e,a),a},ke=(o,i)=>(e,t)=>i(e,t,o);h.DataValidationCacheService=class extends s.Disposable{constructor(e){super();_(this,"_cacheMatrix",new Map);_(this,"_dirtyRanges$",new b.Subject);_(this,"dirtyRanges$",this._dirtyRanges$.asObservable());this._commandService=e,this._initDirtyRanges()}_initDirtyRanges(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===D.SetRangeValuesMutation.id){const{cellValue:t,unitId:a,subUnitId:r}=e.params;if(t){const n=new s.ObjectMatrix(t).getDataRange();if(n.endRow===-1)return;this.markRangeDirty(a,r,[n])}}}))}_ensureCache(e,t){let a=this._cacheMatrix.get(e);a||(a=new Map,this._cacheMatrix.set(e,a));let r=a.get(t);return r||(r=new s.ObjectMatrix,a.set(t,r)),r}ensureCache(e,t){return this._ensureCache(e,t)}addRule(e,t,a){this.markRangeDirty(e,t,a.ranges)}removeRule(e,t,a){this._deleteRange(e,t,a.ranges)}markRangeDirty(e,t,a){const r=this._ensureCache(e,t);a.forEach(n=>{s.Range.foreach(n,(l,u)=>{r.setValue(l,u,void 0)})}),this._dirtyRanges$.next({unitId:e,subUnitId:t,ranges:a})}markCellDirty(e,t,a,r){this._ensureCache(e,t).setValue(a,r,void 0),this._dirtyRanges$.next({unitId:e,subUnitId:t,ranges:[{startRow:a,startColumn:r,endRow:a,endColumn:r}]})}_deleteRange(e,t,a){const r=this._ensureCache(e,t);a.forEach(n=>{s.Range.foreach(n,(l,u)=>{r.realDeleteValue(l,u)})}),this._dirtyRanges$.next({unitId:e,subUnitId:t,ranges:a})}getValue(e,t,a,r){return this._ensureCache(e,t).getValue(a,r)}setValue(e,t,a,r,n){return this._ensureCache(e,t).setValue(a,r,n)}},h.DataValidationCacheService=xe([ke(0,s.Inject(s.ICommandService))],h.DataValidationCacheService);function A(o){var i,e;return(e=(i=o==null?void 0:o[0])==null?void 0:i[0])==null?void 0:e.v}function j(o){var i;return(i=o==null?void 0:o[0])==null?void 0:i[0]}function y(o){return!O.ERROR_TYPE_SET.has(o)}function H(o){return o!==s.DataValidationType.LIST&&o!==s.DataValidationType.LIST_MULTIPLE&&o!==s.DataValidationType.CHECKBOX&&o!==s.DataValidationType.ANY}var qe=Object.defineProperty,Ge=Object.getOwnPropertyDescriptor,Qe=(o,i,e,t)=>{for(var a=t>1?void 0:t?Ge(i,e):i,r=o.length-1,n;r>=0;r--)(n=o[r])&&(a=(t?n(i,e,a):n(a))||a);return t&&a&&qe(i,e,a),a},X=(o,i)=>(e,t)=>i(e,t,o);h.DataValidationCustomFormulaService=class extends s.Disposable{constructor(e,t,a,r){super();_(this,"_ruleFormulaMap",new Map);_(this,"_ruleFormulaMap2",new Map);this._instanceSrv=e,this._registerOtherFormulaService=t,this._dataValidationModel=a,this._dataValidationCacheService=r,this._initFormulaResultHandler()}_initFormulaResultHandler(){this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe(e=>{for(const t in e){const a=e[t];if(this._instanceSrv.getUnitType(t)===s.UniverInstanceType.UNIVER_SHEET)for(const n in a){const l=a[n],{ruleFormulaMap:u}=this._ensureMaps(t,n);l.forEach(d=>{var f,v;const c=u.get((f=d.extra)==null?void 0:f.ruleId),m=this._dataValidationModel.getRuleById(t,n,(v=d.extra)==null?void 0:v.ruleId);m&&c&&this._dataValidationCacheService.markRangeDirty(t,n,m.ranges)})}}}))}_ensureMaps(e,t){let a=this._ruleFormulaMap.get(e),r=this._ruleFormulaMap2.get(e);a||(a=new Map,this._ruleFormulaMap.set(e,a)),r||(r=new Map,this._ruleFormulaMap2.set(e,r));let n=a.get(t);n||(n=new Map,a.set(t,n));let l=r.get(t);return l||(l=new Map,r.set(t,l)),{ruleFormulaMap:n,ruleFormulaMap2:l}}_registerFormula(e,t,a,r,n){return this._registerOtherFormulaService.registerFormulaWithRange(e,t,r,n,{ruleId:a})}deleteByRuleId(e,t,a){const{ruleFormulaMap:r,ruleFormulaMap2:n}=this._ensureMaps(e,t),l=this._dataValidationModel.getRuleById(e,t,a),u=r.get(a);if(!l||!u)return;const d=r.get(a);d&&(r.delete(a),this._registerOtherFormulaService.deleteFormula(e,t,[d.formulaId]));const c=n.get(a);c&&(n.delete(a),this._registerOtherFormulaService.deleteFormula(e,t,[c.formulaId]))}_addFormulaByRange(e,t,a,r,n,l){const{ruleFormulaMap:u,ruleFormulaMap2:d}=this._ensureMaps(e,t),c=l[0].startRow,m=l[0].startColumn;if(r&&s.isFormulaString(r)){const f=this._registerFormula(e,t,a,r,l);u.set(a,{formula:r,originCol:m,originRow:c,formulaId:f})}if(n&&s.isFormulaString(n)){const f=this._registerFormula(e,t,a,n,l);d.set(a,{formula:n,originCol:m,originRow:c,formulaId:f})}}addRule(e,t,a){if(H(a.type)){const{ranges:r,formula1:n,formula2:l,uid:u}=a;this._addFormulaByRange(e,t,u,n,l,r)}}async getCellFormulaValue(e,t,a,r,n){var S,R;const{ruleFormulaMap:l}=this._ensureMaps(e,t),u=l.get(a);if(!u)return Promise.resolve(void 0);const d=await this._registerOtherFormulaService.getFormulaValue(e,t,u.formulaId),{originRow:c,originCol:m}=u,f=r-c,v=n-m;return j((R=(S=d==null?void 0:d.result)==null?void 0:S[f])==null?void 0:R[v])}async getCellFormula2Value(e,t,a,r,n){var S,R;const{ruleFormulaMap2:l}=this._ensureMaps(e,t),u=l.get(a);if(!u)return Promise.resolve(void 0);const d=await this._registerOtherFormulaService.getFormulaValue(e,t,u.formulaId),{originRow:c,originCol:m}=u,f=r-c,v=n-m;return j((R=(S=d==null?void 0:d.result)==null?void 0:S[f])==null?void 0:R[v])}getCellFormulaValueSync(e,t,a,r,n){var S,R;const{ruleFormulaMap:l}=this._ensureMaps(e,t),u=l.get(a);if(!u)return;const d=this._registerOtherFormulaService.getFormulaValueSync(e,t,u.formulaId),{originRow:c,originCol:m}=u,f=r-c,v=n-m;return j((R=(S=d==null?void 0:d.result)==null?void 0:S[f])==null?void 0:R[v])}getCellFormula2ValueSync(e,t,a,r,n){var S,R;const{ruleFormulaMap2:l}=this._ensureMaps(e,t),u=l.get(a);if(!u)return;const d=this._registerOtherFormulaService.getFormulaValueSync(e,t,u.formulaId),{originRow:c,originCol:m}=u,f=r-c,v=n-m;return j((R=(S=d==null?void 0:d.result)==null?void 0:S[f])==null?void 0:R[v])}getRuleFormulaInfo(e,t,a){const{ruleFormulaMap:r}=this._ensureMaps(e,t);return r.get(a)}},h.DataValidationCustomFormulaService=Qe([X(0,s.IUniverInstanceService),X(1,s.Inject(Y.RegisterOtherFormulaService)),X(2,s.Inject(p.DataValidationModel)),X(3,s.Inject(h.DataValidationCacheService))],h.DataValidationCustomFormulaService);var Ye=Object.defineProperty,Xe=Object.getOwnPropertyDescriptor,Ke=(o,i,e,t)=>{for(var a=t>1?void 0:t?Xe(i,e):i,r=o.length-1,n;r>=0;r--)(n=o[r])&&(a=(t?n(i,e,a):n(a))||a);return t&&a&&Ye(i,e,a),a},K=(o,i)=>(e,t)=>i(e,t,o);h.DataValidationFormulaService=class extends s.Disposable{constructor(e,t,a,r){super();_(this,"_formulaRuleMap",new Map);this._instanceService=e,this._registerOtherFormulaService=t,this._dataValidationCacheService=a,this._dataValidationModel=r,this._initFormulaResultHandler()}_initFormulaResultHandler(){this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe(e=>{for(const t in e){const a=e[t];if(this._instanceService.getUnitType(t)===s.UniverInstanceType.UNIVER_SHEET)for(const n in a){const l=a[n],u=this._ensureRuleFormulaMap(t,n);l.forEach(d=>{var c,m;if(u.get((c=d.extra)==null?void 0:c.ruleId)){const f=this._dataValidationModel.getRuleById(t,n,(m=d.extra)==null?void 0:m.ruleId);f&&this._dataValidationCacheService.markRangeDirty(t,n,f.ranges)}})}}}))}_ensureRuleFormulaMap(e,t){let a=this._formulaRuleMap.get(e);a||(a=new Map,this._formulaRuleMap.set(e,a));let r=a.get(t);return r||(r=new Map,a.set(t,r)),r}_registerSingleFormula(e,t,a,r){const n=[{startColumn:0,endColumn:0,startRow:0,endRow:0}];return this._registerOtherFormulaService.registerFormulaWithRange(e,t,a,n,{ruleId:r})}addRule(e,t,a){if(!H(a.type)&&a.type!==s.DataValidationType.CHECKBOX){const{formula1:r,formula2:n,uid:l}=a,u=s.isFormulaString(r),d=s.isFormulaString(n);if(!u&&!d)return;const c=this._ensureRuleFormulaMap(e,t),m=[void 0,void 0];if(u){const f=this._registerSingleFormula(e,t,r,l);m[0]={id:f,text:r}}if(d){const f=this._registerSingleFormula(e,t,n,l);m[1]={id:f,text:n}}c.set(l,m)}}removeRule(e,t,a){const n=this._ensureRuleFormulaMap(e,t).get(a);if(!n)return;const[l,u]=n,d=[l==null?void 0:l.id,u==null?void 0:u.id].filter(Boolean);d.length&&this._registerOtherFormulaService.deleteFormula(e,t,d)}getRuleFormulaResult(e,t,a){const n=this._ensureRuleFormulaMap(e,t).get(a);if(!n)return Promise.resolve(null);const l=async u=>u&&this._registerOtherFormulaService.getFormulaValue(e,t,u.id);return Promise.all([l(n[0]),l(n[1])])}getRuleFormulaResultSync(e,t,a){const n=this._ensureRuleFormulaMap(e,t).get(a);if(n)return n.map(l=>{if(l)return this._registerOtherFormulaService.getFormulaValueSync(e,t,l.id)})}getRuleFormulaInfo(e,t,a){return this._ensureRuleFormulaMap(e,t).get(a)}},h.DataValidationFormulaService=Ke([K(0,s.IUniverInstanceService),K(1,s.Inject(Y.RegisterOtherFormulaService)),K(2,s.Inject(h.DataValidationCacheService)),K(3,s.Inject(p.DataValidationModel))],h.DataValidationFormulaService);function U(o){return s.getOriginCellValue(o)}function Re(o){var i;return String((i=U(o))!=null?i:"")}const ze=class ve{constructor(i,e){this.low=i,this.high=e}clone(){return new ve(this.low,this.high)}get max(){return this.clone()}less_than(i){return this.low<i.low||this.low===i.low&&this.high<i.high}equal_to(i){return this.low===i.low&&this.high===i.high}intersect(i){return!this.not_intersect(i)}not_intersect(i){return this.high<i.low||i.high<this.low}merge(i){return new ve(this.low===void 0?i.low:this.low<i.low?this.low:i.low,this.high===void 0?i.high:this.high>i.high?this.high:i.high)}output(){return[this.low,this.high]}static comparable_max(i,e){return i.merge(e)}static comparable_less_than(i,e){return i<e}},T=0,V=1;class F{constructor(i=void 0,e=void 0,t=null,a=null,r=null,n=V){if(this.left=t,this.right=a,this.parent=r,this.color=n,this.item={key:i,value:e},i&&i instanceof Array&&i.length===2&&!Number.isNaN(i[0])&&!Number.isNaN(i[1])){let[l,u]=i;l>u&&([l,u]=[u,l]),this.item.key=new ze(l,u)}this.max=this.item.key?this.item.key.max:void 0}isNil(){return this.item.key===void 0&&this.item.value===void 0&&this.left===null&&this.right===null&&this.color===V}_value_less_than(i){return this.item.value&&i.item.value&&this.item.value.less_than?this.item.value.less_than(i.item.value):this.item.value<i.item.value}less_than(i){return this.item.value===this.item.key&&i.item.value===i.item.key?this.item.key.less_than(i.item.key):this.item.key.less_than(i.item.key)||this.item.key.equal_to(i.item.key)&&this._value_less_than(i)}_value_equal(i){return this.item.value&&i.item.value&&this.item.value.equal_to?this.item.value.equal_to(i.item.value):this.item.value===i.item.value}equal_to(i){return this.item.value===this.item.key&&i.item.value===i.item.key?this.item.key.equal_to(i.item.key):this.item.key.equal_to(i.item.key)&&this._value_equal(i)}intersect(i){return this.item.key.intersect(i.item.key)}copy_data(i){this.item.key=i.item.key,this.item.value=i.item.value}update_max(){if(this.max=this.item.key?this.item.key.max:void 0,this.right&&this.right.max){const i=this.item.key.constructor.comparable_max;this.max=i(this.max,this.right.max)}if(this.left&&this.left.max){const i=this.item.key.constructor.comparable_max;this.max=i(this.max,this.left.max)}}not_intersect_left_subtree(i){const e=this.item.key.constructor.comparable_less_than;let t=this.left.max.high!==void 0?this.left.max.high:this.left.max;return e(t,i.item.key.low)}not_intersect_right_subtree(i){const e=this.item.key.constructor.comparable_less_than;let t=this.right.max.low!==void 0?this.right.max.low:this.right.item.key.low;return e(i.item.key.high,t)}}class le{constructor(){this.root=null,this.nil_node=new F}get size(){let i=0;return this.tree_walk(this.root,()=>i++),i}get keys(){let i=[];return this.tree_walk(this.root,e=>i.push(e.item.key.output?e.item.key.output():e.item.key)),i}get values(){let i=[];return this.tree_walk(this.root,e=>i.push(e.item.value)),i}get items(){let i=[];return this.tree_walk(this.root,e=>i.push({key:e.item.key.output?e.item.key.output():e.item.key,value:e.item.value})),i}isEmpty(){return this.root==null||this.root===this.nil_node}clear(){this.root=null}insert(i,e=i){if(i===void 0)return;let t=new F(i,e,this.nil_node,this.nil_node,null,T);return this.tree_insert(t),this.recalc_max(t),t}exist(i,e=i){let t=new F(i,e);return!!this.tree_search(this.root,t)}remove(i,e=i){let t=new F(i,e),a=this.tree_search(this.root,t);return a&&this.tree_delete(a),a}search(i,e=(t,a)=>t===a?a.output():t){let t=new F(i),a=[];return this.tree_search_interval(this.root,t,a),a.map(r=>e(r.item.value,r.item.key))}intersect_any(i){let e=new F(i);return this.tree_find_any_interval(this.root,e)}forEach(i){this.tree_walk(this.root,e=>i(e.item.key,e.item.value))}map(i){const e=new le;return this.tree_walk(this.root,t=>e.insert(t.item.key,i(t.item.value,t.item.key))),e}*iterate(i,e=(t,a)=>t===a?a.output():t){let t;for(i?t=this.tree_search_nearest_forward(this.root,new F(i)):this.root&&(t=this.local_minimum(this.root));t;)yield e(t.item.value,t.item.key),t=this.tree_successor(t)}recalc_max(i){let e=i;for(;e.parent!=null;)e.parent.update_max(),e=e.parent}tree_insert(i){let e=this.root,t=null;if(this.root==null||this.root===this.nil_node)this.root=i;else{for(;e!==this.nil_node;)t=e,i.less_than(e)?e=e.left:e=e.right;i.parent=t,i.less_than(t)?t.left=i:t.right=i}this.insert_fixup(i)}insert_fixup(i){let e,t;for(e=i;e!==this.root&&e.parent.color===T;)e.parent===e.parent.parent.left?(t=e.parent.parent.right,t.color===T?(e.parent.color=V,t.color=V,e.parent.parent.color=T,e=e.parent.parent):(e===e.parent.right&&(e=e.parent,this.rotate_left(e)),e.parent.color=V,e.parent.parent.color=T,this.rotate_right(e.parent.parent))):(t=e.parent.parent.left,t.color===T?(e.parent.color=V,t.color=V,e.parent.parent.color=T,e=e.parent.parent):(e===e.parent.left&&(e=e.parent,this.rotate_right(e)),e.parent.color=V,e.parent.parent.color=T,this.rotate_left(e.parent.parent)));this.root.color=V}tree_delete(i){let e,t;i.left===this.nil_node||i.right===this.nil_node?e=i:e=this.tree_successor(i),e.left!==this.nil_node?t=e.left:t=e.right,t.parent=e.parent,e===this.root?this.root=t:(e===e.parent.left?e.parent.left=t:e.parent.right=t,e.parent.update_max()),this.recalc_max(t),e!==i&&(i.copy_data(e),i.update_max(),this.recalc_max(i)),e.color===V&&this.delete_fixup(t)}delete_fixup(i){let e=i,t;for(;e!==this.root&&e.parent!=null&&e.color===V;)e===e.parent.left?(t=e.parent.right,t.color===T&&(t.color=V,e.parent.color=T,this.rotate_left(e.parent),t=e.parent.right),t.left.color===V&&t.right.color===V?(t.color=T,e=e.parent):(t.right.color===V&&(t.color=T,t.left.color=V,this.rotate_right(t),t=e.parent.right),t.color=e.parent.color,e.parent.color=V,t.right.color=V,this.rotate_left(e.parent),e=this.root)):(t=e.parent.left,t.color===T&&(t.color=V,e.parent.color=T,this.rotate_right(e.parent),t=e.parent.left),t.left.color===V&&t.right.color===V?(t.color=T,e=e.parent):(t.left.color===V&&(t.color=T,t.right.color=V,this.rotate_left(t),t=e.parent.left),t.color=e.parent.color,e.parent.color=V,t.left.color=V,this.rotate_right(e.parent),e=this.root));e.color=V}tree_search(i,e){if(!(i==null||i===this.nil_node))return e.equal_to(i)?i:e.less_than(i)?this.tree_search(i.left,e):this.tree_search(i.right,e)}tree_search_nearest_forward(i,e){let t,a=i;for(;a&&a!==this.nil_node;)a.less_than(e)?a.intersect(e)?(t=a,a=a.left):a=a.right:((!t||a.less_than(t))&&(t=a),a=a.left);return t||null}tree_search_interval(i,e,t){i!=null&&i!==this.nil_node&&(i.left!==this.nil_node&&!i.not_intersect_left_subtree(e)&&this.tree_search_interval(i.left,e,t),i.intersect(e)&&t.push(i),i.right!==this.nil_node&&!i.not_intersect_right_subtree(e)&&this.tree_search_interval(i.right,e,t))}tree_find_any_interval(i,e){let t=!1;return i!=null&&i!==this.nil_node&&(i.left!==this.nil_node&&!i.not_intersect_left_subtree(e)&&(t=this.tree_find_any_interval(i.left,e)),t||(t=i.intersect(e)),!t&&i.right!==this.nil_node&&!i.not_intersect_right_subtree(e)&&(t=this.tree_find_any_interval(i.right,e))),t}local_minimum(i){let e=i;for(;e.left!=null&&e.left!==this.nil_node;)e=e.left;return e}local_maximum(i){let e=i;for(;e.right!=null&&e.right!==this.nil_node;)e=e.right;return e}tree_successor(i){let e,t,a;if(i.right!==this.nil_node)e=this.local_minimum(i.right);else{for(t=i,a=i.parent;a!=null&&a.right===t;)t=a,a=a.parent;e=a}return e}rotate_left(i){let e=i.right;i.right=e.left,e.left!==this.nil_node&&(e.left.parent=i),e.parent=i.parent,i===this.root?this.root=e:i===i.parent.left?i.parent.left=e:i.parent.right=e,e.left=i,i.parent=e,i!=null&&i!==this.nil_node&&i.update_max(),e=i.parent,e!=null&&e!==this.nil_node&&e.update_max()}rotate_right(i){let e=i.left;i.left=e.right,e.right!==this.nil_node&&(e.right.parent=i),e.parent=i.parent,i===this.root?this.root=e:i===i.parent.left?i.parent.left=e:i.parent.right=e,e.right=i,i.parent=e,i!==null&&i!==this.nil_node&&i.update_max(),e=i.parent,e!=null&&e!==this.nil_node&&e.update_max()}tree_walk(i,e){i!=null&&i!==this.nil_node&&(this.tree_walk(i.left,e),e(i),this.tree_walk(i.right,e))}testRedBlackProperty(){let i=!0;return this.tree_walk(this.root,function(e){e.color===T&&(e.left.color===V&&e.right.color===V||(i=!1))}),i}testBlackHeightProperty(i){let e=0,t=0,a=0;if(i.color===V&&e++,i.left!==this.nil_node?t=this.testBlackHeightProperty(i.left):t=1,i.right!==this.nil_node?a=this.testBlackHeightProperty(i.right):a=1,t!==a)throw new Error("Red-black height property violated");return e+=t,e}}class ue{constructor(i,e,t,a,r=!1){_(this,"_map");_(this,"_tree",new Map);_(this,"_dirty",!0);_(this,"_buildTree",()=>{if(!this._dirty||this._disableTree)return;const i=new Map;this._map.forEach((t,a)=>{t.forEach(r=>{for(let n=r.startColumn;n<=r.endColumn;n++){let l=i.get(n);l||(l=[],i.set(n,l)),l.push({startRow:r.startRow,endRow:r.endRow,ruleId:a})}})});const e=new Map;i.forEach((t,a)=>{const r=new le;t.forEach(n=>{r.insert([n.startRow,n.endRow],n.ruleId)}),e.set(a,r)}),this._tree=e,this._dirty=!1});_(this,"_debonceBuildTree",s.debounce(this._buildTree,0));this._unitId=e,this._subUnitId=t,this._univerInstanceService=a,this._disableTree=r,this._map=i,this._buildTree()}get _worksheet(){var i;return(i=this._univerInstanceService.getUnit(this._unitId,s.UniverInstanceType.UNIVER_SHEET))==null?void 0:i.getSheetBySheetId(this._subUnitId)}addRule(i){if(!this._worksheet)return;const e=i.uid,t=i.ranges.map(a=>s.Range.transformRange(a,this._worksheet));this._map.forEach((a,r)=>{const n=s.Rectangle.subtractMulti(a,t);n.length===0?this._map.delete(r):this._map.set(r,n)}),this._dirty=!0,this._map.set(e,t),this._debonceBuildTree()}removeRange(i){if(!this._worksheet)return;const e=i.map(t=>s.Range.transformRange(t,this._worksheet));this._map.forEach((t,a)=>{const r=s.Rectangle.subtractMulti(t,e);r.length===0?this._map.delete(a):this._map.set(a,r)}),this._dirty=!0,this._debonceBuildTree()}removeRule(i){this._map.delete(i.uid),this._dirty=!0,this._debonceBuildTree()}updateRange(i,e){if(!this._worksheet)return;this._map.delete(i);const t=e.map(a=>s.Range.transformRange(a,this._worksheet));this._map.forEach((a,r)=>{const n=s.Rectangle.subtractMulti(a,t);n.length===0?this._map.delete(r):this._map.set(r,n)}),this._map.set(i,t),this._dirty=!0,this._debonceBuildTree()}addRangeRules(i){i.forEach(({id:e,ranges:t})=>{if(!t.length)return;let a=this._map.get(e);a?(this._map.set(e,s.Rectangle.mergeRanges([...a,...t])),a=this._map.get(e)):(a=t,this._map.set(e,a)),this._map.forEach((r,n)=>{if(n===e)return;const l=s.Rectangle.subtractMulti(r,t);l.length===0?this._map.delete(n):this._map.set(n,l)})}),this._dirty=!0,this._debonceBuildTree()}diff(i){const e=[];let t=0;return i.forEach((a,r)=>{var u;const n=(u=this._map.get(a.uid))!=null?u:[],l=a.ranges;n.length!==0&&(n.length!==l.length||n.some((d,c)=>!s.Rectangle.equals(d,l[c])))&&e.push({type:"update",ruleId:a.uid,oldRanges:l,newRanges:s.Rectangle.sort(n),rule:a}),n.length===0&&(e.push({type:"delete",rule:a,index:r-t}),t++)}),e}diffWithAddition(i,e){const t=[];let a=0;return i.forEach((r,n)=>{var d;const l=(d=this._map.get(r.uid))!=null?d:[],u=r.ranges;l.length!==0&&(l.length!==u.length||l.some((c,m)=>!s.Rectangle.equals(c,u[m])))&&t.push({type:"update",ruleId:r.uid,oldRanges:u,newRanges:s.Rectangle.sort(l),rule:r}),l.length===0&&(t.push({type:"delete",rule:r,index:n-a}),a++)}),Array.from(e).forEach(r=>{var l;const n=(l=this._map.get(r.uid))!=null?l:[];t.push({type:"add",rule:{...r,ranges:s.Rectangle.sort(n)}})}),t}clone(){return new ue(new Map(s.Tools.deepClone(Array.from(this._map.entries()))),this._unitId,this._subUnitId,this._univerInstanceService,!0)}getValue(i,e){this._dirty&&this._buildTree();const t=this._tree.get(e);if(!t)return;const a=t.search([i,i]);return a.length>0?a[0]:void 0}}var Ze=Object.defineProperty,Je=Object.getOwnPropertyDescriptor,et=(o,i,e,t)=>{for(var a=t>1?void 0:t?Je(i,e):i,r=o.length-1,n;r>=0;r--)(n=o[r])&&(a=(t?n(i,e,a):n(a))||a);return t&&a&&Ze(i,e,a),a},C=(o,i)=>(e,t)=>i(e,t,o);h.SheetDataValidationModel=class extends s.Disposable{constructor(e,t,a,r,n,l,u){super();_(this,"_ruleMatrixMap",new Map);_(this,"_validStatusChange$",new b.Subject);_(this,"_ruleChange$",new b.Subject);_(this,"ruleChange$",this._ruleChange$.asObservable());_(this,"validStatusChange$",this._validStatusChange$.asObservable());this._dataValidationModel=e,this._univerInstanceService=t,this._dataValidatorRegistryService=a,this._dataValidationCacheService=r,this._dataValidationFormulaService=n,this._dataValidationCustomFormulaService=l,this._commandService=u,this._initRuleUpdateListener(),this.disposeWithMe(()=>{this._ruleChange$.complete(),this._validStatusChange$.complete()}),this._initUniverInstanceListener()}_initUniverInstanceListener(){this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(e=>{this._ruleMatrixMap.delete(e.getUnitId())})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===D.RemoveSheetMutation.id){const{unitId:t,subUnitId:a}=e.params,r=this._ruleMatrixMap.get(t);r&&r.delete(a)}}))}_initRuleUpdateListener(){const e=this._dataValidationModel.getAll();for(const[t,a]of e)for(const[r,n]of a)for(const l of n)this._addRule(t,r,l),this._ruleChange$.next({type:"add",unitId:t,subUnitId:r,rule:l,source:"patched"});this.disposeWithMe(this._dataValidationModel.ruleChange$.subscribe(t=>{switch(t.type){case"add":this._addRule(t.unitId,t.subUnitId,t.rule);break;case"update":this._updateRule(t.unitId,t.subUnitId,t.rule.uid,t.oldRule,t.updatePayload);break;case"remove":this._removeRule(t.unitId,t.subUnitId,t.rule);break}this._ruleChange$.next(t)}))}_ensureRuleMatrix(e,t){let a=this._ruleMatrixMap.get(e);a||(a=new Map,this._ruleMatrixMap.set(e,a));let r=a.get(t);return r||(r=new ue(new Map,e,t,this._univerInstanceService),a.set(t,r)),r}_addRuleSideEffect(e,t,a){this._ensureRuleMatrix(e,t).addRule(a),this._dataValidationCacheService.addRule(e,t,a),this._dataValidationFormulaService.addRule(e,t,a),this._dataValidationCustomFormulaService.addRule(e,t,a)}_addRule(e,t,a){(Array.isArray(a)?a:[a]).forEach(n=>{this._addRuleSideEffect(e,t,n)})}_updateRule(e,t,a,r,n){const l=this._ensureRuleMatrix(e,t),u={...r,...n.payload};n.type===p.UpdateRuleType.RANGE?l.updateRange(a,n.payload):n.type===p.UpdateRuleType.ALL&&l.updateRange(a,n.payload.ranges),this._dataValidationCacheService.removeRule(e,t,r),this._dataValidationCacheService.addRule(e,t,u),this._dataValidationFormulaService.removeRule(e,t,r.uid),this._dataValidationFormulaService.addRule(e,t,u),this._dataValidationCustomFormulaService.deleteByRuleId(e,t,a),this._dataValidationCustomFormulaService.addRule(e,t,u)}_removeRule(e,t,a){this._ensureRuleMatrix(e,t).removeRule(a),this._dataValidationCacheService.removeRule(e,t,a),this._dataValidationCustomFormulaService.deleteByRuleId(e,t,a.uid)}getValidator(e){return this._dataValidatorRegistryService.getValidatorItem(e)}getRuleIdByLocation(e,t,a,r){return this._ensureRuleMatrix(e,t).getValue(a,r)}getRuleByLocation(e,t,a,r){const n=this.getRuleIdByLocation(e,t,a,r);if(n)return this._dataValidationModel.getRuleById(e,t,n)}validator(e,t,a){const{col:r,row:n,unitId:l,subUnitId:u,worksheet:d}=t,c=(R,g)=>{a&&a(R,g),g&&this._validStatusChange$.next({unitId:l,subUnitId:u,ruleId:e.uid,status:R,row:n,col:r})},m=d.getCellValueOnly(n,r),f=this.getValidator(e.type),v=d.getCellRaw(n,r),S=U(v);if(f){const R=this._dataValidationCacheService.ensureCache(l,u),g=R.getValue(n,r);return g==null?(R.setValue(n,r,s.DataValidationStatus.VALIDATING),f.validator({value:S,unitId:l,subUnitId:u,row:n,column:r,worksheet:t.worksheet,workbook:t.workbook,interceptValue:U(m),t:v==null?void 0:v.t},e).then(M=>{const N=M?s.DataValidationStatus.VALID:s.DataValidationStatus.INVALID;N===s.DataValidationStatus.VALID?R.realDeleteValue(n,r):R.setValue(n,r,N);const I=R.getValue(n,r);c(N,g!==I)}),s.DataValidationStatus.VALIDATING):(c(g!=null?g:s.DataValidationStatus.VALID,!1),g!=null?g:s.DataValidationStatus.VALID)}else return c(s.DataValidationStatus.VALID,!1),s.DataValidationStatus.VALID}getRuleObjectMatrix(e,t){return this._ensureRuleMatrix(e,t)}getRuleById(e,t,a){return this._dataValidationModel.getRuleById(e,t,a)}getRuleIndex(e,t,a){return this._dataValidationModel.getRuleIndex(e,t,a)}getRules(e,t){return[...this._dataValidationModel.getRules(e,t)]}getUnitRules(e){return this._dataValidationModel.getUnitRules(e)}deleteUnitRules(e){return this._dataValidationModel.deleteUnitRules(e)}getSubUnitIds(e){return this._dataValidationModel.getSubUnitIds(e)}getAll(){return this._dataValidationModel.getAll()}},h.SheetDataValidationModel=et([C(0,s.Inject(p.DataValidationModel)),C(1,s.IUniverInstanceService),C(2,s.Inject(p.DataValidatorRegistryService)),C(3,s.Inject(h.DataValidationCacheService)),C(4,s.Inject(h.DataValidationFormulaService)),C(5,s.Inject(h.DataValidationCustomFormulaService)),C(6,s.ICommandService)],h.SheetDataValidationModel);const $=1,W=0;function Ve(o,i){return s.Tools.isBlank(o)?i.t("dataValidation.validFail.value"):s.isFormulaString(o)?i.t("dataValidation.validFail.primitive"):""}const x=o=>s.Tools.isDefine(o)&&String(o).toLowerCase()==="true"?"1":String(o).toLowerCase()==="false"?"0":o;class De extends p.BaseDataValidator{constructor(){super(...arguments);_(this,"id",s.DataValidationType.CHECKBOX);_(this,"title","dataValidation.checkbox.title");_(this,"operators",[]);_(this,"scopes",["sheet"]);_(this,"_formulaService",this.injector.get(h.DataValidationFormulaService));_(this,"skipDefaultFontRender",(e,t,a)=>{const{unitId:r,subUnitId:n}=a,{formula1:l,formula2:u}=this.parseFormulaSync(e,r,n),d=`${t!=null?t:""}`;return!d||d===`${l}`||d===`${u}`})}validatorFormula(e,t,a){const{formula1:r,formula2:n}=e,l=r===n;if(s.Tools.isBlank(r)&&s.Tools.isBlank(n))return{success:!0};if(l)return{success:!1,formula1:this.localeService.t("dataValidation.validFail.checkboxEqual"),formula2:this.localeService.t("dataValidation.validFail.checkboxEqual")};const u=Ve(r,this.localeService),d=Ve(n,this.localeService);return{success:!u&&!d,formula1:u,formula2:d}}async parseFormula(e,t,a){var m,f,v,S;const{formula1:r=$,formula2:n=W}=e,l=await this._formulaService.getRuleFormulaResult(t,a,e.uid),u=s.isFormulaString(r)?A((f=(m=l==null?void 0:l[0])==null?void 0:m.result)==null?void 0:f[0][0]):r,d=s.isFormulaString(n)?A((S=(v=l==null?void 0:l[1])==null?void 0:v.result)==null?void 0:S[0][0]):n,c=y(String(u))&&y(String(d));return{formula1:x(u),formula2:x(d),originFormula1:u,originFormula2:d,isFormulaValid:c}}getExtraStyle(e,t){return{tb:s.WrapStrategy.CLIP}}parseFormulaSync(e,t,a){var m,f,v,S;const{formula1:r=$,formula2:n=W}=e,l=this._formulaService.getRuleFormulaResultSync(t,a,e.uid),u=s.isFormulaString(r)?A((f=(m=l==null?void 0:l[0])==null?void 0:m.result)==null?void 0:f[0][0]):r,d=s.isFormulaString(n)?A((S=(v=l==null?void 0:l[1])==null?void 0:v.result)==null?void 0:S[0][0]):n,c=y(String(u))&&y(String(d));return{formula1:x(u),formula2:x(d),originFormula1:u,originFormula2:d,isFormulaValid:c}}async isValidType(e,t,a){const{value:r,unitId:n,subUnitId:l}=e,{formula1:u,formula2:d,originFormula1:c,originFormula2:m}=await this.parseFormula(a,n,l);return!s.Tools.isDefine(u)||!s.Tools.isDefine(d)?!0:s.Tools.isDefine(r)&&(String(r)===String(u)||String(r)===String(d)||String(r)===String(c!=null?c:"")||String(r)===String(m!=null?m:""))}generateRuleErrorMessage(e){return this.localeService.t("dataValidation.checkbox.error")}}const tt={[s.DataValidationOperator.BETWEEN]:"dataValidation.date.operators.between",[s.DataValidationOperator.EQUAL]:"dataValidation.date.operators.equal",[s.DataValidationOperator.GREATER_THAN]:"dataValidation.date.operators.greaterThan",[s.DataValidationOperator.GREATER_THAN_OR_EQUAL]:"dataValidation.date.operators.greaterThanOrEqual",[s.DataValidationOperator.LESS_THAN]:"dataValidation.date.operators.lessThan",[s.DataValidationOperator.LESS_THAN_OR_EQUAL]:"dataValidation.date.operators.lessThanOrEqual",[s.DataValidationOperator.NOT_BETWEEN]:"dataValidation.date.operators.notBetween",[s.DataValidationOperator.NOT_EQUAL]:"dataValidation.date.operators.notEqual"};s.DataValidationOperator.BETWEEN+"",s.DataValidationOperator.EQUAL+"",s.DataValidationOperator.GREATER_THAN+"",s.DataValidationOperator.GREATER_THAN_OR_EQUAL+"",s.DataValidationOperator.LESS_THAN+"",s.DataValidationOperator.LESS_THAN_OR_EQUAL+"",s.DataValidationOperator.NOT_BETWEEN+"",s.DataValidationOperator.NOT_EQUAL+"";const at={[s.DataValidationOperator.BETWEEN]:"dataValidation.date.ruleName.between",[s.DataValidationOperator.EQUAL]:"dataValidation.date.ruleName.equal",[s.DataValidationOperator.GREATER_THAN]:"dataValidation.date.ruleName.greaterThan",[s.DataValidationOperator.GREATER_THAN_OR_EQUAL]:"dataValidation.date.ruleName.greaterThanOrEqual",[s.DataValidationOperator.LESS_THAN]:"dataValidation.date.ruleName.lessThan",[s.DataValidationOperator.LESS_THAN_OR_EQUAL]:"dataValidation.date.ruleName.lessThanOrEqual",[s.DataValidationOperator.NOT_BETWEEN]:"dataValidation.date.ruleName.notBetween",[s.DataValidationOperator.NOT_EQUAL]:"dataValidation.date.ruleName.notEqual"},it={[s.DataValidationOperator.BETWEEN]:"dataValidation.date.errorMsg.between",[s.DataValidationOperator.EQUAL]:"dataValidation.date.errorMsg.equal",[s.DataValidationOperator.GREATER_THAN]:"dataValidation.date.errorMsg.greaterThan",[s.DataValidationOperator.GREATER_THAN_OR_EQUAL]:"dataValidation.date.errorMsg.greaterThanOrEqual",[s.DataValidationOperator.LESS_THAN]:"dataValidation.date.errorMsg.lessThan",[s.DataValidationOperator.LESS_THAN_OR_EQUAL]:"dataValidation.date.errorMsg.lessThanOrEqual",[s.DataValidationOperator.NOT_BETWEEN]:"dataValidation.date.errorMsg.notBetween",[s.DataValidationOperator.NOT_EQUAL]:"dataValidation.date.errorMsg.notEqual"},z=[s.DataValidationOperator.BETWEEN,s.DataValidationOperator.NOT_BETWEEN],k="{FORMULA1}",q="{FORMULA2}";function rt(o){return o.filter(Boolean).join(",")}function G(o){return o.split(",").filter(Boolean)}function nt(o){const i=U(o);return i==null?"":i.toString()}function Z(o,i,e){const{formula1:t,formula2:a}=i,r=i.ranges[0].startRow,n=i.ranges[0].startColumn,l=e.row-r,u=e.col-n,d=s.isFormulaString(t)?o.moveFormulaRefOffset(t,u,l,!0):t,c=s.isFormulaString(a)?o.moveFormulaRefOffset(a,u,l,!0):a;return{transformedFormula1:d,transformedFormula2:c}}const de=o=>{var e,t;if(o==null||typeof o=="boolean")return;if(typeof o=="number"||!Number.isNaN(+o))return+o;const i=(e=s.numfmt.parseDate(o))==null?void 0:e.v;return s.Tools.isDefine(i)?i:(t=s.numfmt.parseDate(s.dayjs(o).format("YYYY-MM-DD HH:mm:ss")))==null?void 0:t.v};class Me extends p.BaseDataValidator{constructor(){super(...arguments);_(this,"id",s.DataValidationType.DATE);_(this,"title","dataValidation.date.title");_(this,"operators",[s.DataValidationOperator.BETWEEN,s.DataValidationOperator.EQUAL,s.DataValidationOperator.GREATER_THAN,s.DataValidationOperator.GREATER_THAN_OR_EQUAL,s.DataValidationOperator.LESS_THAN,s.DataValidationOperator.LESS_THAN_OR_EQUAL,s.DataValidationOperator.NOT_BETWEEN,s.DataValidationOperator.NOT_EQUAL]);_(this,"scopes",["sheet"]);_(this,"_customFormulaService",this.injector.get(h.DataValidationCustomFormulaService));_(this,"_lexerTreeBuilder",this.injector.get(O.LexerTreeBuilder))}async parseFormula(e,t,a,r,n){const l=await this._customFormulaService.getCellFormulaValue(t,a,e.uid,r,n),u=await this._customFormulaService.getCellFormula2Value(t,a,e.uid,r,n),{formula1:d,formula2:c}=e,m=y(String(l==null?void 0:l.v))&&y(String(u==null?void 0:u.v));return{formula1:de(s.isFormulaString(d)?l==null?void 0:l.v:d),formula2:de(s.isFormulaString(c)?u==null?void 0:u.v:c),isFormulaValid:m}}async isValidType(e){const{interceptValue:t,value:a}=e;return typeof a=="number"&&typeof t=="string"?!0:typeof t=="string"?!!s.numfmt.parseDate(t):!1}_validatorSingleFormula(e){return!s.Tools.isBlank(e)&&(s.isFormulaString(e)||!Number.isNaN(+e)||!!(e&&s.numfmt.parseDate(e)))}validatorFormula(e,t,a){const r=e.operator;if(!r)return{success:!1};const n=this._validatorSingleFormula(e.formula1),l=this.localeService.t("dataValidation.validFail.date");if(z.includes(r)){const d=this._validatorSingleFormula(e.formula2);return{success:n&&d,formula1:n?void 0:l,formula2:d?void 0:l}}return{success:n,formula1:n?void 0:l}}normalizeFormula(e,t,a){const{formula1:r,formula2:n,bizInfo:l}=e,u=d=>{var m;if(!d)return d;let c;if(!Number.isNaN(+d))c=s.numfmt.dateFromSerial(+d);else{const f=(m=s.numfmt.parseDate(d))==null?void 0:m.v;if(f==null)return"";c=s.numfmt.dateFromSerial(f)}return s.dayjs(`${c[0]}/${c[1]}/${c[2]} ${c[3]}:${c[4]}:${c[5]}`).format(l!=null&&l.showTime?"YYYY-MM-DD HH:mm:ss":"YYYY-MM-DD")};return{formula1:s.isFormulaString(r)?r:u(`${r}`),formula2:s.isFormulaString(n)?n:u(`${n}`)}}transform(e,t,a){const{value:r}=e;return{...e,value:de(r)}}async validatorIsEqual(e,t,a){const{formula1:r}=t,{value:n}=e;return Number.isNaN(r)?!0:n===r}async validatorIsNotEqual(e,t,a){const{formula1:r}=t;return Number.isNaN(r)?!0:e.value!==r}async validatorIsBetween(e,t,a){const{formula1:r,formula2:n}=t;if(Number.isNaN(r)||Number.isNaN(n))return!0;const l=Math.min(r,n),u=Math.max(r,n);return e.value>=l&&e.value<=u}async validatorIsNotBetween(e,t,a){const{formula1:r,formula2:n}=t;if(Number.isNaN(r)||Number.isNaN(n))return!0;const l=Math.min(r,n),u=Math.max(r,n);return e.value<l||e.value>u}async validatorIsGreaterThan(e,t,a){const{formula1:r}=t;return Number.isNaN(r)?!0:e.value>r}async validatorIsGreaterThanOrEqual(e,t,a){const{formula1:r}=t;return Number.isNaN(r)?!0:e.value>=r}async validatorIsLessThan(e,t,a){const{formula1:r}=t;return Number.isNaN(r)?!0:e.value<r}async validatorIsLessThanOrEqual(e,t,a){const{formula1:r}=t;return Number.isNaN(r)?!0:e.value<=r}get operatorNames(){return this.operators.map(e=>this.localeService.t(tt[e]))}generateRuleName(e){var a,r;if(!e.operator)return this.titleStr;const t=this.localeService.t(at[e.operator]).replace(k,(a=e.formula1)!=null?a:"").replace(q,(r=e.formula2)!=null?r:"");return`${this.titleStr} ${t}`}generateRuleErrorMessage(e,t){if(!e.operator)return this.titleStr;const{transformedFormula1:a,transformedFormula2:r}=Z(this._lexerTreeBuilder,e,t);return`${this.localeService.t(it[e.operator]).replace(k,a!=null?a:"").replace(q,r!=null?r:"")}`}}s.DataValidationOperator.BETWEEN+"",s.DataValidationOperator.EQUAL+"",s.DataValidationOperator.GREATER_THAN+"",s.DataValidationOperator.GREATER_THAN_OR_EQUAL+"",s.DataValidationOperator.LESS_THAN+"",s.DataValidationOperator.LESS_THAN_OR_EQUAL+"",s.DataValidationOperator.NOT_BETWEEN+"",s.DataValidationOperator.NOT_EQUAL+"",s.DataValidationOperator.BETWEEN+"",s.DataValidationOperator.EQUAL+"",s.DataValidationOperator.GREATER_THAN+"",s.DataValidationOperator.GREATER_THAN_OR_EQUAL+"",s.DataValidationOperator.LESS_THAN+"",s.DataValidationOperator.LESS_THAN_OR_EQUAL+"",s.DataValidationOperator.NOT_BETWEEN+"",s.DataValidationOperator.NOT_EQUAL+"";const ye={[s.DataValidationOperator.BETWEEN]:"dataValidation.errorMsg.between",[s.DataValidationOperator.EQUAL]:"dataValidation.errorMsg.equal",[s.DataValidationOperator.GREATER_THAN]:"dataValidation.errorMsg.greaterThan",[s.DataValidationOperator.GREATER_THAN_OR_EQUAL]:"dataValidation.errorMsg.greaterThanOrEqual",[s.DataValidationOperator.LESS_THAN]:"dataValidation.errorMsg.lessThan",[s.DataValidationOperator.LESS_THAN_OR_EQUAL]:"dataValidation.errorMsg.lessThanOrEqual",[s.DataValidationOperator.NOT_BETWEEN]:"dataValidation.errorMsg.notBetween",[s.DataValidationOperator.NOT_EQUAL]:"dataValidation.errorMsg.notEqual"};function J(o){let i=o;return typeof o=="string"?((o.startsWith("¥")||o.startsWith("$"))&&(i=o.slice(1)),+i):+o}class st extends p.BaseDataValidator{constructor(){super(...arguments);_(this,"_customFormulaService",this.injector.get(h.DataValidationCustomFormulaService));_(this,"id",s.DataValidationType.DECIMAL);_(this,"_lexerTreeBuilder",this.injector.get(O.LexerTreeBuilder));_(this,"title","dataValidation.decimal.title");_(this,"operators",[s.DataValidationOperator.BETWEEN,s.DataValidationOperator.EQUAL,s.DataValidationOperator.GREATER_THAN,s.DataValidationOperator.GREATER_THAN_OR_EQUAL,s.DataValidationOperator.LESS_THAN,s.DataValidationOperator.LESS_THAN_OR_EQUAL,s.DataValidationOperator.NOT_BETWEEN,s.DataValidationOperator.NOT_EQUAL]);_(this,"scopes",["sheet"])}_isFormulaOrNumber(e){return!s.Tools.isBlank(e)&&(s.isFormulaString(e)||!Number.isNaN(+e))}async isValidType(e,t,a){const{value:r}=e;return!Number.isNaN(J(r))}transform(e,t,a){const{value:r}=e;return{...e,value:J(r)}}_parseNumber(e){return e==null?Number.NaN:+e}async parseFormula(e,t,a,r,n){const l=await this._customFormulaService.getCellFormulaValue(t,a,e.uid,r,n),u=await this._customFormulaService.getCellFormula2Value(t,a,e.uid,r,n),{formula1:d,formula2:c}=e,m=y(String(l==null?void 0:l.v))&&y(String(u==null?void 0:u.v));return{formula1:this._parseNumber(s.isFormulaString(d)?l==null?void 0:l.v:d),formula2:this._parseNumber(s.isFormulaString(c)?u==null?void 0:u.v:c),isFormulaValid:m}}validatorFormula(e,t,a){const r=e.operator;if(!r)return{success:!1};const n=s.Tools.isDefine(e.formula1)&&this._isFormulaOrNumber(e.formula1),l=s.Tools.isDefine(e.formula2)&&this._isFormulaOrNumber(e.formula2),u=z.includes(r),d=this.localeService.t("dataValidation.validFail.number");return u?{success:n&&l,formula1:n?void 0:d,formula2:l?void 0:d}:{success:n,formula1:n?"":d}}async validatorIsEqual(e,t,a){const{formula1:r}=t,{value:n}=e;return Number.isNaN(r)?!0:n===r}async validatorIsNotEqual(e,t,a){const{formula1:r}=t;return Number.isNaN(r)?!0:e.value!==r}async validatorIsBetween(e,t,a){const{formula1:r,formula2:n}=t;if(Number.isNaN(r)||Number.isNaN(n))return!0;const l=Math.min(r,n),u=Math.max(r,n);return e.value>=l&&e.value<=u}async validatorIsNotBetween(e,t,a){const{formula1:r,formula2:n}=t;if(Number.isNaN(r)||Number.isNaN(n))return!0;const l=Math.min(r,n),u=Math.max(r,n);return e.value<l||e.value>u}async validatorIsGreaterThan(e,t,a){const{formula1:r}=t;return Number.isNaN(r)?!0:e.value>r}async validatorIsGreaterThanOrEqual(e,t,a){const{formula1:r}=t;return Number.isNaN(r)?!0:e.value>=r}async validatorIsLessThan(e,t,a){const{formula1:r}=t;return Number.isNaN(r)?!0:e.value<r}async validatorIsLessThanOrEqual(e,t,a){const{formula1:r}=t;return Number.isNaN(r)?!0:e.value<=r}generateRuleErrorMessage(e,t){if(!e.operator)return this.titleStr;const{transformedFormula1:a,transformedFormula2:r}=Z(this._lexerTreeBuilder,e,t);return`${this.localeService.t(ye[e.operator]).replace(k,a!=null?a:"").replace(q,r!=null?r:"")}`}}function ce(o){if(!o)return[];const i=new Set;return o.forEach(e=>{e.forEach(t=>{var r,n;const a=U(t);if(a!=null){if(typeof a!="string"&&typeof(t==null?void 0:t.s)=="object"&&((n=(r=t.s)==null?void 0:r.n)!=null&&n.pattern)){i.add(s.numfmt.format(t.s.n.pattern,a,{throws:!1}));return}y(a.toString())&&i.add(a.toString())}})}),[...i]}const ot=["if","indirect","choose","offset"];function lt(o,i){if(!s.isFormulaString(o)||O.isReferenceString(o.slice(1)))return!0;const t=i.sequenceNodesBuilder(o);return t&&t.some(a=>typeof a=="object"&&a.nodeType===O.sequenceNodeType.FUNCTION&&ot.indexOf(a.token.toLowerCase())>-1)}function ut(o,i){const{formula1:e="",ranges:t}=o;if(O.isReferenceString(e.slice(1))){const r=O.deserializeRangeWithSheet(e.slice(1));if((!r.sheetName||r.sheetName===i)&&t.some(n=>s.Rectangle.intersects(n,r.range)))return!0}return!1}class he extends p.BaseDataValidator{constructor(){super(...arguments);_(this,"formulaService",this.injector.get(h.DataValidationFormulaService));_(this,"_lexer",this.injector.get(O.LexerTreeBuilder));_(this,"_univerInstanceService",this.injector.get(s.IUniverInstanceService));_(this,"id",s.DataValidationType.LIST);_(this,"title","dataValidation.list.title");_(this,"operators",[]);_(this,"scopes",["sheet"]);_(this,"skipDefaultFontRender",e=>e.renderMode!==s.DataValidationRenderMode.TEXT)}validatorFormula(e,t,a){var d,c,m;const r=!s.Tools.isBlank(e.formula1),n=lt((d=e.formula1)!=null?d:"",this._lexer),l=(m=(c=this._univerInstanceService.getUnit(t,s.UniverInstanceType.UNIVER_SHEET))==null?void 0:c.getSheetBySheetId(a))==null?void 0:m.getName(),u=ut(e,l!=null?l:"");return{success:!!(r&&n&&!u),formula1:r?n?u?this.localeService.t("dataValidation.validFail.listIntersects"):void 0:this.localeService.t("dataValidation.validFail.listInvalid"):this.localeService.t("dataValidation.validFail.list")}}getExtraStyle(e,t,{style:a}){var n;const r=(n=a.tb!==s.WrapStrategy.OVERFLOW?a.tb:s.WrapStrategy.CLIP)!=null?n:s.WrapStrategy.WRAP;if(e.type===s.DataValidationType.LIST&&(e.renderMode===s.DataValidationRenderMode.ARROW||e.renderMode===s.DataValidationRenderMode.TEXT)){const l=this.getListWithColorMap(e),u=`${t!=null?t:""}`,d=l[u];if(d)return{bg:{rgb:d},tb:r}}return{tb:r}}parseCellValue(e){const t=e.toString();return G(t)}async parseFormula(e,t,a){var d,c,m,f;const{formula1:r=""}=e,n=await this.formulaService.getRuleFormulaResult(t,a,e.uid),l=A((c=(d=n==null?void 0:n[0])==null?void 0:d.result)==null?void 0:c[0][0]),u=y(String(l));return{formula1:s.isFormulaString(r)?ce((f=(m=n==null?void 0:n[0])==null?void 0:m.result)==null?void 0:f[0][0]):G(r),formula2:void 0,isFormulaValid:u}}async isValidType(e,t,a){const{value:r}=e,{formula1:n=[]}=t;return this.parseCellValue(r).every(u=>n.includes(u))}generateRuleName(){return this.localeService.t("dataValidation.list.name")}generateRuleErrorMessage(){return this.localeService.t("dataValidation.list.error")}getList(e,t,a){var f,v,S,R;const{formula1:r=""}=e,n=this.injector.get(s.IUniverInstanceService),l=(f=t?n.getUniverSheetInstance(t):void 0)!=null?f:n.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET);if(!l)return[];const u=(v=a?l.getSheetBySheetId(a):void 0)!=null?v:l.getActiveSheet();if(!u)return[];const d=l.getUnitId(),c=u.getSheetId(),m=this.formulaService.getRuleFormulaResultSync(d,c,e.uid);return s.isFormulaString(r)?ce((R=(S=m==null?void 0:m[0])==null?void 0:S.result)==null?void 0:R[0][0]):G(r)}async getListAsync(e,t,a){var f,v,S,R;const{formula1:r=""}=e,n=this.injector.get(s.IUniverInstanceService),l=(f=t?n.getUniverSheetInstance(t):void 0)!=null?f:n.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET);if(!l)return[];const u=(v=a?l.getSheetBySheetId(a):void 0)!=null?v:l.getActiveSheet();if(!u)return[];const d=l.getUnitId(),c=u.getSheetId(),m=await this.formulaService.getRuleFormulaResult(d,c,e.uid);return s.isFormulaString(r)?ce((R=(S=m==null?void 0:m[0])==null?void 0:S.result)==null?void 0:R[0][0]):G(r)}getListWithColor(e,t,a){const r=this.getList(e,t,a),n=(e.formula2||"").split(",");return r.map((l,u)=>({label:l,color:n[u]}))}getListWithColorMap(e,t,a){const r=this.getListWithColor(e,t,a),n={};return r.forEach(l=>{l.color&&(n[l.label]=l.color)}),n}}class dt extends p.BaseDataValidator{constructor(){super(...arguments);_(this,"id",s.DataValidationType.TEXT_LENGTH);_(this,"title","dataValidation.textLength.title");_(this,"_lexerTreeBuilder",this.injector.get(O.LexerTreeBuilder));_(this,"operators",[s.DataValidationOperator.BETWEEN,s.DataValidationOperator.EQUAL,s.DataValidationOperator.GREATER_THAN,s.DataValidationOperator.GREATER_THAN_OR_EQUAL,s.DataValidationOperator.LESS_THAN,s.DataValidationOperator.LESS_THAN_OR_EQUAL,s.DataValidationOperator.NOT_BETWEEN,s.DataValidationOperator.NOT_EQUAL]);_(this,"scopes",["sheet"]);_(this,"_customFormulaService",this.injector.get(h.DataValidationCustomFormulaService))}_isFormulaOrInt(e){return!s.Tools.isBlank(e)&&(s.isFormulaString(e)||!Number.isNaN(+e)&&Number.isInteger(+e))}validatorFormula(e,t,a){const r=e.operator;if(!r)return{success:!1};const n=s.Tools.isDefine(e.formula1)&&this._isFormulaOrInt(e.formula1),l=s.Tools.isDefine(e.formula2)&&this._isFormulaOrInt(e.formula2),u=z.includes(r),d=this.localeService.t("dataValidation.validFail.number");return u?{success:n&&l,formula1:n?void 0:d,formula2:l?void 0:d}:{success:n,formula1:d}}_parseNumber(e){return e==null?Number.NaN:+e}_isValidFormula(e){return!Number.isNaN(e)}async parseFormula(e,t,a,r,n){const l=await this._customFormulaService.getCellFormulaValue(t,a,e.uid,r,n),u=await this._customFormulaService.getCellFormula2Value(t,a,e.uid,r,n),{formula1:d,formula2:c}=e,m=y(String(l==null?void 0:l.v))&&y(String(u==null?void 0:u.v));return{formula1:this._parseNumber(s.isFormulaString(d)?l==null?void 0:l.v:d),formula2:this._parseNumber(s.isFormulaString(c)?u==null?void 0:u.v:c),isFormulaValid:m}}transform(e,t,a){return{...e,value:e.value.toString().length}}async isValidType(e,t,a){const{value:r}=e;return typeof r=="string"||typeof r=="number"}async validatorIsEqual(e,t,a){const{formula1:r}=t;return s.Tools.isDefine(r)?e.value===r:!1}async validatorIsNotEqual(e,t,a){const{formula1:r}=t;return s.Tools.isDefine(r)?e.value!==r:!1}async validatorIsBetween(e,t,a){const{formula1:r,formula2:n}=t,{value:l}=e;if(!this._isValidFormula(r)||!this._isValidFormula(n))return!1;const u=Math.max(r,n),d=Math.min(r,n);return l>=d&&l<=u}async validatorIsNotBetween(e,t,a){const{formula1:r,formula2:n}=t,{value:l}=e;if(!this._isValidFormula(r)||!this._isValidFormula(n))return!1;const u=Math.max(r,n),d=Math.min(r,n);return l<d||l>u}async validatorIsGreaterThan(e,t,a){const{formula1:r}=t,{value:n}=e;return this._isValidFormula(r)?n>r:!1}async validatorIsGreaterThanOrEqual(e,t,a){const{formula1:r}=t,{value:n}=e;return this._isValidFormula(r)?n>=r:!1}async validatorIsLessThan(e,t,a){const{formula1:r}=t,{value:n}=e;return this._isValidFormula(r)?n<r:!1}async validatorIsLessThanOrEqual(e,t,a){const{formula1:r}=t,{value:n}=e;return this._isValidFormula(r)?n<=r:!1}generateRuleErrorMessage(e,t){if(!e.operator)return this.titleStr;const{transformedFormula1:a,transformedFormula2:r}=Z(this._lexerTreeBuilder,e,t);return`${this.localeService.t(p.TextLengthErrorTitleMap[e.operator]).replace(k,a!=null?a:"").replace(q,r!=null?r:"")}`}}function Te(o){var e,t;return o?o.p?!((t=(e=o.p.body)==null?void 0:e.dataStream)!=null?t:"").slice(0,-2).trim():s.Tools.isBlank(o.v):!0}function Q(o,i,e,t,a="command",r=!0){const n=t.get(O.LexerTreeBuilder),l=[],u=[],d=t.get(h.SheetDataValidationModel),c=t.get(s.IUniverInstanceService),m=D.getSheetCommandTarget(c,{unitId:o,subUnitId:i});if(!m)return{redoMutations:l,undoMutations:u};const{worksheet:f}=m,v=new s.ObjectMatrix;let S=!1;function R(g,M){r&&g.forEach(N=>{s.Range.foreach(N,(I,w)=>{const E=f.getCellRaw(I,w),P=Re(E);(Te(E)||P===M)&&(S=!0,v.setValue(I,w,{v:M,p:null}))})})}if(e.forEach(g=>{switch(g.type){case"delete":l.push({id:p.RemoveDataValidationMutation.id,params:{unitId:o,subUnitId:i,ruleId:g.rule.uid,source:a}}),u.unshift({id:p.AddDataValidationMutation.id,params:{unitId:o,subUnitId:i,rule:g.rule,index:g.index,source:a}});break;case"update":{if(H(g.rule.type)){const N=g.oldRanges[0].startRow,I=g.oldRanges[0].startColumn,w=g.newRanges[0].startRow,E=g.newRanges[0].startColumn,P=w-N,ne=E-I,se=s.isFormulaString(g.rule.formula1)?n.moveFormulaRefOffset(g.rule.formula1,ne,P):g.rule.formula1,oe=s.isFormulaString(g.rule.formula2)?n.moveFormulaRefOffset(g.rule.formula2,ne,P):g.rule.formula2;(se!==g.rule.formula1||oe!==g.rule.formula2||!s.isRangesEqual(g.newRanges,g.oldRanges))&&(l.push({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:i,ruleId:g.ruleId,payload:{type:p.UpdateRuleType.ALL,payload:{formula1:se,formula2:oe,ranges:g.newRanges}}}}),u.unshift({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:i,ruleId:g.ruleId,payload:{type:p.UpdateRuleType.ALL,payload:{formula1:g.rule.formula1,formula2:g.rule.formula2,ranges:g.oldRanges}}}}))}else l.push({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:i,ruleId:g.ruleId,payload:{type:p.UpdateRuleType.RANGE,payload:g.newRanges},source:a}}),u.unshift({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:i,ruleId:g.ruleId,payload:{type:p.UpdateRuleType.RANGE,payload:g.oldRanges},source:a}});const M=d.getRuleById(o,i,g.ruleId);if(M&&M.type===s.DataValidationType.CHECKBOX){const I=d.getValidator(s.DataValidationType.CHECKBOX).parseFormulaSync(M,o,i);R(g.newRanges,I.formula2)}break}case"add":{if(l.push({id:p.AddDataValidationMutation.id,params:{unitId:o,subUnitId:i,rule:g.rule,source:a}}),u.unshift({id:p.RemoveDataValidationMutation.id,params:{unitId:o,subUnitId:i,ruleId:g.rule.uid,source:a}}),g.rule.type===s.DataValidationType.CHECKBOX){const N=d.getValidator(s.DataValidationType.CHECKBOX).parseFormulaSync(g.rule,o,i);R(g.rule.ranges,N.originFormula2)}break}}}),S){const g={id:D.SetRangeValuesMutation.id,params:{unitId:o,subUnitId:i,cellValue:v.getData()}},M={id:D.SetRangeValuesMutation.id,params:D.SetRangeValuesUndoMutationFactory(t,g.params)};l.push(g),u.push(M)}return{redoMutations:l,undoMutations:u}}const Ne={type:s.CommandType.COMMAND,id:"sheet.command.updateDataValidationRuleRange",handler(o,i){if(!i)return!1;const{unitId:e,subUnitId:t,ranges:a,ruleId:r}=i,n=o.get(h.SheetDataValidationModel),l=o.get(s.ICommandService),u=o.get(s.IUndoRedoService);if(!n.getRuleById(e,t,r))return!1;const c=n.getRuleObjectMatrix(e,t).clone();c.updateRange(r,a);const m=c.diff(n.getRules(e,t)),{redoMutations:f,undoMutations:v}=Q(e,t,m,o);return u.pushUndoRedo({undoMutations:v,redoMutations:f,unitID:e}),s.sequenceExecute(f,l),!0}},Oe={type:s.CommandType.COMMAND,id:"sheet.command.addDataValidation",handler(o,i){if(!i)return!1;const{unitId:e,subUnitId:t,rule:a}=i,r=o.get(h.SheetDataValidationModel),n=o.get(s.ICommandService),l=o.get(s.IUndoRedoService),u=r.getRuleObjectMatrix(e,t).clone();u.addRule(a);const d=u.diff(r.getRules(e,t)),c=r.getValidator(a.type),m={unitId:e,subUnitId:t,rule:{...a,...c==null?void 0:c.normalizeFormula(a,e,t)}},{redoMutations:f,undoMutations:v}=Q(e,t,d,o);return f.push({id:p.AddDataValidationMutation.id,params:m}),v.unshift({id:p.RemoveDataValidationMutation.id,params:{unitId:e,subUnitId:t,ruleId:a.uid}}),l.pushUndoRedo({unitID:e,redoMutations:f,undoMutations:v}),s.sequenceExecute(f,n),!0}},Ie={type:s.CommandType.COMMAND,id:"sheets.command.update-data-validation-setting",handler(o,i){if(!i)return!1;const e=o.get(s.ICommandService),t=o.get(s.IUndoRedoService),a=o.get(h.SheetDataValidationModel),r=o.get(p.DataValidatorRegistryService),{unitId:n,subUnitId:l,ruleId:u,setting:d}=i,c=r.getValidatorItem(d.type);if(!c)return!1;const m=a.getRuleById(n,l,u);if(!m)return!1;const f={...m,...d};if(!c.validatorFormula(f,n,l).success)return!1;const v={unitId:n,subUnitId:l,ruleId:u,payload:{type:p.UpdateRuleType.SETTING,payload:{...d,...c.normalizeFormula(f,n,l)}}},S=[{id:p.UpdateDataValidationMutation.id,params:v}],R={unitId:n,subUnitId:l,ruleId:u,payload:{type:p.UpdateRuleType.SETTING,payload:p.getRuleSetting(m)}},g=[{id:p.UpdateDataValidationMutation.id,params:R}];if(d.type===s.DataValidationType.CHECKBOX){const N=m.ranges,I=o.get(s.IUniverInstanceService),w=D.getSheetCommandTarget(I,{unitId:n,subUnitId:l});if(w){const E=new s.ObjectMatrix,{worksheet:P}=w,{formula2:ne=W,formula1:se=$}=m,{formula2:oe=W,formula1:jt=$}=d;N.forEach($t=>{s.Range.foreach($t,(_e,ge)=>{const je=P.getCellRaw(_e,ge),He=Re(je);Te(je)||He===String(ne)?E.setValue(_e,ge,{v:oe,p:null}):He===String(se)&&E.setValue(_e,ge,{v:jt,p:null})})});const Pe={id:D.SetRangeValuesMutation.id,params:{unitId:n,subUnitId:l,cellValue:E.getData()}},Ht={id:D.SetRangeValuesMutation.id,params:D.SetRangeValuesUndoMutationFactory(o,Pe.params)};S.push(Pe),g.push(Ht)}}return s.sequenceExecute(S,e).result?(t.pushUndoRedo({unitID:n,redoMutations:S,undoMutations:g}),!0):!1}},Ee={type:s.CommandType.COMMAND,id:"sheets.command.update-data-validation-options",handler(o,i){if(!i)return!1;const e=o.get(s.ICommandService),t=o.get(s.IUndoRedoService),a=o.get(h.SheetDataValidationModel),{unitId:r,subUnitId:n,ruleId:l,options:u}=i,d=a.getRuleById(r,n,l);if(!d)return!1;const c={unitId:r,subUnitId:n,ruleId:l,payload:{type:p.UpdateRuleType.OPTIONS,payload:u}},m=[{id:p.UpdateDataValidationMutation.id,params:c}],f={unitId:r,subUnitId:n,ruleId:l,payload:{type:p.UpdateRuleType.OPTIONS,payload:p.getRuleOptions(d)}},v=[{id:p.UpdateDataValidationMutation.id,params:f}];return t.pushUndoRedo({unitID:r,redoMutations:m,undoMutations:v}),e.executeCommand(p.UpdateDataValidationMutation.id,c),!0}},Fe={type:s.CommandType.COMMAND,id:"sheets.command.clear-range-data-validation",handler(o,i){if(!i)return!1;const{unitId:e,subUnitId:t,ranges:a}=i,r=o.get(s.ICommandService),n=o.get(s.IUniverInstanceService),l=D.getSheetCommandTarget(n,{unitId:e,subUnitId:t}),u=o.get(h.SheetDataValidationModel);if(!l)return!1;const d=o.get(s.IUndoRedoService),c=u.getRuleObjectMatrix(e,t).clone();c.removeRange(a);const m=c.diff(u.getRules(e,t)),{redoMutations:f,undoMutations:v}=Q(e,t,m,o);return d.pushUndoRedo({unitID:e,redoMutations:f,undoMutations:v}),s.sequenceExecute(f,r).result}},Ce={type:s.CommandType.COMMAND,id:"sheet.command.remove-all-data-validation",handler(o,i){if(!i)return!1;const{unitId:e,subUnitId:t}=i,a=o.get(s.ICommandService),r=o.get(h.SheetDataValidationModel),n=o.get(s.IUndoRedoService),l=[...r.getRules(e,t)],u={unitId:e,subUnitId:t,ruleId:l.map(m=>m.uid)},d=[{id:p.RemoveDataValidationMutation.id,params:u}],c=[{id:p.AddDataValidationMutation.id,params:{unitId:e,subUnitId:t,rule:l}}];return n.pushUndoRedo({redoMutations:d,undoMutations:c,unitID:e}),a.executeCommand(p.RemoveDataValidationMutation.id,u),!0}},ct=(o,i)=>{const e=o.get(h.SheetDataValidationModel),{unitId:t,subUnitId:a,ruleId:r,source:n}=i;if(Array.isArray(r)){const u=r.map(d=>e.getRuleById(t,a,d)).filter(Boolean);return[{id:p.AddDataValidationMutation.id,params:{unitId:t,subUnitId:a,rule:u,source:n}}]}return[{id:p.AddDataValidationMutation.id,params:{unitId:t,subUnitId:a,rule:{...e.getRuleById(t,a,r)},index:e.getRuleIndex(t,a,r)}}]},we={type:s.CommandType.COMMAND,id:"sheet.command.remove-data-validation-rule",handler(o,i){if(!i)return!1;const{unitId:e,subUnitId:t,ruleId:a}=i,r=o.get(s.ICommandService),n=o.get(s.IUndoRedoService),l=o.get(h.SheetDataValidationModel),u=[{id:p.RemoveDataValidationMutation.id,params:i}],d=[{id:p.AddDataValidationMutation.id,params:{unitId:e,subUnitId:t,rule:{...l.getRuleById(e,t,a)},index:l.getRuleIndex(e,t,a)}}];return n.pushUndoRedo({undoMutations:d,redoMutations:u,unitID:i.unitId}),r.executeCommand(p.RemoveDataValidationMutation.id,i),!0}},ht="sheets-data-validation.config",mt={};class ft extends p.BaseDataValidator{constructor(){super(...arguments);_(this,"id",s.DataValidationType.ANY);_(this,"title","dataValidation.any.title");_(this,"operators",[]);_(this,"scopes",["sheet"])}async parseFormula(e,t,a){return{formula1:e.formula1,formula2:e.formula2,isFormulaValid:!0}}validatorFormula(e,t,a){return{success:!0}}async isValidType(e,t,a){return!0}generateRuleErrorMessage(e){return this.localeService.t("dataValidation.any.error")}}class pt extends p.BaseDataValidator{constructor(){super(...arguments);_(this,"id",s.DataValidationType.CUSTOM);_(this,"title","dataValidation.custom.title");_(this,"operators",[]);_(this,"scopes",["sheet"]);_(this,"_customFormulaService",this.injector.get(h.DataValidationCustomFormulaService))}validatorFormula(e,t,a){const r=s.isFormulaString(e.formula1);return{success:r,formula1:r?"":this.localeService.t("dataValidation.validFail.formula")}}async parseFormula(e,t,a){return{formula1:void 0,formula2:void 0,isFormulaValid:!0}}async isValidType(e,t,a){const{column:r,row:n,unitId:l,subUnitId:u}=e,d=await this._customFormulaService.getCellFormulaValue(l,u,a.uid,n,r),c=d==null?void 0:d.v;return y(String(c))&&s.Tools.isDefine(c)&&c!==""?d.t===s.CellValueType.BOOLEAN?!!c:typeof c=="boolean"?c:typeof c=="number"?!!c:typeof c=="string"?y(c):!!c:!1}generateRuleErrorMessage(e){return this.localeService.t("dataValidation.custom.error")}generateRuleName(e){var t;return this.localeService.t("dataValidation.custom.ruleName").replace("{FORMULA1}",(t=e.formula1)!=null?t:"")}}class be extends he{constructor(){super(...arguments);_(this,"id",s.DataValidationType.LIST_MULTIPLE);_(this,"title","dataValidation.listMultiple.title");_(this,"skipDefaultFontRender",()=>!0)}}class _t extends p.BaseDataValidator{constructor(){super(...arguments);_(this,"_customFormulaService",this.injector.get(h.DataValidationCustomFormulaService));_(this,"_lexerTreeBuilder",this.injector.get(O.LexerTreeBuilder));_(this,"id",s.DataValidationType.WHOLE);_(this,"title","dataValidation.whole.title");_(this,"operators",[s.DataValidationOperator.BETWEEN,s.DataValidationOperator.EQUAL,s.DataValidationOperator.GREATER_THAN,s.DataValidationOperator.GREATER_THAN_OR_EQUAL,s.DataValidationOperator.LESS_THAN,s.DataValidationOperator.LESS_THAN_OR_EQUAL,s.DataValidationOperator.NOT_BETWEEN,s.DataValidationOperator.NOT_EQUAL]);_(this,"scopes",["sheet"])}_isFormulaOrInt(e){return!s.Tools.isBlank(e)&&(s.isFormulaString(e)||!Number.isNaN(+e)&&Number.isInteger(+e))}async isValidType(e,t,a){const{value:r}=e,n=J(r);return!Number.isNaN(n)&&Number.isInteger(n)}transform(e,t,a){const{value:r}=e;return{...e,value:J(r)}}_parseNumber(e){return e==null?Number.NaN:+e}async parseFormula(e,t,a,r,n){const l=await this._customFormulaService.getCellFormulaValue(t,a,e.uid,r,n),u=await this._customFormulaService.getCellFormula2Value(t,a,e.uid,r,n),{formula1:d,formula2:c}=e,m=s.isFormulaString(d)?l==null?void 0:l.v:d,f=s.isFormulaString(c)?u==null?void 0:u.v:c,v=y(`${m}`)&&y(`${f}`);return{formula1:this._parseNumber(m),formula2:this._parseNumber(f),isFormulaValid:v}}validatorFormula(e,t,a){const r=e.operator;if(!r)return{success:!1};const n=s.Tools.isDefine(e.formula1)&&this._isFormulaOrInt(e.formula1),l=s.Tools.isDefine(e.formula2)&&this._isFormulaOrInt(e.formula2),u=z.includes(r),d=this.localeService.t("dataValidation.validFail.number");return u?{success:n&&l,formula1:n?void 0:d,formula2:l?void 0:d}:{success:n,formula1:d}}async validatorIsEqual(e,t,a){const{formula1:r}=t,{value:n}=e;return Number.isNaN(r)?!0:n===r}async validatorIsNotEqual(e,t,a){const{formula1:r}=t;return Number.isNaN(r)?!0:e.value!==r}async validatorIsBetween(e,t,a){const{formula1:r,formula2:n}=t;if(Number.isNaN(r)||Number.isNaN(n))return!0;const l=Math.min(r,n),u=Math.max(r,n);return e.value>=l&&e.value<=u}async validatorIsNotBetween(e,t,a){const{formula1:r,formula2:n}=t;if(Number.isNaN(r)||Number.isNaN(n))return!0;const l=Math.min(r,n),u=Math.max(r,n);return e.value<l||e.value>u}async validatorIsGreaterThan(e,t,a){const{formula1:r}=t;return Number.isNaN(r)?!0:e.value>r}async validatorIsGreaterThanOrEqual(e,t,a){const{formula1:r}=t;return Number.isNaN(r)?!0:e.value>=r}async validatorIsLessThan(e,t,a){const{formula1:r}=t;return Number.isNaN(r)?!0:e.value<r}async validatorIsLessThanOrEqual(e,t,a){const{formula1:r}=t;return Number.isNaN(r)?!0:e.value<=r}generateRuleErrorMessage(e,t){if(!e.operator)return this.titleStr;const{transformedFormula1:a,transformedFormula2:r}=Z(this._lexerTreeBuilder,e,t);return`${this.localeService.t(ye[e.operator]).replace(k,a!=null?a:"").replace(q,r!=null?r:"")}`}}var gt=Object.defineProperty,vt=Object.getOwnPropertyDescriptor,St=(o,i,e,t)=>{for(var a=t>1?void 0:t?vt(i,e):i,r=o.length-1,n;r>=0;r--)(n=o[r])&&(a=(t?n(i,e,a):n(a))||a);return t&&a&>(i,e,a),a},L=(o,i)=>(e,t)=>i(e,t,o);let ee=class extends s.RxDisposable{constructor(o,i,e,t,a,r){super(),this._univerInstanceService=o,this._dataValidatorRegistryService=i,this._injector=e,this._selectionManagerService=t,this._sheetInterceptorService=a,this._sheetDataValidationModel=r,this._init()}_init(){this._registerValidators(),this._initCommandInterceptor()}_registerValidators(){[ft,st,_t,dt,Me,De,he,be,pt].forEach(o=>{const i=this._injector.createInstance(o);this.disposeWithMe(this._dataValidatorRegistryService.register(i)),this.disposeWithMe(s.toDisposable(()=>this._injector.delete(o)))})}_initCommandInterceptor(){this._sheetInterceptorService.interceptCommand({getMutations:o=>{var i;if(o.id===D.ClearSelectionAllCommand.id){const e=this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET),t=e.getUnitId(),a=e.getActiveSheet();if(!a)throw new Error("No active sheet found");const r=a.getSheetId(),n=(i=this._selectionManagerService.getCurrentSelections())==null?void 0:i.map(m=>m.range),l=this._sheetDataValidationModel.getRuleObjectMatrix(t,r).clone();n&&l.removeRange(n);const u=l.diff(this._sheetDataValidationModel.getRules(t,r)),{redoMutations:d,undoMutations:c}=Q(t,r,u,this._injector,"patched");return{undos:c,redos:d}}return{undos:[],redos:[]}}})}};ee=St([L(0,s.IUniverInstanceService),L(1,s.Inject(p.DataValidatorRegistryService)),L(2,s.Inject(s.Injector)),L(3,s.Inject(D.SheetsSelectionsService)),L(4,s.Inject(D.SheetInterceptorService)),L(5,s.Inject(h.SheetDataValidationModel))],ee);var Ae=(o=>(o[o.View=0]="View",o[o.Edit=1]="Edit",o[o.ManageCollaborator=2]="ManageCollaborator",o[o.Print=3]="Print",o[o.Duplicate=4]="Duplicate",o[o.Comment=5]="Comment",o[o.Copy=6]="Copy",o[o.Share=7]="Share",o[o.Export=8]="Export",o[o.MoveWorksheet=9]="MoveWorksheet",o[o.DeleteWorksheet=10]="DeleteWorksheet",o[o.HideWorksheet=11]="HideWorksheet",o[o.RenameWorksheet=12]="RenameWorksheet",o[o.CreateWorksheet=13]="CreateWorksheet",o[o.SetWorksheetStyle=14]="SetWorksheetStyle",o[o.EditWorksheetCell=15]="EditWorksheetCell",o[o.InsertHyperlink=16]="InsertHyperlink",o[o.Sort=17]="Sort",o[o.Filter=18]="Filter",o[o.PivotTable=19]="PivotTable",o[o.FloatImg=20]="FloatImg",o[o.History=21]="History",o[o.RwHgtClWdt=22]="RwHgtClWdt",o[o.ViemRwHgtClWdt=23]="ViemRwHgtClWdt",o[o.ViewFilter=24]="ViewFilter",o[o.MoveSheet=25]="MoveSheet",o[o.DeleteSheet=26]="DeleteSheet",o[o.HideSheet=27]="HideSheet",o[o.CopySheet=28]="CopySheet",o[o.RenameSheet=29]="RenameSheet",o[o.CreateSheet=30]="CreateSheet",o[o.SelectProtectedCells=31]="SelectProtectedCells",o[o.SelectUnProtectedCells=32]="SelectUnProtectedCells",o[o.SetCellStyle=33]="SetCellStyle",o[o.SetCellValue=34]="SetCellValue",o[o.SetRowStyle=35]="SetRowStyle",o[o.SetColumnStyle=36]="SetColumnStyle",o[o.InsertRow=37]="InsertRow",o[o.InsertColumn=38]="InsertColumn",o[o.DeleteRow=39]="DeleteRow",o[o.DeleteColumn=40]="DeleteColumn",o[o.EditExtraObject=41]="EditExtraObject",o[o.Delete=42]="Delete",o[o.RecoverHistory=43]="RecoverHistory",o[o.ViewHistory=44]="ViewHistory",o[o.CreatePermissionObject=45]="CreatePermissionObject",o[o.UNRECOGNIZED=-1]="UNRECOGNIZED",o))(Ae||{}),Rt=Object.defineProperty,Vt=Object.getOwnPropertyDescriptor,Dt=(o,i,e,t)=>{for(var a=t>1?void 0:t?Vt(i,e):i,r=o.length-1,n;r>=0;r--)(n=o[r])&&(a=(t?n(i,e,a):n(a))||a);return t&&a&&Rt(i,e,a),a},me=(o,i)=>(e,t)=>i(e,t,o);h.DataValidationFormulaController=class extends s.Disposable{constructor(i,e,t){super(),this._univerInstanceService=i,this._permissionService=e,this._lexerTreeBuilder=t}getFormulaRefCheck(i){var t,a;const e=this._lexerTreeBuilder.sequenceNodesBuilder(i);if(!e)return!0;for(let r=0;r<e.length;r++){const n=e[r];if(typeof n=="string")continue;const{token:l}=n,u=O.deserializeRangeWithSheetWithCache(l),d=this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET);let c=d.getActiveSheet();const m=d.getUnitId();if(u.sheetName){if(c=d.getSheetBySheetName(u.sheetName),!c)return!1;const g=c==null?void 0:c.getSheetId();if(!this._permissionService.getPermissionPoint(new D.WorksheetViewPermission(m,g).id))return!1}if(!c)return!1;const{startRow:f,endRow:v,startColumn:S,endColumn:R}=u.range;for(let g=f;g<=v;g++)for(let M=S;M<=R;M++){const N=(a=(t=c.getCell(g,M))==null?void 0:t.selectionProtection)==null?void 0:a[0];if((N==null?void 0:N[Ae.View])===!1)return!1}}return!0}},h.DataValidationFormulaController=Dt([me(0,s.IUniverInstanceService),me(1,s.IPermissionService),me(2,s.Inject(O.LexerTreeBuilder))],h.DataValidationFormulaController);var Mt=Object.defineProperty,yt=Object.getOwnPropertyDescriptor,Tt=(o,i,e,t)=>{for(var a=t>1?void 0:t?yt(i,e):i,r=o.length-1,n;r>=0;r--)(n=o[r])&&(a=(t?n(i,e,a):n(a))||a);return t&&a&&Mt(i,e,a),a},Ue=(o,i)=>(e,t)=>i(e,t,o);let te=class extends s.Disposable{constructor(i,e){super();_(this,"_disposableMap",new Map);_(this,"registerRule",(i,e,t)=>{H(t.type)&&this.register(i,e,t)});this._dataValidationModel=i,this._formulaRefRangeService=e,this._initRefRange()}_getIdWithUnitId(i,e,t){return`${i}_${e}_${t}`}register(i,e,t){const a=t.ranges,r=t.formula1,n=t.formula2,l=this._formulaRefRangeService.registerRangeFormula(i,e,a,[r!=null?r:"",n!=null?n:""],d=>{if(d.length===0)return{undos:[{id:p.AddDataValidationMutation.id,params:{unitId:i,subUnitId:e,rule:t}}],redos:[{id:p.RemoveDataValidationMutation.id,params:{unitId:i,subUnitId:e,ruleId:t.uid}}]};const c=[],m=[],f=d[0];c.push({id:p.UpdateDataValidationMutation.id,params:{unitId:i,subUnitId:e,ruleId:t.uid,payload:{type:p.UpdateRuleType.ALL,payload:{ranges:f.ranges,formula1:f.formulas[0],formula2:f.formulas[1]}}}}),m.push({id:p.UpdateDataValidationMutation.id,params:{unitId:i,subUnitId:e,ruleId:t.uid,payload:{type:p.UpdateRuleType.ALL,payload:{ranges:a,formula1:r,formula2:n}}}});for(let v=1;v<d.length;v++){const S=d[v],R=s.generateRandomId();c.push({id:p.AddDataValidationMutation.id,params:{unitId:i,subUnitId:e,rule:{...t,uid:R,formula1:S.formulas[0],formula2:S.formulas[1],ranges:S.ranges}}}),m.push({id:p.RemoveDataValidationMutation.id,params:{unitId:i,subUnitId:e,ruleId:R}})}return{undos:m,redos:c}}),u=this._getIdWithUnitId(i,e,t.uid);this._disposableMap.set(u,l)}_initRefRange(){const i=this._dataValidationModel.getAll();for(const[e,t]of i)for(const[a,r]of t)for(const n of r)this.registerRule(e,a,n);this.disposeWithMe(this._dataValidationModel.ruleChange$.subscribe(e=>{const{unitId:t,subUnitId:a,rule:r}=e;switch(e.type){case"add":{const n=e.rule;this.registerRule(e.unitId,e.subUnitId,n);break}case"remove":{const n=this._disposableMap.get(this._getIdWithUnitId(t,a,r.uid));n&&n.dispose();break}case"update":{const n=e.rule,l=this._disposableMap.get(this._getIdWithUnitId(t,a,n.uid));l&&l.dispose(),this.registerRule(e.unitId,e.subUnitId,n);break}}})),this.disposeWithMe(s.toDisposable(()=>{this._disposableMap.forEach(e=>{e.dispose()}),this._disposableMap.clear()}))}};te=Tt([Ue(0,s.Inject(h.SheetDataValidationModel)),Ue(1,s.Inject(Y.FormulaRefRangeService))],te);var Nt=Object.defineProperty,Ot=Object.getOwnPropertyDescriptor,It=(o,i,e,t)=>{for(var a=t>1?void 0:t?Ot(i,e):i,r=o.length-1,n;r>=0;r--)(n=o[r])&&(a=(t?n(i,e,a):n(a))||a);return t&&a&&Nt(i,e,a),a},B=(o,i)=>(e,t)=>i(e,t,o);let ae=class extends s.Disposable{constructor(i,e,t,a,r,n){super();_(this,"_disposableMap",new Map);_(this,"registerRule",(i,e,t)=>{H(t.type)||(this.register(i,e,t),this.registerFormula(i,e,t))});this._dataValidationModel=i,this._injector=e,this._refRangeService=t,this._dataValidationCustomFormulaService=a,this._dataValidationFormulaService=r,this._formulaRefRangeService=n,this._initRefRange()}_getIdWithUnitId(i,e,t){return`${i}_${e}_${t}`}registerFormula(i,e,t){var d;const a=t.uid,r=this._getIdWithUnitId(i,e,a),n=(d=this._disposableMap.get(r))!=null?d:new Set,l=(c,m)=>{const f=this._dataValidationModel.getRuleById(i,e,a);if(!f)return{redos:[],undos:[]};const v=f[c];if(!v||v===m)return{redos:[],undos:[]};const S={unitId:i,subUnitId:e,ruleId:t.uid,payload:{type:p.UpdateRuleType.SETTING,payload:{type:f.type,formula1:f.formula1,formula2:f.formula2,[c]:m}}},R={unitId:i,subUnitId:e,ruleId:t.uid,payload:{type:p.UpdateRuleType.SETTING,payload:{type:f.type,formula1:f.formula1,formula2:f.formula2}}},g=[{id:p.UpdateDataValidationMutation.id,params:S}],M=[{id:p.UpdateDataValidationMutation.id,params:R}];return{redos:g,undos:M}},u=this._dataValidationFormulaService.getRuleFormulaInfo(i,e,a);if(u){const[c,m]=u;if(c){const f=this._formulaRefRangeService.registerFormula(i,e,c.text,v=>l("formula1",v));n.add(()=>f.dispose())}if(m){const f=this._formulaRefRangeService.registerFormula(i,e,m.text,v=>l("formula2",v));n.add(()=>f.dispose())}}}register(i,e,t){var u;const a=d=>{const c=[...t.ranges],f=c.map(S=>D.handleCommonDefaultRangeChangeWithEffectRefCommands(S,d)).filter(S=>!!S).flat();if(s.isRangesEqual(f,c))return{redos:[],undos:[]};if(f.length){const S={unitId:i,subUnitId:e,ruleId:t.uid,payload:{type:p.UpdateRuleType.RANGE,payload:f},source:"patched"},R=[{id:p.UpdateDataValidationMutation.id,params:S}],g=[{id:p.UpdateDataValidationMutation.id,params:{unitId:i,subUnitId:e,ruleId:t.uid,payload:{type:p.UpdateRuleType.RANGE,payload:c},source:"patched"}}];return{redos:R,undos:g}}else{const S={unitId:i,subUnitId:e,ruleId:t.uid},R=[{id:p.RemoveDataValidationMutation.id,params:S}],g=ct(this._injector,S);return{redos:R,undos:g}}},r=[];t.ranges.forEach(d=>{const c=this._refRangeService.registerRefRange(d,a,i,e);r.push(()=>c.dispose())});const n=this._getIdWithUnitId(i,e,t.uid),l=(u=this._disposableMap.get(n))!=null?u:new Set;l.add(()=>r.forEach(d=>d())),this._disposableMap.set(n,l)}_initRefRange(){const i=this._dataValidationModel.getAll();for(const[e,t]of i)for(const[a,r]of t)for(const n of r)this.registerRule(e,a,n);this.disposeWithMe(this._dataValidationModel.ruleChange$.subscribe(e=>{const{unitId:t,subUnitId:a,rule:r}=e;switch(e.type){case"add":{const n=e.rule;this.registerRule(e.unitId,e.subUnitId,n);break}case"remove":{const n=this._disposableMap.get(this._getIdWithUnitId(t,a,r.uid));n&&n.forEach(l=>l());break}case"update":{const n=e.rule,l=this._disposableMap.get(this._getIdWithUnitId(t,a,n.uid));l&&l.forEach(u=>u()),this.registerRule(e.unitId,e.subUnitId,n);break}}})),this.disposeWithMe(s.toDisposable(()=>{this._disposableMap.forEach(e=>{e.forEach(t=>t())}),this._disposableMap.clear()}))}};ae=It([B(0,s.Inject(h.SheetDataValidationModel)),B(1,s.Inject(s.Injector)),B(2,s.Inject(D.RefRangeService)),B(3,s.Inject(h.DataValidationCustomFormulaService)),B(4,s.Inject(h.DataValidationFormulaService)),B(5,s.Inject(Y.FormulaRefRangeService))],ae);var Et=Object.defineProperty,Ft=Object.getOwnPropertyDescriptor,Ct=(o,i,e,t)=>{for(var a=t>1?void 0:t?Ft(i,e):i,r=o.length-1,n;r>=0;r--)(n=o[r])&&(a=(t?n(i,e,a):n(a))||a);return t&&a&&Et(i,e,a),a},fe=(o,i)=>(e,t)=>i(e,t,o);let ie=class extends s.Disposable{constructor(o,i,e){super(),this._sheetInterceptorService=o,this._univerInstanceService=i,this._sheetDataValidationModel=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:o=>{var i;if(o.id===D.RemoveSheetCommand.id){const e=o.params,t=e.unitId||this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET).getUnitId(),a=this._univerInstanceService.getUniverSheetInstance(t);if(!a)return{redos:[],undos:[]};const r=e.subUnitId||((i=a.getActiveSheet())==null?void 0:i.getSheetId());if(!r)return{redos:[],undos:[]};const n=this._sheetDataValidationModel.getRules(t,r);if(n.length===0)return{redos:[],undos:[]};const l=n.map(c=>c.uid),u={unitId:t,subUnitId:r,ruleId:l,source:"patched"},d={unitId:t,subUnitId:r,rule:[...n],source:"patched"};return{redos:[{id:p.RemoveDataValidationMutation.id,params:u}],undos:[{id:p.AddDataValidationMutation.id,params:d}]}}return{redos:[],undos:[]}}}))}};ie=Ct([fe(0,s.Inject(D.SheetInterceptorService)),fe(1,s.Inject(s.IUniverInstanceService)),fe(2,s.Inject(h.SheetDataValidationModel))],ie);var wt=Object.defineProperty,bt=Object.getOwnPropertyDescriptor,At=(o,i,e,t)=>{for(var a=t>1?void 0:t?bt(i,e):i,r=o.length-1,n;r>=0;r--)(n=o[r])&&(a=(t?n(i,e,a):n(a))||a);return t&&a&&wt(i,e,a),a},re=(o,i)=>(e,t)=>i(e,t,o);h.SheetsDataValidationValidatorService=class extends s.Disposable{constructor(i,e,t,a){super(),this._univerInstanceService=i,this._sheetDataValidationModel=e,this._dataValidationCacheService=t,this._lifecycleService=a,this._initRecalculate()}_initRecalculate(){const i=e=>{if(e.length===0)return;const t=this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET),a=t==null?void 0:t.getActiveSheet(),r={};e.flat().forEach(n=>{r[n.unitId]||(r[n.unitId]={}),r[n.unitId][n.subUnitId]||(r[n.unitId][n.subUnitId]=[]);const l=this._univerInstanceService.getUnit(n.unitId,s.UniverInstanceType.UNIVER_SHEET),u=l==null?void 0:l.getSheetBySheetId(n.subUnitId);u&&r[n.unitId][n.subUnitId].push(...n.ranges.map(d=>s.Range.transformRange(d,u)))}),Object.entries(r).forEach(([n,l])=>{Object.entries(l).forEach(([u,d])=>{(t==null?void 0:t.getUnitId())===n&&(a==null?void 0:a.getSheetId())===u?this.validatorRanges(n,u,d):requestIdleCallback(()=>{this.validatorRanges(n,u,d)})})})};this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.pipe(b.bufferWhen(()=>this._lifecycleService.lifecycle$.pipe(b.filter(e=>e===s.LifecycleStages.Rendered)))).subscribe(i)),this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.pipe(b.filter(()=>this._lifecycleService.stage>=s.LifecycleStages.Rendered),s.bufferDebounceTime(20)).subscribe(i))}async _validatorByCell(i,e,t,a){const r=i.getUnitId(),n=e.getSheetId();if(!s.Tools.isDefine(t)||!s.Tools.isDefine(a))throw new Error(`row or col is not defined, row: ${t}, col: ${a}`);const l=this._sheetDataValidationModel.getRuleByLocation(r,n,t,a);return l?new Promise(u=>{this._sheetDataValidationModel.validator(l,{unitId:r,subUnitId:n,row:t,col:a,worksheet:e,workbook:i},d=>{u(d)})}):s.DataValidationStatus.VALID}async validatorCell(i,e,t,a){const r=this._univerInstanceService.getUnit(i,s.UniverInstanceType.UNIVER_SHEET);if(!r)throw new Error(`cannot find current workbook, unitId: ${i}`);const n=r.getSheetBySheetId(e);if(!n)throw new Error(`cannot find current worksheet, sheetId: ${e}`);return this._validatorByCell(r,n,t,a)}validatorRanges(i,e,t){const a=this._univerInstanceService.getUnit(i,s.UniverInstanceType.UNIVER_SHEET);if(!a)throw new Error(`cannot find current workbook, unitId: ${i}`);const r=a.getSheetBySheetId(e);if(!r)throw new Error(`cannot find current worksheet, sheetId: ${e}`);return Promise.all(t.map(n=>{const l=[];return s.Range.foreach(n,(u,d)=>{l.push(this._validatorByCell(a,r,u,d))}),l}))}async validatorWorksheet(i,e){const t=this._univerInstanceService.getUnit(i,s.UniverInstanceType.UNIVER_SHEET);if(!t)throw new Error(`cannot find current workbook, unitId: ${i}`);const a=t.getSheetBySheetId(e);if(!a)throw new Error(`cannot find current worksheet, sheetId: ${e}`);const r=this._sheetDataValidationModel.getRules(i,e);return await Promise.all(r.map(n=>Promise.all(n.ranges.map(l=>{const u=[];return s.Range.foreach(l,(d,c)=>{u.push(this._validatorByCell(t,a,d,c))}),u})))),this._dataValidationCacheService.ensureCache(i,e)}async validatorWorkbook(i){const e=this._sheetDataValidationModel.getSubUnitIds(i),t=await Promise.all(e.map(r=>this.validatorWorksheet(i,r))),a={};return t.forEach((r,n)=>{a[e[n]]=r}),a}getDataValidations(i,e,t){const a=this._sheetDataValidationModel.getRuleObjectMatrix(i,e),r=new Set;return t.forEach(l=>{s.Range.foreach(l,(u,d)=>{const c=a.getValue(u,d);c&&r.add(c)})}),Array.from(r).map(l=>this._sheetDataValidationModel.getRuleById(i,e,l)).filter(Boolean)}getDataValidation(i,e,t){return this.getDataValidations(i,e,t)[0]}},h.SheetsDataValidationValidatorService=At([re(0,s.IUniverInstanceService),re(1,s.Inject(h.SheetDataValidationModel)),re(2,s.Inject(h.DataValidationCacheService)),re(3,s.Inject(s.LifecycleService))],h.SheetsDataValidationValidatorService);var Le=Object.defineProperty,Ut=Object.getOwnPropertyDescriptor,Lt=(o,i,e)=>i in o?Le(o,i,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[i]=e,Bt=(o,i,e,t)=>{for(var a=t>1?void 0:t?Ut(i,e):i,r=o.length-1,n;r>=0;r--)(n=o[r])&&(a=(t?n(i,e,a):n(a))||a);return t&&a&&Le(i,e,a),a},pe=(o,i)=>(e,t)=>i(e,t,o),Be=(o,i,e)=>Lt(o,typeof i!="symbol"?i+"":i,e);h.UniverSheetsDataValidationPlugin=class extends s.Plugin{constructor(i=mt,e,t,a){super(),this._config=i,this._injector=e,this._commandService=t,this._configService=a;const{...r}=this._config;this._configService.setConfig(ht,r)}onStarting(){[[h.DataValidationCacheService],[h.DataValidationFormulaService],[h.DataValidationCustomFormulaService],[h.SheetsDataValidationValidatorService],[h.SheetDataValidationModel],[ee],[h.DataValidationFormulaController],[ie],[ae],[te]].forEach(i=>{this._injector.add(i)}),[Oe,Ne,Ie,Ee,we,Ce,Fe].forEach(i=>{this._commandService.registerCommand(i)}),this._injector.get(h.DataValidationCacheService),this._injector.get(h.SheetsDataValidationValidatorService),this._injector.get(te),this._injector.get(ae)}onReady(){this._injector.get(ie)}onRendered(){this._injector.get(ee),this._injector.get(h.DataValidationFormulaController)}},Be(h.UniverSheetsDataValidationPlugin,"pluginName",Se),Be(h.UniverSheetsDataValidationPlugin,"type",s.UniverInstanceType.UNIVER_SHEET),h.UniverSheetsDataValidationPlugin=Bt([s.DependentOn(p.UniverDataValidationPlugin),pe(1,s.Inject(s.Injector)),pe(2,s.ICommandService),pe(3,s.IConfigService)],h.UniverSheetsDataValidationPlugin);function Pt(o){const e=o.get(D.SheetsSelectionsService).getCurrentSelections().map(r=>r.range);return{uid:s.Tools.generateRandomId(6),type:s.DataValidationType.DECIMAL,operator:s.DataValidationOperator.EQUAL,formula1:"100",ranges:e!=null?e:[{startColumn:0,endColumn:0,startRow:0,endRow:0}]}}h.AddSheetDataValidationCommand=Oe,h.CHECKBOX_FORMULA_1=$,h.CHECKBOX_FORMULA_2=W,h.CheckboxValidator=De,h.ClearRangeDataValidationCommand=Fe,h.DATA_VALIDATION_PLUGIN_NAME=Se,h.DateValidator=Me,h.ListMultipleValidator=be,h.ListValidator=he,h.RemoveSheetAllDataValidationCommand=Ce,h.RemoveSheetDataValidationCommand=we,h.UpdateSheetDataValidationOptionsCommand=Ee,h.UpdateSheetDataValidationRangeCommand=Ne,h.UpdateSheetDataValidationSettingCommand=Ie,h.createDefaultNewRule=Pt,h.deserializeListOptions=G,h.getCellValueOrigin=U,h.getDataValidationCellValue=nt,h.getDataValidationDiffMutations=Q,h.getFormulaCellData=j,h.getFormulaResult=A,h.isLegalFormulaResult=y,h.serializeListOptions=rt,h.transformCheckboxValue=x,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(m,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("@univerjs/core"),require("@univerjs/data-validation"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/sheets-formula"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/data-validation","@univerjs/sheets","rxjs","@univerjs/sheets-formula","@univerjs/engine-formula"],r):(m=typeof globalThis<"u"?globalThis:m||self,r(m.UniverSheetsDataValidation={},m.UniverCore,m.UniverDataValidation,m.UniverSheets,m.rxjs,m.UniverSheetsFormula,m.UniverEngineFormula))})(this,function(m,r,g,D,E,Y,T){"use strict";var Lt=Object.defineProperty;var Bt=(m,r,g)=>r in m?Lt(m,r,{enumerable:!0,configurable:!0,writable:!0,value:g}):m[r]=g;var _=(m,r,g)=>Bt(m,typeof r!="symbol"?r+"":r,g);const _e="SHEET_DATA_VALIDATION_PLUGIN";var je=Object.defineProperty,Pe=Object.getOwnPropertyDescriptor,$e=(o,s,e,t)=>{for(var a=t>1?void 0:t?Pe(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=(t?n(s,e,a):n(a))||a);return t&&a&&je(s,e,a),a},fe=(o,s)=>(e,t)=>s(e,t,o);m.DataValidationCacheService=class extends r.Disposable{constructor(e,t){super();_(this,"_cacheMatrix",new Map);_(this,"_dirtyRanges$",new E.Subject);_(this,"dirtyRanges$",this._dirtyRanges$.asObservable());this._commandService=e,this._univerInstanceService=t,this._initDirtyRanges(),this._initSheetRemove()}_initDirtyRanges(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===D.SetRangeValuesMutation.id){const{cellValue:t,unitId:a,subUnitId:i}=e.params;if(t){const n=new r.ObjectMatrix(t).getDataRange();if(n.endRow===-1)return;this.markRangeDirty(a,i,[n])}}}))}_initSheetRemove(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var t;if(e.id===D.RemoveSheetMutation.id){const{unitId:a,subUnitId:i}=e.params;(t=this._cacheMatrix.get(a))==null||t.delete(i)}})),this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(e=>{e.type===r.UniverInstanceType.UNIVER_SHEET&&this._cacheMatrix.delete(e.getUnitId())}))}_ensureCache(e,t){let a=this._cacheMatrix.get(e);a||(a=new Map,this._cacheMatrix.set(e,a));let i=a.get(t);return i||(i=new r.ObjectMatrix,a.set(t,i)),i}ensureCache(e,t){return this._ensureCache(e,t)}addRule(e,t,a){this.markRangeDirty(e,t,a.ranges)}removeRule(e,t,a){this._deleteRange(e,t,a.ranges)}markRangeDirty(e,t,a){const i=this._ensureCache(e,t);a.forEach(n=>{r.Range.foreach(n,(l,u)=>{i.setValue(l,u,void 0)})}),this._dirtyRanges$.next({unitId:e,subUnitId:t,ranges:a})}_deleteRange(e,t,a){const i=this._ensureCache(e,t);a.forEach(n=>{r.Range.foreach(n,(l,u)=>{i.realDeleteValue(l,u)})}),this._dirtyRanges$.next({unitId:e,subUnitId:t,ranges:a})}getValue(e,t,a,i){return this._ensureCache(e,t).getValue(a,i)}},m.DataValidationCacheService=$e([fe(0,r.Inject(r.ICommandService)),fe(1,r.Inject(r.IUniverInstanceService))],m.DataValidationCacheService);function N(o){var s,e;return(e=(s=o==null?void 0:o[0])==null?void 0:s[0])==null?void 0:e.v}function B(o){var s;return(s=o==null?void 0:o[0])==null?void 0:s[0]}function y(o){return!T.ERROR_TYPE_SET.has(o)}function j(o,s){var t;const e=s.getValidatorItem(o);return(t=e==null?void 0:e.offsetFormulaByRange)!=null?t:!1}var He=Object.defineProperty,We=Object.getOwnPropertyDescriptor,xe=(o,s,e,t)=>{for(var a=t>1?void 0:t?We(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=(t?n(s,e,a):n(a))||a);return t&&a&&He(s,e,a),a},P=(o,s)=>(e,t)=>s(e,t,o);m.DataValidationCustomFormulaService=class extends r.Disposable{constructor(e,t,a,i,n){super();_(this,"_ruleFormulaMap",new Map);_(this,"_ruleFormulaMap2",new Map);this._instanceSrv=e,this._registerOtherFormulaService=t,this._dataValidationModel=a,this._dataValidationCacheService=i,this._validatorRegistryService=n,this._initFormulaResultHandler()}_initFormulaResultHandler(){this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe(e=>{for(const t in e){const a=e[t];if(this._instanceSrv.getUnitType(t)===r.UniverInstanceType.UNIVER_SHEET)for(const n in a){const l=a[n],{ruleFormulaMap:u}=this._ensureMaps(t,n);l.forEach(d=>{var p,f;const c=u.get((p=d.extra)==null?void 0:p.ruleId),h=this._dataValidationModel.getRuleById(t,n,(f=d.extra)==null?void 0:f.ruleId);h&&c&&this._dataValidationCacheService.markRangeDirty(t,n,h.ranges)})}}}))}_ensureMaps(e,t){let a=this._ruleFormulaMap.get(e),i=this._ruleFormulaMap2.get(e);a||(a=new Map,this._ruleFormulaMap.set(e,a)),i||(i=new Map,this._ruleFormulaMap2.set(e,i));let n=a.get(t);n||(n=new Map,a.set(t,n));let l=i.get(t);return l||(l=new Map,i.set(t,l)),{ruleFormulaMap:n,ruleFormulaMap2:l}}_registerFormula(e,t,a,i,n){return this._registerOtherFormulaService.registerFormulaWithRange(e,t,i,n,{ruleId:a})}deleteByRuleId(e,t,a){const{ruleFormulaMap:i,ruleFormulaMap2:n}=this._ensureMaps(e,t),l=this._dataValidationModel.getRuleById(e,t,a),u=i.get(a);if(!l||!u)return;const d=i.get(a);d&&(i.delete(a),this._registerOtherFormulaService.deleteFormula(e,t,[d.formulaId]));const c=n.get(a);c&&(n.delete(a),this._registerOtherFormulaService.deleteFormula(e,t,[c.formulaId]))}_addFormulaByRange(e,t,a,i,n,l){const{ruleFormulaMap:u,ruleFormulaMap2:d}=this._ensureMaps(e,t),c=l[0].startRow,h=l[0].startColumn;if(i&&r.isFormulaString(i)){const p=this._registerFormula(e,t,a,i,l);u.set(a,{formula:i,originCol:h,originRow:c,formulaId:p})}if(n&&r.isFormulaString(n)){const p=this._registerFormula(e,t,a,n,l);d.set(a,{formula:n,originCol:h,originRow:c,formulaId:p})}}addRule(e,t,a){if(j(a.type,this._validatorRegistryService)){const{ranges:i,formula1:n,formula2:l,uid:u}=a;this._addFormulaByRange(e,t,u,n,l,i)}}async getCellFormulaValue(e,t,a,i,n){var v,R;const{ruleFormulaMap:l}=this._ensureMaps(e,t),u=l.get(a);if(!u)return Promise.resolve(void 0);const d=await this._registerOtherFormulaService.getFormulaValue(e,t,u.formulaId),{originRow:c,originCol:h}=u,p=i-c,f=n-h;return B((R=(v=d==null?void 0:d.result)==null?void 0:v[p])==null?void 0:R[f])}async getCellFormula2Value(e,t,a,i,n){var v,R;const{ruleFormulaMap2:l}=this._ensureMaps(e,t),u=l.get(a);if(!u)return Promise.resolve(void 0);const d=await this._registerOtherFormulaService.getFormulaValue(e,t,u.formulaId),{originRow:c,originCol:h}=u,p=i-c,f=n-h;return B((R=(v=d==null?void 0:d.result)==null?void 0:v[p])==null?void 0:R[f])}getCellFormulaValueSync(e,t,a,i,n){var v,R;const{ruleFormulaMap:l}=this._ensureMaps(e,t),u=l.get(a);if(!u)return;const d=this._registerOtherFormulaService.getFormulaValueSync(e,t,u.formulaId),{originRow:c,originCol:h}=u,p=i-c,f=n-h;return B((R=(v=d==null?void 0:d.result)==null?void 0:v[p])==null?void 0:R[f])}getCellFormula2ValueSync(e,t,a,i,n){var v,R;const{ruleFormulaMap2:l}=this._ensureMaps(e,t),u=l.get(a);if(!u)return;const d=this._registerOtherFormulaService.getFormulaValueSync(e,t,u.formulaId),{originRow:c,originCol:h}=u,p=i-c,f=n-h;return B((R=(v=d==null?void 0:d.result)==null?void 0:v[p])==null?void 0:R[f])}getRuleFormulaInfo(e,t,a){const{ruleFormulaMap:i}=this._ensureMaps(e,t);return i.get(a)}},m.DataValidationCustomFormulaService=xe([P(0,r.IUniverInstanceService),P(1,r.Inject(Y.RegisterOtherFormulaService)),P(2,r.Inject(g.DataValidationModel)),P(3,r.Inject(m.DataValidationCacheService)),P(4,r.Inject(g.DataValidatorRegistryService))],m.DataValidationCustomFormulaService);var qe=Object.defineProperty,Qe=Object.getOwnPropertyDescriptor,Ge=(o,s,e,t)=>{for(var a=t>1?void 0:t?Qe(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=(t?n(s,e,a):n(a))||a);return t&&a&&qe(s,e,a),a},$=(o,s)=>(e,t)=>s(e,t,o);m.DataValidationFormulaService=class extends r.Disposable{constructor(e,t,a,i,n){super();_(this,"_formulaRuleMap",new Map);this._instanceService=e,this._registerOtherFormulaService=t,this._dataValidationCacheService=a,this._dataValidationModel=i,this._validatorRegistryService=n,this._initFormulaResultHandler()}_initFormulaResultHandler(){this.disposeWithMe(this._registerOtherFormulaService.formulaResult$.subscribe(e=>{for(const t in e){const a=e[t];if(this._instanceService.getUnitType(t)===r.UniverInstanceType.UNIVER_SHEET)for(const n in a){const l=a[n],u=this._ensureRuleFormulaMap(t,n);l.forEach(d=>{var c,h;if(u.get((c=d.extra)==null?void 0:c.ruleId)){const p=this._dataValidationModel.getRuleById(t,n,(h=d.extra)==null?void 0:h.ruleId);p&&this._dataValidationCacheService.markRangeDirty(t,n,p.ranges)}})}}}))}_ensureRuleFormulaMap(e,t){let a=this._formulaRuleMap.get(e);a||(a=new Map,this._formulaRuleMap.set(e,a));let i=a.get(t);return i||(i=new Map,a.set(t,i)),i}_registerSingleFormula(e,t,a,i){const n=[{startColumn:0,endColumn:0,startRow:0,endRow:0}];return this._registerOtherFormulaService.registerFormulaWithRange(e,t,a,n,{ruleId:i})}addRule(e,t,a){if(!j(a.type,this._validatorRegistryService)&&a.type!==r.DataValidationType.CHECKBOX){const{formula1:i,formula2:n,uid:l}=a,u=r.isFormulaString(i),d=r.isFormulaString(n);if(!u&&!d)return;const c=this._ensureRuleFormulaMap(e,t),h=[void 0,void 0];if(u){const p=this._registerSingleFormula(e,t,i,l);h[0]={id:p,text:i}}if(d){const p=this._registerSingleFormula(e,t,n,l);h[1]={id:p,text:n}}c.set(l,h)}}removeRule(e,t,a){const n=this._ensureRuleFormulaMap(e,t).get(a);if(!n)return;const[l,u]=n,d=[l==null?void 0:l.id,u==null?void 0:u.id].filter(Boolean);d.length&&this._registerOtherFormulaService.deleteFormula(e,t,d)}getRuleFormulaResult(e,t,a){const n=this._ensureRuleFormulaMap(e,t).get(a);if(!n)return Promise.resolve(null);const l=async u=>u&&this._registerOtherFormulaService.getFormulaValue(e,t,u.id);return Promise.all([l(n[0]),l(n[1])])}getRuleFormulaResultSync(e,t,a){const n=this._ensureRuleFormulaMap(e,t).get(a);if(n)return n.map(l=>{if(l)return this._registerOtherFormulaService.getFormulaValueSync(e,t,l.id)})}getRuleFormulaInfo(e,t,a){return this._ensureRuleFormulaMap(e,t).get(a)}},m.DataValidationFormulaService=Ge([$(0,r.IUniverInstanceService),$(1,r.Inject(Y.RegisterOtherFormulaService)),$(2,r.Inject(m.DataValidationCacheService)),$(3,r.Inject(g.DataValidationModel)),$(4,r.Inject(g.DataValidatorRegistryService))],m.DataValidationFormulaService);function A(o){return r.getOriginCellValue(o)}function Se(o){var s;return String((s=A(o))!=null?s:"")}class oe{constructor(s,e,t,a,i=!1){_(this,"_map");_(this,"_tree",new r.RBush);_(this,"_dirty",!0);_(this,"_buildTree",()=>{if(!this._dirty||this._disableTree)return;this._tree.clear();const s=[];this._map.forEach((e,t)=>{e.forEach(a=>{s.push({minX:a.startRow,maxX:a.endRow,minY:a.startColumn,maxY:a.endColumn,ruleId:t})})}),this._tree.load(s),this._dirty=!1});_(this,"_debonceBuildTree",r.debounce(this._buildTree,0));this._unitId=e,this._subUnitId=t,this._univerInstanceService=a,this._disableTree=i,this._map=s,this._buildTree()}get _worksheet(){var s;return(s=this._univerInstanceService.getUnit(this._unitId,r.UniverInstanceType.UNIVER_SHEET))==null?void 0:s.getSheetBySheetId(this._subUnitId)}_addRule(s,e){if(!this._worksheet)return;const t=e.map(a=>r.Range.transformRange(a,this._worksheet));this._map.forEach((a,i)=>{const n=r.Rectangle.subtractMulti(a,t);n.length===0?this._map.delete(i):this._map.set(i,n)}),this._dirty=!0,this._map.set(s,t),this._debonceBuildTree()}addRule(s){this._addRule(s.uid,s.ranges)}removeRange(s){if(!this._worksheet)return;const e=s.map(t=>r.Range.transformRange(t,this._worksheet));this._map.forEach((t,a)=>{const i=r.Rectangle.subtractMulti(t,e);i.length===0?this._map.delete(a):this._map.set(a,i)}),this._dirty=!0,this._debonceBuildTree()}_removeRule(s){this._map.delete(s),this._dirty=!0,this._debonceBuildTree()}removeRule(s){this._removeRule(s.uid)}updateRange(s,e){this._removeRule(s),this._addRule(s,e)}addRangeRules(s){s.forEach(({id:e,ranges:t})=>{if(!t.length)return;let a=this._map.get(e);a?(this._map.set(e,r.Rectangle.mergeRanges([...a,...t])),a=this._map.get(e)):(a=t,this._map.set(e,a)),this._map.forEach((i,n)=>{if(n===e)return;const l=r.Rectangle.subtractMulti(i,t);l.length===0?this._map.delete(n):this._map.set(n,l)})}),this._dirty=!0,this._debonceBuildTree()}diff(s){const e=[];let t=0;return s.forEach((a,i)=>{var u;const n=(u=this._map.get(a.uid))!=null?u:[],l=a.ranges;n.length!==0&&(n.length!==l.length||n.some((d,c)=>!r.Rectangle.equals(d,l[c])))&&e.push({type:"update",ruleId:a.uid,oldRanges:l,newRanges:r.Rectangle.sort(n),rule:a}),n.length===0&&(e.push({type:"delete",rule:a,index:i-t}),t++)}),e}diffWithAddition(s,e){const t=[];let a=0;return s.forEach((i,n)=>{var d;const l=(d=this._map.get(i.uid))!=null?d:[],u=i.ranges;l.length!==0&&(l.length!==u.length||l.some((c,h)=>!r.Rectangle.equals(c,u[h])))&&t.push({type:"update",ruleId:i.uid,oldRanges:u,newRanges:r.Rectangle.sort(l),rule:i}),l.length===0&&(t.push({type:"delete",rule:i,index:n-a}),a++)}),Array.from(e).forEach(i=>{var l;const n=(l=this._map.get(i.uid))!=null?l:[];t.push({type:"add",rule:{...i,ranges:r.Rectangle.sort(n)}})}),t}clone(){return new oe(new Map(r.Tools.deepClone(Array.from(this._map.entries()))),this._unitId,this._subUnitId,this._univerInstanceService,!0)}getValue(s,e){this._dirty&&this._buildTree();const t=this._tree.search({minX:s,maxX:s,minY:e,maxY:e});return t.length>0?t[0].ruleId:void 0}}var ke=Object.defineProperty,Ye=Object.getOwnPropertyDescriptor,Xe=(o,s,e,t)=>{for(var a=t>1?void 0:t?Ye(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=(t?n(s,e,a):n(a))||a);return t&&a&&ke(s,e,a),a},C=(o,s)=>(e,t)=>s(e,t,o);m.SheetDataValidationModel=class extends r.Disposable{constructor(e,t,a,i,n,l,u){super();_(this,"_ruleMatrixMap",new Map);_(this,"_validStatusChange$",new E.Subject);_(this,"_ruleChange$",new E.Subject);_(this,"ruleChange$",this._ruleChange$.asObservable());_(this,"validStatusChange$",this._validStatusChange$.asObservable());this._dataValidationModel=e,this._univerInstanceService=t,this._dataValidatorRegistryService=a,this._dataValidationCacheService=i,this._dataValidationFormulaService=n,this._dataValidationCustomFormulaService=l,this._commandService=u,this._initRuleUpdateListener(),this.disposeWithMe(()=>{this._ruleChange$.complete(),this._validStatusChange$.complete()}),this._initUniverInstanceListener()}_initUniverInstanceListener(){this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(e=>{this._ruleMatrixMap.delete(e.getUnitId())})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===D.RemoveSheetMutation.id){const{unitId:t,subUnitId:a}=e.params,i=this._ruleMatrixMap.get(t);i&&i.delete(a)}}))}_initRuleUpdateListener(){const e=this._dataValidationModel.getAll();for(const[t,a]of e)for(const[i,n]of a)for(const l of n)this._addRule(t,i,l),this._ruleChange$.next({type:"add",unitId:t,subUnitId:i,rule:l,source:"patched"});this.disposeWithMe(this._dataValidationModel.ruleChange$.subscribe(t=>{switch(t.type){case"add":this._addRule(t.unitId,t.subUnitId,t.rule);break;case"update":this._updateRule(t.unitId,t.subUnitId,t.rule.uid,t.oldRule,t.updatePayload);break;case"remove":this._removeRule(t.unitId,t.subUnitId,t.rule);break}this._ruleChange$.next(t)}))}_ensureRuleMatrix(e,t){let a=this._ruleMatrixMap.get(e);a||(a=new Map,this._ruleMatrixMap.set(e,a));let i=a.get(t);return i||(i=new oe(new Map,e,t,this._univerInstanceService),a.set(t,i)),i}_addRuleSideEffect(e,t,a){this._ensureRuleMatrix(e,t).addRule(a),this._dataValidationCacheService.addRule(e,t,a),this._dataValidationFormulaService.addRule(e,t,a),this._dataValidationCustomFormulaService.addRule(e,t,a)}_addRule(e,t,a){(Array.isArray(a)?a:[a]).forEach(n=>{this._addRuleSideEffect(e,t,n)})}_updateRule(e,t,a,i,n){const l=this._ensureRuleMatrix(e,t),u={...i,...n.payload};n.type===g.UpdateRuleType.RANGE?l.updateRange(a,n.payload):n.type===g.UpdateRuleType.ALL&&l.updateRange(a,n.payload.ranges),this._dataValidationCacheService.removeRule(e,t,i),this._dataValidationCacheService.addRule(e,t,u),this._dataValidationFormulaService.removeRule(e,t,i.uid),this._dataValidationFormulaService.addRule(e,t,u),this._dataValidationCustomFormulaService.deleteByRuleId(e,t,a),this._dataValidationCustomFormulaService.addRule(e,t,u)}_removeRule(e,t,a){this._ensureRuleMatrix(e,t).removeRule(a),this._dataValidationCacheService.removeRule(e,t,a),this._dataValidationCustomFormulaService.deleteByRuleId(e,t,a.uid)}getValidator(e){return this._dataValidatorRegistryService.getValidatorItem(e)}getRuleIdByLocation(e,t,a,i){return this._ensureRuleMatrix(e,t).getValue(a,i)}getRuleByLocation(e,t,a,i){const n=this.getRuleIdByLocation(e,t,a,i);if(n)return this._dataValidationModel.getRuleById(e,t,n)}validator(e,t,a){const{col:i,row:n,unitId:l,subUnitId:u,worksheet:d}=t,c=(R,V)=>{a&&a(R,V),V&&this._validStatusChange$.next({unitId:l,subUnitId:u,ruleId:e.uid,status:R,row:n,col:i})},h=d.getCellValueOnly(n,i),p=this.getValidator(e.type),f=d.getCellRaw(n,i),v=A(f);if(p){const R=this._dataValidationCacheService.ensureCache(l,u),V=R.getValue(n,i);return V==null?(R.setValue(n,i,r.DataValidationStatus.VALIDATING),p.validator({value:v,unitId:l,subUnitId:u,row:n,column:i,worksheet:t.worksheet,workbook:t.workbook,interceptValue:A(h),t:f==null?void 0:f.t},e).then(S=>{const M=S?r.DataValidationStatus.VALID:r.DataValidationStatus.INVALID;M===r.DataValidationStatus.VALID?R.realDeleteValue(n,i):R.setValue(n,i,M);const O=R.getValue(n,i);c(M,V!==O)}),r.DataValidationStatus.VALIDATING):(c(V!=null?V:r.DataValidationStatus.VALID,!1),V!=null?V:r.DataValidationStatus.VALID)}else return c(r.DataValidationStatus.VALID,!1),r.DataValidationStatus.VALID}getRuleObjectMatrix(e,t){return this._ensureRuleMatrix(e,t)}getRuleById(e,t,a){return this._dataValidationModel.getRuleById(e,t,a)}getRuleIndex(e,t,a){return this._dataValidationModel.getRuleIndex(e,t,a)}getRules(e,t){return[...this._dataValidationModel.getRules(e,t)]}getUnitRules(e){return this._dataValidationModel.getUnitRules(e)}deleteUnitRules(e){return this._dataValidationModel.deleteUnitRules(e)}getSubUnitIds(e){return this._dataValidationModel.getSubUnitIds(e)}getAll(){return this._dataValidationModel.getAll()}},m.SheetDataValidationModel=Xe([C(0,r.Inject(g.DataValidationModel)),C(1,r.IUniverInstanceService),C(2,r.Inject(g.DataValidatorRegistryService)),C(3,r.Inject(m.DataValidationCacheService)),C(4,r.Inject(m.DataValidationFormulaService)),C(5,r.Inject(m.DataValidationCustomFormulaService)),C(6,r.ICommandService)],m.SheetDataValidationModel);const H=1,W=0;function ve(o,s){return r.Tools.isBlank(o)?s.t("dataValidation.validFail.value"):r.isFormulaString(o)?s.t("dataValidation.validFail.primitive"):""}const x=o=>r.Tools.isDefine(o)&&String(o).toLowerCase()==="true"?"1":String(o).toLowerCase()==="false"?"0":o;class Re extends g.BaseDataValidator{constructor(){super(...arguments);_(this,"id",r.DataValidationType.CHECKBOX);_(this,"title","dataValidation.checkbox.title");_(this,"operators",[]);_(this,"scopes",["sheet"]);_(this,"offsetFormulaByRange",!1);_(this,"_formulaService",this.injector.get(m.DataValidationFormulaService));_(this,"skipDefaultFontRender",(e,t,a)=>{const{unitId:i,subUnitId:n}=a,{formula1:l,formula2:u}=this.parseFormulaSync(e,i,n),d=`${t!=null?t:""}`;return!d||d===`${l}`||d===`${u}`})}validatorFormula(e,t,a){const{formula1:i,formula2:n}=e,l=i===n;if(r.Tools.isBlank(i)&&r.Tools.isBlank(n))return{success:!0};if(l)return{success:!1,formula1:this.localeService.t("dataValidation.validFail.checkboxEqual"),formula2:this.localeService.t("dataValidation.validFail.checkboxEqual")};const u=ve(i,this.localeService),d=ve(n,this.localeService);return{success:!u&&!d,formula1:u,formula2:d}}async parseFormula(e,t,a){var h,p,f,v;const{formula1:i=H,formula2:n=W}=e,l=await this._formulaService.getRuleFormulaResult(t,a,e.uid),u=r.isFormulaString(i)?N((p=(h=l==null?void 0:l[0])==null?void 0:h.result)==null?void 0:p[0][0]):i,d=r.isFormulaString(n)?N((v=(f=l==null?void 0:l[1])==null?void 0:f.result)==null?void 0:v[0][0]):n,c=y(String(u))&&y(String(d));return{formula1:x(u),formula2:x(d),originFormula1:u,originFormula2:d,isFormulaValid:c}}getExtraStyle(e,t){return{tb:r.WrapStrategy.CLIP}}parseFormulaSync(e,t,a){var h,p,f,v;const{formula1:i=H,formula2:n=W}=e,l=this._formulaService.getRuleFormulaResultSync(t,a,e.uid),u=r.isFormulaString(i)?N((p=(h=l==null?void 0:l[0])==null?void 0:h.result)==null?void 0:p[0][0]):i,d=r.isFormulaString(n)?N((v=(f=l==null?void 0:l[1])==null?void 0:f.result)==null?void 0:v[0][0]):n,c=y(String(u))&&y(String(d));return{formula1:x(u),formula2:x(d),originFormula1:u,originFormula2:d,isFormulaValid:c}}async isValidType(e,t,a){const{value:i,unitId:n,subUnitId:l}=e,{formula1:u,formula2:d,originFormula1:c,originFormula2:h}=await this.parseFormula(a,n,l);return!r.Tools.isDefine(u)||!r.Tools.isDefine(d)?!0:r.Tools.isDefine(i)&&(String(i)===String(u)||String(i)===String(d)||String(i)===String(c!=null?c:"")||String(i)===String(h!=null?h:""))}generateRuleErrorMessage(e){return this.localeService.t("dataValidation.checkbox.error")}}const Ke={[r.DataValidationOperator.BETWEEN]:"dataValidation.date.operators.between",[r.DataValidationOperator.EQUAL]:"dataValidation.date.operators.equal",[r.DataValidationOperator.GREATER_THAN]:"dataValidation.date.operators.greaterThan",[r.DataValidationOperator.GREATER_THAN_OR_EQUAL]:"dataValidation.date.operators.greaterThanOrEqual",[r.DataValidationOperator.LESS_THAN]:"dataValidation.date.operators.lessThan",[r.DataValidationOperator.LESS_THAN_OR_EQUAL]:"dataValidation.date.operators.lessThanOrEqual",[r.DataValidationOperator.NOT_BETWEEN]:"dataValidation.date.operators.notBetween",[r.DataValidationOperator.NOT_EQUAL]:"dataValidation.date.operators.notEqual"};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 ze={[r.DataValidationOperator.BETWEEN]:"dataValidation.date.ruleName.between",[r.DataValidationOperator.EQUAL]:"dataValidation.date.ruleName.equal",[r.DataValidationOperator.GREATER_THAN]:"dataValidation.date.ruleName.greaterThan",[r.DataValidationOperator.GREATER_THAN_OR_EQUAL]:"dataValidation.date.ruleName.greaterThanOrEqual",[r.DataValidationOperator.LESS_THAN]:"dataValidation.date.ruleName.lessThan",[r.DataValidationOperator.LESS_THAN_OR_EQUAL]:"dataValidation.date.ruleName.lessThanOrEqual",[r.DataValidationOperator.NOT_BETWEEN]:"dataValidation.date.ruleName.notBetween",[r.DataValidationOperator.NOT_EQUAL]:"dataValidation.date.ruleName.notEqual"},Ze={[r.DataValidationOperator.BETWEEN]:"dataValidation.date.errorMsg.between",[r.DataValidationOperator.EQUAL]:"dataValidation.date.errorMsg.equal",[r.DataValidationOperator.GREATER_THAN]:"dataValidation.date.errorMsg.greaterThan",[r.DataValidationOperator.GREATER_THAN_OR_EQUAL]:"dataValidation.date.errorMsg.greaterThanOrEqual",[r.DataValidationOperator.LESS_THAN]:"dataValidation.date.errorMsg.lessThan",[r.DataValidationOperator.LESS_THAN_OR_EQUAL]:"dataValidation.date.errorMsg.lessThanOrEqual",[r.DataValidationOperator.NOT_BETWEEN]:"dataValidation.date.errorMsg.notBetween",[r.DataValidationOperator.NOT_EQUAL]:"dataValidation.date.errorMsg.notEqual"},X=[r.DataValidationOperator.BETWEEN,r.DataValidationOperator.NOT_BETWEEN],q="{FORMULA1}",Q="{FORMULA2}";function Je(o){return o.filter(Boolean).join(",")}function G(o){return o.split(",").filter(Boolean)}function et(o){const s=A(o);return s==null?"":s.toString()}function K(o,s,e){const{formula1:t,formula2:a}=s,i=s.ranges[0].startRow,n=s.ranges[0].startColumn,l=e.row-i,u=e.col-n,d=r.isFormulaString(t)?o.moveFormulaRefOffset(t,u,l,!0):t,c=r.isFormulaString(a)?o.moveFormulaRefOffset(a,u,l,!0):a;return{transformedFormula1:d,transformedFormula2:c}}const se=o=>{var e,t;if(o==null||typeof o=="boolean")return;if(typeof o=="number"||!Number.isNaN(+o))return+o;const s=(e=r.numfmt.parseDate(o))==null?void 0:e.v;return r.Tools.isDefine(s)?s:(t=r.numfmt.parseDate(r.dayjs(o).format("YYYY-MM-DD HH:mm:ss")))==null?void 0:t.v};class Ve extends g.BaseDataValidator{constructor(){super(...arguments);_(this,"id",r.DataValidationType.DATE);_(this,"title","dataValidation.date.title");_(this,"operators",[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]);_(this,"scopes",["sheet"]);_(this,"_customFormulaService",this.injector.get(m.DataValidationCustomFormulaService));_(this,"_lexerTreeBuilder",this.injector.get(T.LexerTreeBuilder))}async parseFormula(e,t,a,i,n){const l=await this._customFormulaService.getCellFormulaValue(t,a,e.uid,i,n),u=await this._customFormulaService.getCellFormula2Value(t,a,e.uid,i,n),{formula1:d,formula2:c}=e,h=y(String(l==null?void 0:l.v))&&y(String(u==null?void 0:u.v));return{formula1:se(r.isFormulaString(d)?l==null?void 0:l.v:d),formula2:se(r.isFormulaString(c)?u==null?void 0:u.v:c),isFormulaValid:h}}async isValidType(e){const{interceptValue:t,value:a}=e;return typeof a=="number"&&typeof t=="string"?!0:typeof t=="string"?!!r.numfmt.parseDate(t):!1}_validatorSingleFormula(e){return!r.Tools.isBlank(e)&&(r.isFormulaString(e)||!Number.isNaN(+e)||!!(e&&r.numfmt.parseDate(e)))}validatorFormula(e,t,a){const i=e.operator;if(!i)return{success:!1};const n=this._validatorSingleFormula(e.formula1),l=this.localeService.t("dataValidation.validFail.date");if(X.includes(i)){const d=this._validatorSingleFormula(e.formula2);return{success:n&&d,formula1:n?void 0:l,formula2:d?void 0:l}}return{success:n,formula1:n?void 0:l}}normalizeFormula(e,t,a){const{formula1:i,formula2:n,bizInfo:l}=e,u=d=>{var h;if(!d)return d;let c;if(!Number.isNaN(+d))c=r.numfmt.dateFromSerial(+d);else{const p=(h=r.numfmt.parseDate(d))==null?void 0:h.v;if(p==null)return"";c=r.numfmt.dateFromSerial(p)}return r.dayjs(`${c[0]}/${c[1]}/${c[2]} ${c[3]}:${c[4]}:${c[5]}`).format(l!=null&&l.showTime?"YYYY-MM-DD HH:mm:ss":"YYYY-MM-DD")};return{formula1:r.isFormulaString(i)?i:u(`${i}`),formula2:r.isFormulaString(n)?n:u(`${n}`)}}transform(e,t,a){const{value:i}=e;return{...e,value:se(i)}}get operatorNames(){return this.operators.map(e=>this.localeService.t(Ke[e]))}generateRuleName(e){var a,i;if(!e.operator)return this.titleStr;const t=this.localeService.t(ze[e.operator]).replace(q,(a=e.formula1)!=null?a:"").replace(Q,(i=e.formula2)!=null?i:"");return`${this.titleStr} ${t}`}generateRuleErrorMessage(e,t){if(!e.operator)return this.titleStr;const{transformedFormula1:a,transformedFormula2:i}=K(this._lexerTreeBuilder,e,t);return`${this.localeService.t(Ze[e.operator]).replace(q,a!=null?a:"").replace(Q,i!=null?i:"")}`}}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+"",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 De={[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"};function z(o){let s=o;return typeof o=="string"?((o.startsWith("¥")||o.startsWith("$"))&&(s=o.slice(1)),+s):+o}class tt extends g.BaseDataValidator{constructor(){super(...arguments);_(this,"_customFormulaService",this.injector.get(m.DataValidationCustomFormulaService));_(this,"id",r.DataValidationType.DECIMAL);_(this,"_lexerTreeBuilder",this.injector.get(T.LexerTreeBuilder));_(this,"title","dataValidation.decimal.title");_(this,"operators",[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]);_(this,"scopes",["sheet"])}_isFormulaOrNumber(e){return!r.Tools.isBlank(e)&&(r.isFormulaString(e)||!Number.isNaN(+e))}async isValidType(e,t,a){const{value:i}=e;return!Number.isNaN(z(i))}transform(e,t,a){const{value:i}=e;return{...e,value:z(i)}}_parseNumber(e){return e==null?Number.NaN:+e}async parseFormula(e,t,a,i,n){const l=await this._customFormulaService.getCellFormulaValue(t,a,e.uid,i,n),u=await this._customFormulaService.getCellFormula2Value(t,a,e.uid,i,n),{formula1:d,formula2:c}=e,h=y(String(l==null?void 0:l.v))&&y(String(u==null?void 0:u.v));return{formula1:this._parseNumber(r.isFormulaString(d)?l==null?void 0:l.v:d),formula2:this._parseNumber(r.isFormulaString(c)?u==null?void 0:u.v:c),isFormulaValid:h}}validatorFormula(e,t,a){const i=e.operator;if(!i)return{success:!1};const n=r.Tools.isDefine(e.formula1)&&this._isFormulaOrNumber(e.formula1),l=r.Tools.isDefine(e.formula2)&&this._isFormulaOrNumber(e.formula2),u=X.includes(i),d=this.localeService.t("dataValidation.validFail.number");return u?{success:n&&l,formula1:n?void 0:d,formula2:l?void 0:d}:{success:n,formula1:n?"":d}}generateRuleErrorMessage(e,t){if(!e.operator)return this.titleStr;const{transformedFormula1:a,transformedFormula2:i}=K(this._lexerTreeBuilder,e,t);return`${this.localeService.t(De[e.operator]).replace(q,a!=null?a:"").replace(Q,i!=null?i:"")}`}}function le(o){if(!o)return[];const s=new Set;return o.forEach(e=>{e.forEach(t=>{var i,n;const a=A(t);if(a!=null){if(typeof a!="string"&&typeof(t==null?void 0:t.s)=="object"&&((n=(i=t.s)==null?void 0:i.n)!=null&&n.pattern)){s.add(r.numfmt.format(t.s.n.pattern,a,{throws:!1}));return}y(a.toString())&&s.add(a.toString())}})}),[...s]}const at=["if","indirect","choose","offset"];function it(o,s){if(!r.isFormulaString(o)||T.isReferenceString(o.slice(1)))return!0;const t=s.sequenceNodesBuilder(o);return t&&t.some(a=>typeof a=="object"&&a.nodeType===T.sequenceNodeType.FUNCTION&&at.indexOf(a.token.toLowerCase())>-1)}function rt(o,s){const{formula1:e="",ranges:t}=o;if(T.isReferenceString(e.slice(1))){const i=T.deserializeRangeWithSheet(e.slice(1));if((!i.sheetName||i.sheetName===s)&&t.some(n=>r.Rectangle.intersects(n,i.range)))return!0}return!1}class ue extends g.BaseDataValidator{constructor(){super(...arguments);_(this,"formulaService",this.injector.get(m.DataValidationFormulaService));_(this,"_lexer",this.injector.get(T.LexerTreeBuilder));_(this,"_univerInstanceService",this.injector.get(r.IUniverInstanceService));_(this,"offsetFormulaByRange",!1);_(this,"id",r.DataValidationType.LIST);_(this,"title","dataValidation.list.title");_(this,"operators",[]);_(this,"scopes",["sheet"]);_(this,"skipDefaultFontRender",e=>e.renderMode!==r.DataValidationRenderMode.TEXT)}validatorFormula(e,t,a){var d,c,h;const i=!r.Tools.isBlank(e.formula1),n=it((d=e.formula1)!=null?d:"",this._lexer),l=(h=(c=this._univerInstanceService.getUnit(t,r.UniverInstanceType.UNIVER_SHEET))==null?void 0:c.getSheetBySheetId(a))==null?void 0:h.getName(),u=rt(e,l!=null?l:"");return{success:!!(i&&n&&!u),formula1:i?n?u?this.localeService.t("dataValidation.validFail.listIntersects"):void 0:this.localeService.t("dataValidation.validFail.listInvalid"):this.localeService.t("dataValidation.validFail.list")}}getExtraStyle(e,t,{style:a}){var n;const i=(n=a.tb!==r.WrapStrategy.OVERFLOW?a.tb:r.WrapStrategy.CLIP)!=null?n:r.WrapStrategy.WRAP;if(e.type===r.DataValidationType.LIST&&(e.renderMode===r.DataValidationRenderMode.ARROW||e.renderMode===r.DataValidationRenderMode.TEXT)){const l=this.getListWithColorMap(e),u=`${t!=null?t:""}`,d=l[u];if(d)return{bg:{rgb:d},tb:i}}return{tb:i}}parseCellValue(e){const t=e.toString();return G(t)}async parseFormula(e,t,a){var u,d;const i=await this.formulaService.getRuleFormulaResult(t,a,e.uid),n=N((d=(u=i==null?void 0:i[0])==null?void 0:u.result)==null?void 0:d[0][0]);return{formula1:void 0,formula2:void 0,isFormulaValid:y(String(n))}}async isValidType(e,t,a){var p,f;const{value:i,unitId:n,subUnitId:l}=e,{formula1:u=""}=a,d=await this.formulaService.getRuleFormulaResult(n,l,a.uid),c=r.isFormulaString(u)?le((f=(p=d==null?void 0:d[0])==null?void 0:p.result)==null?void 0:f[0][0]):G(u);return this.parseCellValue(i).every(v=>c.includes(v))}generateRuleName(){return this.localeService.t("dataValidation.list.name")}generateRuleErrorMessage(){return this.localeService.t("dataValidation.list.error")}getList(e,t,a){var p,f,v,R;const{formula1:i=""}=e,n=this.injector.get(r.IUniverInstanceService),l=(p=t?n.getUniverSheetInstance(t):void 0)!=null?p:n.getCurrentUnitForType(r.UniverInstanceType.UNIVER_SHEET);if(!l)return[];const u=(f=a?l.getSheetBySheetId(a):void 0)!=null?f:l.getActiveSheet();if(!u)return[];const d=l.getUnitId(),c=u.getSheetId(),h=this.formulaService.getRuleFormulaResultSync(d,c,e.uid);return r.isFormulaString(i)?le((R=(v=h==null?void 0:h[0])==null?void 0:v.result)==null?void 0:R[0][0]):G(i)}async getListAsync(e,t,a){var p,f,v,R;const{formula1:i=""}=e,n=this.injector.get(r.IUniverInstanceService),l=(p=t?n.getUniverSheetInstance(t):void 0)!=null?p:n.getCurrentUnitForType(r.UniverInstanceType.UNIVER_SHEET);if(!l)return[];const u=(f=a?l.getSheetBySheetId(a):void 0)!=null?f:l.getActiveSheet();if(!u)return[];const d=l.getUnitId(),c=u.getSheetId(),h=await this.formulaService.getRuleFormulaResult(d,c,e.uid);return r.isFormulaString(i)?le((R=(v=h==null?void 0:h[0])==null?void 0:v.result)==null?void 0:R[0][0]):G(i)}getListWithColor(e,t,a){const i=this.getList(e,t,a),n=(e.formula2||"").split(",");return i.map((l,u)=>({label:l,color:n[u]}))}getListWithColorMap(e,t,a){const i=this.getListWithColor(e,t,a),n={};return i.forEach(l=>{l.color&&(n[l.label]=l.color)}),n}}class nt extends g.BaseDataValidator{constructor(){super(...arguments);_(this,"id",r.DataValidationType.TEXT_LENGTH);_(this,"title","dataValidation.textLength.title");_(this,"_lexerTreeBuilder",this.injector.get(T.LexerTreeBuilder));_(this,"operators",[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]);_(this,"scopes",["sheet"]);_(this,"_customFormulaService",this.injector.get(m.DataValidationCustomFormulaService))}_isFormulaOrInt(e){return!r.Tools.isBlank(e)&&(r.isFormulaString(e)||!Number.isNaN(+e)&&Number.isInteger(+e))}validatorFormula(e,t,a){const i=e.operator;if(!i)return{success:!1};const n=r.Tools.isDefine(e.formula1)&&this._isFormulaOrInt(e.formula1),l=r.Tools.isDefine(e.formula2)&&this._isFormulaOrInt(e.formula2),u=X.includes(i),d=this.localeService.t("dataValidation.validFail.number");return u?{success:n&&l,formula1:n?void 0:d,formula2:l?void 0:d}:{success:n,formula1:d}}_parseNumber(e){return e==null?Number.NaN:+e}async parseFormula(e,t,a,i,n){const l=await this._customFormulaService.getCellFormulaValue(t,a,e.uid,i,n),u=await this._customFormulaService.getCellFormula2Value(t,a,e.uid,i,n),{formula1:d,formula2:c}=e,h=y(String(l==null?void 0:l.v))&&y(String(u==null?void 0:u.v));return{formula1:this._parseNumber(r.isFormulaString(d)?l==null?void 0:l.v:d),formula2:this._parseNumber(r.isFormulaString(c)?u==null?void 0:u.v:c),isFormulaValid:h}}transform(e,t,a){return{...e,value:e.value.toString().length}}async isValidType(e,t,a){const{value:i}=e;return typeof i=="string"||typeof i=="number"}generateRuleErrorMessage(e,t){if(!e.operator)return this.titleStr;const{transformedFormula1:a,transformedFormula2:i}=K(this._lexerTreeBuilder,e,t);return`${this.localeService.t(g.TextLengthErrorTitleMap[e.operator]).replace(q,a!=null?a:"").replace(Q,i!=null?i:"")}`}}function Me(o){var e,t;return o?o.p?!((t=(e=o.p.body)==null?void 0:e.dataStream)!=null?t:"").slice(0,-2).trim():r.Tools.isBlank(o.v):!0}function k(o,s,e,t,a="command",i=!0){const n=t.get(T.LexerTreeBuilder),l=t.get(g.DataValidatorRegistryService),u=[],d=[],c=t.get(m.SheetDataValidationModel),h=t.get(r.IUniverInstanceService),p=D.getSheetCommandTarget(h,{unitId:o,subUnitId:s});if(!p)return{redoMutations:u,undoMutations:d};const{worksheet:f}=p,v=new r.ObjectMatrix;let R=!1;function V(S,M){i&&S.forEach(O=>{r.Range.foreach(O,(I,F)=>{const b=f.getCellRaw(I,F),L=Se(b);(Me(b)||L===M)&&(R=!0,v.setValue(I,F,{v:M,p:null}))})})}if(e.forEach(S=>{switch(S.type){case"delete":u.push({id:g.RemoveDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:S.rule.uid,source:a}}),d.unshift({id:g.AddDataValidationMutation.id,params:{unitId:o,subUnitId:s,rule:S.rule,index:S.index,source:a}});break;case"update":{if(j(S.rule.type,l)){const O=S.oldRanges[0].startRow,I=S.oldRanges[0].startColumn,F=S.newRanges[0].startRow,b=S.newRanges[0].startColumn,L=F-O,ie=b-I,re=r.isFormulaString(S.rule.formula1)?n.moveFormulaRefOffset(S.rule.formula1,ie,L):S.rule.formula1,ne=r.isFormulaString(S.rule.formula2)?n.moveFormulaRefOffset(S.rule.formula2,ie,L):S.rule.formula2;re!==S.rule.formula1||ne!==S.rule.formula2||!r.isRangesEqual(S.newRanges,S.oldRanges)?(u.push({id:g.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:S.ruleId,payload:{type:g.UpdateRuleType.ALL,payload:{formula1:re,formula2:ne,ranges:S.newRanges}}}}),d.unshift({id:g.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:S.ruleId,payload:{type:g.UpdateRuleType.ALL,payload:{formula1:S.rule.formula1,formula2:S.rule.formula2,ranges:S.oldRanges}}}})):(u.push({id:g.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:S.ruleId,payload:{type:g.UpdateRuleType.RANGE,payload:S.newRanges},source:a}}),d.unshift({id:g.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:S.ruleId,payload:{type:g.UpdateRuleType.RANGE,payload:S.oldRanges},source:a}}))}else u.push({id:g.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:S.ruleId,payload:{type:g.UpdateRuleType.RANGE,payload:S.newRanges},source:a}}),d.unshift({id:g.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:S.ruleId,payload:{type:g.UpdateRuleType.RANGE,payload:S.oldRanges},source:a}});const M=c.getRuleById(o,s,S.ruleId);if(M&&M.type===r.DataValidationType.CHECKBOX){const I=c.getValidator(r.DataValidationType.CHECKBOX).parseFormulaSync(M,o,s);V(S.newRanges,I.formula2)}break}case"add":{if(u.push({id:g.AddDataValidationMutation.id,params:{unitId:o,subUnitId:s,rule:S.rule,source:a}}),d.unshift({id:g.RemoveDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:S.rule.uid,source:a}}),S.rule.type===r.DataValidationType.CHECKBOX){const O=c.getValidator(r.DataValidationType.CHECKBOX).parseFormulaSync(S.rule,o,s);V(S.rule.ranges,O.originFormula2)}break}}}),R){const S={id:D.SetRangeValuesMutation.id,params:{unitId:o,subUnitId:s,cellValue:v.getData()}},M={id:D.SetRangeValuesMutation.id,params:D.SetRangeValuesUndoMutationFactory(t,S.params)};u.push(S),d.push(M)}return{redoMutations:u,undoMutations:d}}const ye={type:r.CommandType.COMMAND,id:"sheet.command.updateDataValidationRuleRange",handler(o,s){if(!s)return!1;const{unitId:e,subUnitId:t,ranges:a,ruleId:i}=s,n=o.get(m.SheetDataValidationModel),l=o.get(r.ICommandService),u=o.get(r.IUndoRedoService);if(!n.getRuleById(e,t,i))return!1;const c=n.getRuleObjectMatrix(e,t).clone();c.updateRange(i,a);const h=c.diff(n.getRules(e,t)),{redoMutations:p,undoMutations:f}=k(e,t,h,o);return u.pushUndoRedo({undoMutations:f,redoMutations:p,unitID:e}),r.sequenceExecute(p,l),!0}},Te={type:r.CommandType.COMMAND,id:"sheet.command.addDataValidation",handler(o,s){if(!s)return!1;const{unitId:e,subUnitId:t,rule:a}=s,i=o.get(m.SheetDataValidationModel),n=o.get(r.ICommandService),l=o.get(r.IUndoRedoService),u=i.getRuleObjectMatrix(e,t).clone();u.addRule(a);const d=u.diff(i.getRules(e,t)),c=i.getValidator(a.type),h={unitId:e,subUnitId:t,rule:{...a,...c==null?void 0:c.normalizeFormula(a,e,t)}},{redoMutations:p,undoMutations:f}=k(e,t,d,o);return p.push({id:g.AddDataValidationMutation.id,params:h}),f.unshift({id:g.RemoveDataValidationMutation.id,params:{unitId:e,subUnitId:t,ruleId:a.uid}}),l.pushUndoRedo({unitID:e,redoMutations:p,undoMutations:f}),r.sequenceExecute(p,n),!0}},Oe={type:r.CommandType.COMMAND,id:"sheets.command.update-data-validation-setting",handler(o,s){if(!s)return!1;const e=o.get(r.ICommandService),t=o.get(r.IUndoRedoService),a=o.get(m.SheetDataValidationModel),i=o.get(g.DataValidatorRegistryService),{unitId:n,subUnitId:l,ruleId:u,setting:d}=s,c=i.getValidatorItem(d.type);if(!c)return!1;const h=a.getRuleById(n,l,u);if(!h)return!1;const p={...h,...d};if(!c.validatorFormula(p,n,l).success)return!1;const f={unitId:n,subUnitId:l,ruleId:u,payload:{type:g.UpdateRuleType.SETTING,payload:{...d,...c.normalizeFormula(p,n,l)}}},v=[{id:g.UpdateDataValidationMutation.id,params:f}],R={unitId:n,subUnitId:l,ruleId:u,payload:{type:g.UpdateRuleType.SETTING,payload:g.getRuleSetting(h)}},V=[{id:g.UpdateDataValidationMutation.id,params:R}];if(d.type===r.DataValidationType.CHECKBOX){const M=h.ranges,O=o.get(r.IUniverInstanceService),I=D.getSheetCommandTarget(O,{unitId:n,subUnitId:l});if(I){const F=new r.ObjectMatrix,{worksheet:b}=I,{formula2:L=W,formula1:ie=H}=h,{formula2:re=W,formula1:ne=H}=d;M.forEach(bt=>{r.Range.foreach(bt,(pe,ge)=>{const Le=b.getCellRaw(pe,ge),Be=Se(Le);Me(Le)||Be===String(L)?F.setValue(pe,ge,{v:re,p:null}):Be===String(ie)&&F.setValue(pe,ge,{v:ne,p:null})})});const be={id:D.SetRangeValuesMutation.id,params:{unitId:n,subUnitId:l,cellValue:F.getData()}},Ut={id:D.SetRangeValuesMutation.id,params:D.SetRangeValuesUndoMutationFactory(o,be.params)};v.push(be),V.push(Ut)}}return r.sequenceExecute(v,e).result?(t.pushUndoRedo({unitID:n,redoMutations:v,undoMutations:V}),!0):!1}},Ie={type:r.CommandType.COMMAND,id:"sheets.command.update-data-validation-options",handler(o,s){if(!s)return!1;const e=o.get(r.ICommandService),t=o.get(r.IUndoRedoService),a=o.get(m.SheetDataValidationModel),{unitId:i,subUnitId:n,ruleId:l,options:u}=s,d=a.getRuleById(i,n,l);if(!d)return!1;const c={unitId:i,subUnitId:n,ruleId:l,payload:{type:g.UpdateRuleType.OPTIONS,payload:u}},h=[{id:g.UpdateDataValidationMutation.id,params:c}],p={unitId:i,subUnitId:n,ruleId:l,payload:{type:g.UpdateRuleType.OPTIONS,payload:g.getRuleOptions(d)}},f=[{id:g.UpdateDataValidationMutation.id,params:p}];return t.pushUndoRedo({unitID:i,redoMutations:h,undoMutations:f}),e.executeCommand(g.UpdateDataValidationMutation.id,c),!0}},Fe={type:r.CommandType.COMMAND,id:"sheets.command.clear-range-data-validation",handler(o,s){if(!s)return!1;const{unitId:e,subUnitId:t,ranges:a}=s,i=o.get(r.ICommandService),n=o.get(r.IUniverInstanceService),l=D.getSheetCommandTarget(n,{unitId:e,subUnitId:t}),u=o.get(m.SheetDataValidationModel);if(!l)return!1;const d=o.get(r.IUndoRedoService),c=u.getRuleObjectMatrix(e,t).clone();c.removeRange(a);const h=c.diff(u.getRules(e,t)),{redoMutations:p,undoMutations:f}=k(e,t,h,o);return d.pushUndoRedo({unitID:e,redoMutations:p,undoMutations:f}),r.sequenceExecute(p,i).result}},Ce={type:r.CommandType.COMMAND,id:"sheet.command.remove-all-data-validation",handler(o,s){if(!s)return!1;const{unitId:e,subUnitId:t}=s,a=o.get(r.ICommandService),i=o.get(m.SheetDataValidationModel),n=o.get(r.IUndoRedoService),l=[...i.getRules(e,t)],u={unitId:e,subUnitId:t,ruleId:l.map(h=>h.uid)},d=[{id:g.RemoveDataValidationMutation.id,params:u}],c=[{id:g.AddDataValidationMutation.id,params:{unitId:e,subUnitId:t,rule:l}}];return n.pushUndoRedo({redoMutations:d,undoMutations:c,unitID:e}),a.executeCommand(g.RemoveDataValidationMutation.id,u),!0}},ot=(o,s)=>{const e=o.get(m.SheetDataValidationModel),{unitId:t,subUnitId:a,ruleId:i,source:n}=s;if(Array.isArray(i)){const u=i.map(d=>e.getRuleById(t,a,d)).filter(Boolean);return[{id:g.AddDataValidationMutation.id,params:{unitId:t,subUnitId:a,rule:u,source:n}}]}return[{id:g.AddDataValidationMutation.id,params:{unitId:t,subUnitId:a,rule:{...e.getRuleById(t,a,i)},index:e.getRuleIndex(t,a,i)}}]},Ee={type:r.CommandType.COMMAND,id:"sheet.command.remove-data-validation-rule",handler(o,s){if(!s)return!1;const{unitId:e,subUnitId:t,ruleId:a}=s,i=o.get(r.ICommandService),n=o.get(r.IUndoRedoService),l=o.get(m.SheetDataValidationModel),u=[{id:g.RemoveDataValidationMutation.id,params:s}],d=[{id:g.AddDataValidationMutation.id,params:{unitId:e,subUnitId:t,rule:{...l.getRuleById(e,t,a)},index:l.getRuleIndex(e,t,a)}}];return n.pushUndoRedo({undoMutations:d,redoMutations:u,unitID:s.unitId}),i.executeCommand(g.RemoveDataValidationMutation.id,s),!0}},st="sheets-data-validation.config",lt={};var ut=Object.defineProperty,dt=Object.getOwnPropertyDescriptor,ct=(o,s,e,t)=>{for(var a=t>1?void 0:t?dt(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=(t?n(s,e,a):n(a))||a);return t&&a&&ut(s,e,a),a},de=(o,s)=>(e,t)=>s(e,t,o);let Z=class extends r.Disposable{constructor(s,e,t){super();_(this,"_disposableMap",new Map);_(this,"registerRule",(s,e,t)=>{j(t.type,this._validatorRegistryService)&&this.register(s,e,t)});this._dataValidationModel=s,this._formulaRefRangeService=e,this._validatorRegistryService=t,this._initRefRange()}_getIdWithUnitId(s,e,t){return`${s}_${e}_${t}`}register(s,e,t){const a=t.ranges,i=t.formula1,n=t.formula2,l=this._formulaRefRangeService.registerRangeFormula(s,e,a,[i!=null?i:"",n!=null?n:""],d=>{if(d.length===0)return{undos:[{id:g.AddDataValidationMutation.id,params:{unitId:s,subUnitId:e,rule:t}}],redos:[{id:g.RemoveDataValidationMutation.id,params:{unitId:s,subUnitId:e,ruleId:t.uid}}]};const c=[],h=[],p=d[0];c.push({id:g.UpdateDataValidationMutation.id,params:{unitId:s,subUnitId:e,ruleId:t.uid,payload:{type:g.UpdateRuleType.ALL,payload:{ranges:p.ranges,formula1:p.formulas[0],formula2:p.formulas[1]}}}}),h.push({id:g.UpdateDataValidationMutation.id,params:{unitId:s,subUnitId:e,ruleId:t.uid,payload:{type:g.UpdateRuleType.ALL,payload:{ranges:a,formula1:i,formula2:n}}}});for(let f=1;f<d.length;f++){const v=d[f],R=r.generateRandomId();c.push({id:g.AddDataValidationMutation.id,params:{unitId:s,subUnitId:e,rule:{...t,uid:R,formula1:v.formulas[0],formula2:v.formulas[1],ranges:v.ranges}}}),h.push({id:g.RemoveDataValidationMutation.id,params:{unitId:s,subUnitId:e,ruleId:R}})}return{undos:h,redos:c}}),u=this._getIdWithUnitId(s,e,t.uid);this._disposableMap.set(u,l)}_initRefRange(){const s=this._dataValidationModel.getAll();for(const[e,t]of s)for(const[a,i]of t)for(const n of i)this.registerRule(e,a,n);this.disposeWithMe(this._dataValidationModel.ruleChange$.subscribe(e=>{const{unitId:t,subUnitId:a,rule:i}=e;switch(e.type){case"add":{const n=e.rule;this.registerRule(e.unitId,e.subUnitId,n);break}case"remove":{const n=this._disposableMap.get(this._getIdWithUnitId(t,a,i.uid));n&&n.dispose();break}case"update":{const n=e.rule,l=this._disposableMap.get(this._getIdWithUnitId(t,a,n.uid));l&&l.dispose(),this.registerRule(e.unitId,e.subUnitId,n);break}}})),this.disposeWithMe(r.toDisposable(()=>{this._disposableMap.forEach(e=>{e.dispose()}),this._disposableMap.clear()}))}};Z=ct([de(0,r.Inject(m.SheetDataValidationModel)),de(1,r.Inject(Y.FormulaRefRangeService)),de(2,r.Inject(g.DataValidatorRegistryService))],Z);var Ne=(o=>(o[o.View=0]="View",o[o.Edit=1]="Edit",o[o.ManageCollaborator=2]="ManageCollaborator",o[o.Print=3]="Print",o[o.Duplicate=4]="Duplicate",o[o.Comment=5]="Comment",o[o.Copy=6]="Copy",o[o.Share=7]="Share",o[o.Export=8]="Export",o[o.MoveWorksheet=9]="MoveWorksheet",o[o.DeleteWorksheet=10]="DeleteWorksheet",o[o.HideWorksheet=11]="HideWorksheet",o[o.RenameWorksheet=12]="RenameWorksheet",o[o.CreateWorksheet=13]="CreateWorksheet",o[o.SetWorksheetStyle=14]="SetWorksheetStyle",o[o.EditWorksheetCell=15]="EditWorksheetCell",o[o.InsertHyperlink=16]="InsertHyperlink",o[o.Sort=17]="Sort",o[o.Filter=18]="Filter",o[o.PivotTable=19]="PivotTable",o[o.FloatImg=20]="FloatImg",o[o.History=21]="History",o[o.RwHgtClWdt=22]="RwHgtClWdt",o[o.ViemRwHgtClWdt=23]="ViemRwHgtClWdt",o[o.ViewFilter=24]="ViewFilter",o[o.MoveSheet=25]="MoveSheet",o[o.DeleteSheet=26]="DeleteSheet",o[o.HideSheet=27]="HideSheet",o[o.CopySheet=28]="CopySheet",o[o.RenameSheet=29]="RenameSheet",o[o.CreateSheet=30]="CreateSheet",o[o.SelectProtectedCells=31]="SelectProtectedCells",o[o.SelectUnProtectedCells=32]="SelectUnProtectedCells",o[o.SetCellStyle=33]="SetCellStyle",o[o.SetCellValue=34]="SetCellValue",o[o.SetRowStyle=35]="SetRowStyle",o[o.SetColumnStyle=36]="SetColumnStyle",o[o.InsertRow=37]="InsertRow",o[o.InsertColumn=38]="InsertColumn",o[o.DeleteRow=39]="DeleteRow",o[o.DeleteColumn=40]="DeleteColumn",o[o.EditExtraObject=41]="EditExtraObject",o[o.Delete=42]="Delete",o[o.RecoverHistory=43]="RecoverHistory",o[o.ViewHistory=44]="ViewHistory",o[o.CreatePermissionObject=45]="CreatePermissionObject",o[o.UNRECOGNIZED=-1]="UNRECOGNIZED",o))(Ne||{}),mt=Object.defineProperty,ht=Object.getOwnPropertyDescriptor,pt=(o,s,e,t)=>{for(var a=t>1?void 0:t?ht(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=(t?n(s,e,a):n(a))||a);return t&&a&&mt(s,e,a),a},ce=(o,s)=>(e,t)=>s(e,t,o);m.DataValidationFormulaController=class extends r.Disposable{constructor(s,e,t){super(),this._univerInstanceService=s,this._permissionService=e,this._lexerTreeBuilder=t}getFormulaRefCheck(s){var t,a;const e=this._lexerTreeBuilder.sequenceNodesBuilder(s);if(!e)return!0;for(let i=0;i<e.length;i++){const n=e[i];if(typeof n=="string")continue;const{token:l}=n,u=T.deserializeRangeWithSheetWithCache(l),d=this._univerInstanceService.getCurrentUnitForType(r.UniverInstanceType.UNIVER_SHEET);let c=d.getActiveSheet();const h=d.getUnitId();if(u.sheetName){if(c=d.getSheetBySheetName(u.sheetName),!c)return!1;const V=c==null?void 0:c.getSheetId();if(!this._permissionService.getPermissionPoint(new D.WorksheetViewPermission(h,V).id))return!1}if(!c)return!1;const{startRow:p,endRow:f,startColumn:v,endColumn:R}=u.range;for(let V=p;V<=f;V++)for(let S=v;S<=R;S++){const M=(a=(t=c.getCell(V,S))==null?void 0:t.selectionProtection)==null?void 0:a[0];if((M==null?void 0:M[Ne.View])===!1)return!1}}return!0}},m.DataValidationFormulaController=pt([ce(0,r.IUniverInstanceService),ce(1,r.IPermissionService),ce(2,r.Inject(T.LexerTreeBuilder))],m.DataValidationFormulaController);var gt=Object.defineProperty,_t=Object.getOwnPropertyDescriptor,ft=(o,s,e,t)=>{for(var a=t>1?void 0:t?_t(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=(t?n(s,e,a):n(a))||a);return t&&a&>(s,e,a),a},w=(o,s)=>(e,t)=>s(e,t,o);let J=class extends r.Disposable{constructor(s,e,t,a,i,n){super();_(this,"_disposableMap",new Map);_(this,"registerRule",(s,e,t)=>{j(t.type,this._validatorRegistryService)||(this.register(s,e,t),this.registerFormula(s,e,t))});this._dataValidationModel=s,this._injector=e,this._refRangeService=t,this._dataValidationFormulaService=a,this._formulaRefRangeService=i,this._validatorRegistryService=n,this._initRefRange()}_getIdWithUnitId(s,e,t){return`${s}_${e}_${t}`}registerFormula(s,e,t){var d;const a=t.uid,i=this._getIdWithUnitId(s,e,a),n=(d=this._disposableMap.get(i))!=null?d:new Set,l=(c,h)=>{const p=this._dataValidationModel.getRuleById(s,e,a);if(!p)return{redos:[],undos:[]};const f=p[c];if(!f||f===h)return{redos:[],undos:[]};const v={unitId:s,subUnitId:e,ruleId:t.uid,payload:{type:g.UpdateRuleType.SETTING,payload:{type:p.type,formula1:p.formula1,formula2:p.formula2,[c]:h}}},R={unitId:s,subUnitId:e,ruleId:t.uid,payload:{type:g.UpdateRuleType.SETTING,payload:{type:p.type,formula1:p.formula1,formula2:p.formula2}}},V=[{id:g.UpdateDataValidationMutation.id,params:v}],S=[{id:g.UpdateDataValidationMutation.id,params:R}];return{redos:V,undos:S}},u=this._dataValidationFormulaService.getRuleFormulaInfo(s,e,a);if(u){const[c,h]=u;if(c){const p=this._formulaRefRangeService.registerFormula(s,e,c.text,f=>l("formula1",f));n.add(()=>p.dispose())}if(h){const p=this._formulaRefRangeService.registerFormula(s,e,h.text,f=>l("formula2",f));n.add(()=>p.dispose())}}}register(s,e,t){var u;const a=d=>{const c=[...t.ranges],p=c.map(v=>D.handleCommonDefaultRangeChangeWithEffectRefCommands(v,d)).filter(v=>!!v).flat();if(r.isRangesEqual(p,c))return{redos:[],undos:[]};if(p.length){const v={unitId:s,subUnitId:e,ruleId:t.uid,payload:{type:g.UpdateRuleType.RANGE,payload:p},source:"patched"},R=[{id:g.UpdateDataValidationMutation.id,params:v}],V=[{id:g.UpdateDataValidationMutation.id,params:{unitId:s,subUnitId:e,ruleId:t.uid,payload:{type:g.UpdateRuleType.RANGE,payload:c},source:"patched"}}];return{redos:R,undos:V}}else{const v={unitId:s,subUnitId:e,ruleId:t.uid},R=[{id:g.RemoveDataValidationMutation.id,params:v}],V=ot(this._injector,v);return{redos:R,undos:V}}},i=[];t.ranges.forEach(d=>{const c=this._refRangeService.registerRefRange(d,a,s,e);i.push(()=>c.dispose())});const n=this._getIdWithUnitId(s,e,t.uid),l=(u=this._disposableMap.get(n))!=null?u:new Set;l.add(()=>i.forEach(d=>d())),this._disposableMap.set(n,l)}_initRefRange(){const s=this._dataValidationModel.getAll();for(const[e,t]of s)for(const[a,i]of t)for(const n of i)this.registerRule(e,a,n);this.disposeWithMe(this._dataValidationModel.ruleChange$.subscribe(e=>{const{unitId:t,subUnitId:a,rule:i}=e;switch(e.type){case"add":{const n=e.rule;this.registerRule(e.unitId,e.subUnitId,n);break}case"remove":{const n=this._disposableMap.get(this._getIdWithUnitId(t,a,i.uid));n&&n.forEach(l=>l());break}case"update":{const n=e.rule,l=this._disposableMap.get(this._getIdWithUnitId(t,a,n.uid));l&&l.forEach(u=>u()),this.registerRule(e.unitId,e.subUnitId,n);break}}})),this.disposeWithMe(r.toDisposable(()=>{this._disposableMap.forEach(e=>{e.forEach(t=>t())}),this._disposableMap.clear()}))}};J=ft([w(0,r.Inject(m.SheetDataValidationModel)),w(1,r.Inject(r.Injector)),w(2,r.Inject(D.RefRangeService)),w(3,r.Inject(m.DataValidationFormulaService)),w(4,r.Inject(Y.FormulaRefRangeService)),w(5,r.Inject(g.DataValidatorRegistryService))],J);var St=Object.defineProperty,vt=Object.getOwnPropertyDescriptor,Rt=(o,s,e,t)=>{for(var a=t>1?void 0:t?vt(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=(t?n(s,e,a):n(a))||a);return t&&a&&St(s,e,a),a},me=(o,s)=>(e,t)=>s(e,t,o);let ee=class extends r.Disposable{constructor(o,s,e){super(),this._sheetInterceptorService=o,this._univerInstanceService=s,this._sheetDataValidationModel=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:o=>{var s;if(o.id===D.RemoveSheetCommand.id){const e=o.params,t=e.unitId||this._univerInstanceService.getCurrentUnitForType(r.UniverInstanceType.UNIVER_SHEET).getUnitId(),a=this._univerInstanceService.getUniverSheetInstance(t);if(!a)return{redos:[],undos:[]};const i=e.subUnitId||((s=a.getActiveSheet())==null?void 0:s.getSheetId());if(!i)return{redos:[],undos:[]};const n=this._sheetDataValidationModel.getRules(t,i);if(n.length===0)return{redos:[],undos:[]};const l=n.map(c=>c.uid),u={unitId:t,subUnitId:i,ruleId:l,source:"patched"},d={unitId:t,subUnitId:i,rule:[...n],source:"patched"};return{redos:[{id:g.RemoveDataValidationMutation.id,params:u}],undos:[{id:g.AddDataValidationMutation.id,params:d}]}}return{redos:[],undos:[]}}}))}};ee=Rt([me(0,r.Inject(D.SheetInterceptorService)),me(1,r.Inject(r.IUniverInstanceService)),me(2,r.Inject(m.SheetDataValidationModel))],ee);class Vt extends g.BaseDataValidator{constructor(){super(...arguments);_(this,"id",r.DataValidationType.ANY);_(this,"title","dataValidation.any.title");_(this,"operators",[]);_(this,"scopes",["sheet"]);_(this,"offsetFormulaByRange",!1)}async parseFormula(e,t,a){return{formula1:e.formula1,formula2:e.formula2,isFormulaValid:!0}}validatorFormula(e,t,a){return{success:!0}}async isValidType(e,t,a){return!0}generateRuleErrorMessage(e){return this.localeService.t("dataValidation.any.error")}}class Dt extends g.BaseDataValidator{constructor(){super(...arguments);_(this,"id",r.DataValidationType.CUSTOM);_(this,"title","dataValidation.custom.title");_(this,"operators",[]);_(this,"scopes",["sheet"]);_(this,"_customFormulaService",this.injector.get(m.DataValidationCustomFormulaService))}validatorFormula(e,t,a){const i=r.isFormulaString(e.formula1);return{success:i,formula1:i?"":this.localeService.t("dataValidation.validFail.formula")}}async parseFormula(e,t,a){return{formula1:void 0,formula2:void 0,isFormulaValid:!0}}async isValidType(e,t,a){const{column:i,row:n,unitId:l,subUnitId:u}=e,d=await this._customFormulaService.getCellFormulaValue(l,u,a.uid,n,i),c=d==null?void 0:d.v;return y(String(c))&&r.Tools.isDefine(c)&&c!==""?d.t===r.CellValueType.BOOLEAN?!!c:typeof c=="boolean"?c:typeof c=="number"?!!c:typeof c=="string"?y(c):!!c:!1}generateRuleErrorMessage(e){return this.localeService.t("dataValidation.custom.error")}generateRuleName(e){var t;return this.localeService.t("dataValidation.custom.ruleName").replace("{FORMULA1}",(t=e.formula1)!=null?t:"")}}class Ae extends ue{constructor(){super(...arguments);_(this,"id",r.DataValidationType.LIST_MULTIPLE);_(this,"title","dataValidation.listMultiple.title");_(this,"offsetFormulaByRange",!1);_(this,"skipDefaultFontRender",()=>!0)}}class Mt extends g.BaseDataValidator{constructor(){super(...arguments);_(this,"_customFormulaService",this.injector.get(m.DataValidationCustomFormulaService));_(this,"_lexerTreeBuilder",this.injector.get(T.LexerTreeBuilder));_(this,"id",r.DataValidationType.WHOLE);_(this,"title","dataValidation.whole.title");_(this,"operators",[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]);_(this,"scopes",["sheet"])}_isFormulaOrInt(e){return!r.Tools.isBlank(e)&&(r.isFormulaString(e)||!Number.isNaN(+e)&&Number.isInteger(+e))}async isValidType(e,t,a){const{value:i}=e,n=z(i);return!Number.isNaN(n)&&Number.isInteger(n)}transform(e,t,a){const{value:i}=e;return{...e,value:z(i)}}_parseNumber(e){return e==null?Number.NaN:+e}async parseFormula(e,t,a,i,n){const l=await this._customFormulaService.getCellFormulaValue(t,a,e.uid,i,n),u=await this._customFormulaService.getCellFormula2Value(t,a,e.uid,i,n),{formula1:d,formula2:c}=e,h=r.isFormulaString(d)?l==null?void 0:l.v:d,p=r.isFormulaString(c)?u==null?void 0:u.v:c,f=y(`${h}`)&&y(`${p}`);return{formula1:this._parseNumber(h),formula2:this._parseNumber(p),isFormulaValid:f}}validatorFormula(e,t,a){const i=e.operator;if(!i)return{success:!1};const n=r.Tools.isDefine(e.formula1)&&this._isFormulaOrInt(e.formula1),l=r.Tools.isDefine(e.formula2)&&this._isFormulaOrInt(e.formula2),u=X.includes(i),d=this.localeService.t("dataValidation.validFail.number");return u?{success:n&&l,formula1:n?void 0:d,formula2:l?void 0:d}:{success:n,formula1:d}}generateRuleErrorMessage(e,t){if(!e.operator)return this.titleStr;const{transformedFormula1:a,transformedFormula2:i}=K(this._lexerTreeBuilder,e,t);return`${this.localeService.t(De[e.operator]).replace(q,a!=null?a:"").replace(Q,i!=null?i:"")}`}}var yt=Object.defineProperty,Tt=Object.getOwnPropertyDescriptor,Ot=(o,s,e,t)=>{for(var a=t>1?void 0:t?Tt(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=(t?n(s,e,a):n(a))||a);return t&&a&&yt(s,e,a),a},U=(o,s)=>(e,t)=>s(e,t,o);let te=class extends r.RxDisposable{constructor(o,s,e,t,a,i){super(),this._univerInstanceService=o,this._dataValidatorRegistryService=s,this._injector=e,this._selectionManagerService=t,this._sheetInterceptorService=a,this._sheetDataValidationModel=i,this._init()}_init(){this._registerValidators(),this._initCommandInterceptor()}_registerValidators(){[Vt,tt,Mt,nt,Ve,Re,ue,Ae,Dt].forEach(o=>{const s=this._injector.createInstance(o);this.disposeWithMe(this._dataValidatorRegistryService.register(s)),this.disposeWithMe(r.toDisposable(()=>this._injector.delete(o)))})}_initCommandInterceptor(){this._sheetInterceptorService.interceptCommand({getMutations:o=>{var s;if(o.id===D.ClearSelectionAllCommand.id){const e=this._univerInstanceService.getCurrentUnitForType(r.UniverInstanceType.UNIVER_SHEET),t=e.getUnitId(),a=e.getActiveSheet();if(!a)throw new Error("No active sheet found");const i=a.getSheetId(),n=(s=this._selectionManagerService.getCurrentSelections())==null?void 0:s.map(h=>h.range),l=this._sheetDataValidationModel.getRuleObjectMatrix(t,i).clone();n&&l.removeRange(n);const u=l.diff(this._sheetDataValidationModel.getRules(t,i)),{redoMutations:d,undoMutations:c}=k(t,i,u,this._injector,"patched");return{undos:c,redos:d}}return{undos:[],redos:[]}}})}};te=Ot([U(0,r.IUniverInstanceService),U(1,r.Inject(g.DataValidatorRegistryService)),U(2,r.Inject(r.Injector)),U(3,r.Inject(D.SheetsSelectionsService)),U(4,r.Inject(D.SheetInterceptorService)),U(5,r.Inject(m.SheetDataValidationModel))],te);var It=Object.defineProperty,Ft=Object.getOwnPropertyDescriptor,Ct=(o,s,e,t)=>{for(var a=t>1?void 0:t?Ft(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=(t?n(s,e,a):n(a))||a);return t&&a&&It(s,e,a),a},ae=(o,s)=>(e,t)=>s(e,t,o);m.SheetsDataValidationValidatorService=class extends r.Disposable{constructor(s,e,t,a){super(),this._univerInstanceService=s,this._sheetDataValidationModel=e,this._dataValidationCacheService=t,this._lifecycleService=a,this._initRecalculate()}_initRecalculate(){const s=e=>{if(e.length===0)return;const t=this._univerInstanceService.getCurrentUnitForType(r.UniverInstanceType.UNIVER_SHEET),a=t==null?void 0:t.getActiveSheet(),i={};e.flat().forEach(n=>{i[n.unitId]||(i[n.unitId]={}),i[n.unitId][n.subUnitId]||(i[n.unitId][n.subUnitId]=[]);const l=this._univerInstanceService.getUnit(n.unitId,r.UniverInstanceType.UNIVER_SHEET),u=l==null?void 0:l.getSheetBySheetId(n.subUnitId);u&&i[n.unitId][n.subUnitId].push(...n.ranges.map(d=>r.Range.transformRange(d,u)))}),Object.entries(i).forEach(([n,l])=>{Object.entries(l).forEach(([u,d])=>{(t==null?void 0:t.getUnitId())===n&&(a==null?void 0:a.getSheetId())===u?this.validatorRanges(n,u,d):requestIdleCallback(()=>{this.validatorRanges(n,u,d)})})})};this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.pipe(E.bufferWhen(()=>this._lifecycleService.lifecycle$.pipe(E.filter(e=>e===r.LifecycleStages.Rendered)))).subscribe(s)),this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.pipe(E.filter(()=>this._lifecycleService.stage>=r.LifecycleStages.Rendered),r.bufferDebounceTime(20)).subscribe(s))}async _validatorByCell(s,e,t,a){const i=s.getUnitId(),n=e.getSheetId();if(!r.Tools.isDefine(t)||!r.Tools.isDefine(a))throw new Error(`row or col is not defined, row: ${t}, col: ${a}`);const l=this._sheetDataValidationModel.getRuleByLocation(i,n,t,a);return l?new Promise(u=>{this._sheetDataValidationModel.validator(l,{unitId:i,subUnitId:n,row:t,col:a,worksheet:e,workbook:s},d=>{u(d)})}):r.DataValidationStatus.VALID}async validatorCell(s,e,t,a){const i=this._univerInstanceService.getUnit(s,r.UniverInstanceType.UNIVER_SHEET);if(!i)throw new Error(`cannot find current workbook, unitId: ${s}`);const n=i.getSheetBySheetId(e);if(!n)throw new Error(`cannot find current worksheet, sheetId: ${e}`);return this._validatorByCell(i,n,t,a)}validatorRanges(s,e,t){if(!t.length)return Promise.resolve([]);const a=this._univerInstanceService.getUnit(s,r.UniverInstanceType.UNIVER_SHEET);if(!a)throw new Error(`cannot find current workbook, unitId: ${s}`);const i=a.getSheetBySheetId(e);if(!i)throw new Error(`cannot find current worksheet, sheetId: ${e}`);return Promise.all(t.map(n=>{const l=[];return r.Range.foreach(n,(u,d)=>{l.push(this._validatorByCell(a,i,u,d))}),l}))}async validatorWorksheet(s,e){const t=this._univerInstanceService.getUnit(s,r.UniverInstanceType.UNIVER_SHEET);if(!t)throw new Error(`cannot find current workbook, unitId: ${s}`);const a=t.getSheetBySheetId(e);if(!a)throw new Error(`cannot find current worksheet, sheetId: ${e}`);const i=this._sheetDataValidationModel.getRules(s,e);return await Promise.all(i.map(n=>Promise.all(n.ranges.map(l=>{const u=[];return r.Range.foreach(l,(d,c)=>{u.push(this._validatorByCell(t,a,d,c))}),u})))),this._dataValidationCacheService.ensureCache(s,e)}async validatorWorkbook(s){const e=this._sheetDataValidationModel.getSubUnitIds(s),t=await Promise.all(e.map(i=>this.validatorWorksheet(s,i))),a={};return t.forEach((i,n)=>{a[e[n]]=i}),a}getDataValidations(s,e,t){const a=this._sheetDataValidationModel.getRuleObjectMatrix(s,e),i=new Set;return t.forEach(l=>{r.Range.foreach(l,(u,d)=>{const c=a.getValue(u,d);c&&i.add(c)})}),Array.from(i).map(l=>this._sheetDataValidationModel.getRuleById(s,e,l)).filter(Boolean)}getDataValidation(s,e,t){return this.getDataValidations(s,e,t)[0]}},m.SheetsDataValidationValidatorService=Ct([ae(0,r.IUniverInstanceService),ae(1,r.Inject(m.SheetDataValidationModel)),ae(2,r.Inject(m.DataValidationCacheService)),ae(3,r.Inject(r.LifecycleService))],m.SheetsDataValidationValidatorService);var we=Object.defineProperty,Et=Object.getOwnPropertyDescriptor,Nt=(o,s,e)=>s in o?we(o,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[s]=e,At=(o,s,e,t)=>{for(var a=t>1?void 0:t?Et(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=(t?n(s,e,a):n(a))||a);return t&&a&&we(s,e,a),a},he=(o,s)=>(e,t)=>s(e,t,o),Ue=(o,s,e)=>Nt(o,typeof s!="symbol"?s+"":s,e);m.UniverSheetsDataValidationPlugin=class extends r.Plugin{constructor(s=lt,e,t,a){super(),this._config=s,this._injector=e,this._commandService=t,this._configService=a;const{...i}=this._config;this._configService.setConfig(st,i)}onStarting(){[[m.DataValidationCacheService],[m.DataValidationFormulaService],[m.DataValidationCustomFormulaService],[m.SheetsDataValidationValidatorService],[m.SheetDataValidationModel],[te],[m.DataValidationFormulaController],[ee],[J],[Z]].forEach(s=>{this._injector.add(s)}),[Te,ye,Oe,Ie,Ee,Ce,Fe].forEach(s=>{this._commandService.registerCommand(s)}),this._injector.get(m.DataValidationCacheService),this._injector.get(m.SheetsDataValidationValidatorService),this._injector.get(Z),this._injector.get(J)}onReady(){this._injector.get(ee)}onRendered(){this._injector.get(te),this._injector.get(m.DataValidationFormulaController)}},Ue(m.UniverSheetsDataValidationPlugin,"pluginName",_e),Ue(m.UniverSheetsDataValidationPlugin,"type",r.UniverInstanceType.UNIVER_SHEET),m.UniverSheetsDataValidationPlugin=At([r.DependentOn(g.UniverDataValidationPlugin),he(1,r.Inject(r.Injector)),he(2,r.ICommandService),he(3,r.IConfigService)],m.UniverSheetsDataValidationPlugin);function wt(o){const e=o.get(D.SheetsSelectionsService).getCurrentSelections().map(i=>i.range);return{uid:r.Tools.generateRandomId(6),type:r.DataValidationType.DECIMAL,operator:r.DataValidationOperator.EQUAL,formula1:"100",ranges:e!=null?e:[{startColumn:0,endColumn:0,startRow:0,endRow:0}]}}m.AddSheetDataValidationCommand=Te,m.CHECKBOX_FORMULA_1=H,m.CHECKBOX_FORMULA_2=W,m.CheckboxValidator=Re,m.ClearRangeDataValidationCommand=Fe,m.DATA_VALIDATION_PLUGIN_NAME=_e,m.DateValidator=Ve,m.ListMultipleValidator=Ae,m.ListValidator=ue,m.RemoveSheetAllDataValidationCommand=Ce,m.RemoveSheetDataValidationCommand=Ee,m.UpdateSheetDataValidationOptionsCommand=Ie,m.UpdateSheetDataValidationRangeCommand=ye,m.UpdateSheetDataValidationSettingCommand=Oe,m.createDefaultNewRule=wt,m.deserializeListOptions=G,m.getCellValueOrigin=A,m.getDataValidationCellValue=et,m.getDataValidationDiffMutations=k,m.getFormulaCellData=B,m.getFormulaResult=N,m.isLegalFormulaResult=y,m.serializeListOptions=Je,m.transformCheckboxValue=x,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-data-validation",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1-nightly.202411301606",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Data validation for Univer Sheets",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -53,21 +53,20 @@
|
|
|
53
53
|
"rxjs": ">=7.0.0"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@
|
|
57
|
-
"@univerjs/
|
|
58
|
-
"@univerjs/
|
|
59
|
-
"@univerjs/
|
|
60
|
-
"@univerjs/
|
|
61
|
-
"@univerjs/
|
|
62
|
-
"@univerjs/sheets-formula": "0.5.0"
|
|
56
|
+
"@univerjs/protocol": "0.1.39",
|
|
57
|
+
"@univerjs/core": "0.5.1-nightly.202411301606",
|
|
58
|
+
"@univerjs/engine-formula": "0.5.1-nightly.202411301606",
|
|
59
|
+
"@univerjs/sheets": "0.5.1-nightly.202411301606",
|
|
60
|
+
"@univerjs/sheets-formula": "0.5.1-nightly.202411301606",
|
|
61
|
+
"@univerjs/data-validation": "0.5.1-nightly.202411301606"
|
|
63
62
|
},
|
|
64
63
|
"devDependencies": {
|
|
65
|
-
"less": "^4.2.
|
|
64
|
+
"less": "^4.2.1",
|
|
66
65
|
"rxjs": "^7.8.1",
|
|
67
|
-
"typescript": "^5.
|
|
68
|
-
"vite": "^
|
|
69
|
-
"vitest": "^2.1.
|
|
70
|
-
"@univerjs-infra/shared": "0.5.
|
|
66
|
+
"typescript": "^5.7.2",
|
|
67
|
+
"vite": "^6.0.1",
|
|
68
|
+
"vitest": "^2.1.6",
|
|
69
|
+
"@univerjs-infra/shared": "0.5.1"
|
|
71
70
|
},
|
|
72
71
|
"space": {
|
|
73
72
|
".": {
|
package/LICENSE
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|