@univerjs/sheets-data-validation 0.4.2-nightly.202411081606 → 0.4.2-nightly.202411091134
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/facade.js +1 -1
- package/lib/es/facade.js +99 -1873
- package/lib/types/facade/f-workbook.d.ts +1 -3
- package/lib/types/facade/f-worksheet.d.ts +1 -1
- package/lib/umd/facade.js +1 -1
- package/package.json +6 -6
package/lib/cjs/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var xe=Object.defineProperty;var $e=(s,e,t)=>e in s?xe(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var b=(s,e,t)=>$e(s,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const te=require("@univerjs/sheets/facade"),i=require("@univerjs/core"),v=require("@univerjs/data-validation"),De=require("@univerjs/engine-formula"),W=require("@univerjs/sheets"),Y=require("rxjs"),Me=require("@univerjs/sheets-formula");var ke=Object.defineProperty,Ae=Object.getOwnPropertyDescriptor,Ue=(s,e,t,a)=>{for(var r=a>1?void 0:a?Ae(e,t):e,n=s.length-1,o;n>=0;n--)(o=s[n])&&(r=(a?o(e,t,r):o(r))||r);return a&&r&&ke(e,t,r),r},Fe=(s,e)=>(t,a)=>e(t,a,s);let ie=class extends i.Disposable{constructor(e){super();b(this,"_cacheMatrix",new Map);b(this,"_dirtyRanges$",new Y.Subject);b(this,"dirtyRanges$",this._dirtyRanges$.asObservable());this._commandService=e,this._initDirtyRanges()}_initDirtyRanges(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===W.SetRangeValuesMutation.id){const{cellValue:t,unitId:a,subUnitId:r}=e.params;if(t){const n=new i.ObjectMatrix(t).getDataRange();if(n.endRow===-1)return;this._dirtyRanges$.next({unitId:a,subUnitId:r,ranges:[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 i.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)}updateRuleRanges(e,t,a,r,n){const o=this._ensureCache(e,t);n.forEach(l=>{i.Range.foreach(l,(u,h)=>{const m=o.getValue(u,h);m&&(m.temp=!0)})}),r.forEach(l=>{i.Range.foreach(l,(u,h)=>{const m=o.getValue(u,h);m&&m.ruleId===a?m.temp=!1:o.setValue(u,h,void 0)})}),n.forEach(l=>{i.Range.foreach(l,(u,h)=>{const m=o.getValue(u,h);m&&m.temp===!0&&o.realDeleteValue(u,h)})}),this._dirtyRanges$.next({unitId:e,subUnitId:t,ranges:[...n,...r]})}markRangeDirty(e,t,a){const r=this._ensureCache(e,t);a.forEach(n=>{i.Range.foreach(n,(o,l)=>{r.setValue(o,l,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=>{i.Range.foreach(n,(o,l)=>{r.realDeleteValue(o,l)})}),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)}};ie=Ue([Fe(0,i.Inject(i.ICommandService))],ie);function Ne(s){var e;return(e=s==null?void 0:s[0])==null?void 0:e[0]}var Le=Object.defineProperty,Be=Object.getOwnPropertyDescriptor,He=(s,e,t,a)=>{for(var r=a>1?void 0:a?Be(e,t):e,n=s.length-1,o;n>=0;n--)(o=s[n])&&(r=(a?o(e,t,r):o(r))||r);return a&&r&&Le(e,t,r),r},he=(s,e)=>(t,a)=>e(t,a,s);let _e=class extends i.Disposable{constructor(e,t,a,r){super();b(this,"_ruleFormulaMap",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)===i.UniverInstanceType.UNIVER_SHEET)for(const n in a){const o=a[n],{ruleFormulaMap:l}=this._ensureMaps(t,n);o.forEach(u=>{var f,M;const h=l.get((f=u.extra)==null?void 0:f.ruleId),m=this._dataValidationModel.getRuleById(t,n,(M=u.extra)==null?void 0:M.ruleId);m&&h&&!h.isTransformable&&this._dataValidationCacheService.markRangeDirty(t,n,m.ranges)})}}}))}_ensureMaps(e,t){let a=this._ruleFormulaMap.get(e);a||(a=new Map,this._ruleFormulaMap.set(e,a));let r=a.get(t);return r||(r=new Map,a.set(t,r)),{ruleFormulaMap:r}}_registerFormula(e,t,a,r,n){return this._registerOtherFormulaService.registerFormulaWithRange(e,t,r,n,{ruleId:a})}deleteByRuleId(e,t,a){const{ruleFormulaMap:r}=this._ensureMaps(e,t),n=this._dataValidationModel.getRuleById(e,t,a),o=r.get(a);if(!n||!o)return;const l=r.get(a);l&&(r.delete(a),this._registerOtherFormulaService.deleteFormula(e,t,[l.formulaId]))}_addFormulaByRange(e,t,a,r,n){const{ruleFormulaMap:o}=this._ensureMaps(e,t);if(!r)return;const l=n[0].startRow,u=n[0].startColumn,h=this._registerFormula(e,t,a,r,n);o.set(a,{formula:r,originCol:u,originRow:l,formulaId:h,isTransformable:!0})}addRule(e,t,a){const{ranges:r,formula1:n,uid:o,type:l}=a;l!==i.DataValidationType.CUSTOM||!n||!i.isFormulaString(n)||this._addFormulaByRange(e,t,o,n,r)}async getCellFormulaValue(e,t,a,r,n){var E,C;const{ruleFormulaMap:o}=this._ensureMaps(e,t),l=o.get(a);if(!l)return Promise.resolve(void 0);const u=await this._registerOtherFormulaService.getFormulaValue(e,t,l.formulaId),{originRow:h,originCol:m}=l,f=r-h,M=n-m;return Ne((C=(E=u==null?void 0:u.result)==null?void 0:E[f])==null?void 0:C[M])}getRuleFormulaInfo(e,t,a){const{ruleFormulaMap:r}=this._ensureMaps(e,t);return r.get(a)}};_e=He([he(0,i.IUniverInstanceService),he(1,i.Inject(Me.RegisterOtherFormulaService)),he(2,i.Inject(v.DataValidationModel)),he(3,i.Inject(ie))],_e);var je=Object.defineProperty,qe=Object.getOwnPropertyDescriptor,We=(s,e,t,a)=>{for(var r=a>1?void 0:a?qe(e,t):e,n=s.length-1,o;n>=0;n--)(o=s[n])&&(r=(a?o(e,t,r):o(r))||r);return a&&r&&je(e,t,r),r},ce=(s,e)=>(t,a)=>e(t,a,s);let fe=class extends i.Disposable{constructor(e,t,a,r){super();b(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)===i.UniverInstanceType.UNIVER_SHEET)for(const n in a){const o=a[n],l=this._ensureRuleFormulaMap(t,n);o.forEach(u=>{var h,m;if(l.get((h=u.extra)==null?void 0:h.ruleId)){const f=this._dataValidationModel.getRuleById(t,n,(m=u.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,r,n,o){const l=i.isFormulaString(r),u=i.isFormulaString(n);if(!l&&!u)return;const h=this._ensureRuleFormulaMap(e,t),m=[void 0,void 0];if(l){const f=this._registerSingleFormula(e,t,r,a);m[0]={id:f,text:r}}if(u){const f=this._registerSingleFormula(e,t,n,a);m[1]={id:f,text:n}}h.set(a,m)}removeRule(e,t,a){const n=this._ensureRuleFormulaMap(e,t).get(a);if(!n)return;const[o,l]=n,u=[o==null?void 0:o.id,l==null?void 0:l.id].filter(Boolean);u.length&&this._registerOtherFormulaService.deleteFormula(e,t,u)}updateRuleFormulaText(e,t,a,r,n,o){const u=this._ensureRuleFormulaMap(e,t).get(a);if(!u){this.addRule(e,t,a,r,n,o);return}const[h,m]=u;if((h==null?void 0:h.text)!==r)if(h&&this._registerOtherFormulaService.deleteFormula(e,t,[h.id]),i.isFormulaString(r)){const f=this._registerSingleFormula(e,t,r,a);u[0]={text:r,id:f}}else u[0]=void 0;if((m==null?void 0:m.text)!==n)if(m&&this._registerOtherFormulaService.deleteFormula(e,t,[m.id]),i.isFormulaString(n)){const f=this._registerSingleFormula(e,t,n,a);u[1]={text:n,id:f}}else u[1]=void 0}getRuleFormulaResult(e,t,a){const n=this._ensureRuleFormulaMap(e,t).get(a);if(!n)return Promise.resolve(null);const o=async l=>l&&this._registerOtherFormulaService.getFormulaValue(e,t,l.id);return Promise.all([o(n[0]),o(n[1])])}getRuleFormulaResultSync(e,t,a){const n=this._ensureRuleFormulaMap(e,t).get(a);if(n)return n.map(o=>{if(o)return this._registerOtherFormulaService.getFormulaValueSync(e,t,o.id)})}getRuleFormulaInfo(e,t,a){return this._ensureRuleFormulaMap(e,t).get(a)}};fe=We([ce(0,i.IUniverInstanceService),ce(1,i.Inject(Me.RegisterOtherFormulaService)),ce(2,i.Inject(ie)),ce(3,i.Inject(v.DataValidationModel))],fe);function me(s){return i.getOriginCellValue(s)}function Te(s){var e;return String((e=me(s))!=null?e:"")}const Pe=class ge{constructor(e,t){this.low=e,this.high=t}clone(){return new ge(this.low,this.high)}get max(){return this.clone()}less_than(e){return this.low<e.low||this.low===e.low&&this.high<e.high}equal_to(e){return this.low===e.low&&this.high===e.high}intersect(e){return!this.not_intersect(e)}not_intersect(e){return this.high<e.low||e.high<this.low}merge(e){return new ge(this.low===void 0?e.low:this.low<e.low?this.low:e.low,this.high===void 0?e.high:this.high>e.high?this.high:e.high)}output(){return[this.low,this.high]}static comparable_max(e,t){return e.merge(t)}static comparable_less_than(e,t){return e<t}},A=0,D=1;class J{constructor(e=void 0,t=void 0,a=null,r=null,n=null,o=D){if(this.left=a,this.right=r,this.parent=n,this.color=o,this.item={key:e,value:t},e&&e instanceof Array&&e.length===2&&!Number.isNaN(e[0])&&!Number.isNaN(e[1])){let[l,u]=e;l>u&&([l,u]=[u,l]),this.item.key=new Pe(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===D}_value_less_than(e){return this.item.value&&e.item.value&&this.item.value.less_than?this.item.value.less_than(e.item.value):this.item.value<e.item.value}less_than(e){return this.item.value===this.item.key&&e.item.value===e.item.key?this.item.key.less_than(e.item.key):this.item.key.less_than(e.item.key)||this.item.key.equal_to(e.item.key)&&this._value_less_than(e)}_value_equal(e){return this.item.value&&e.item.value&&this.item.value.equal_to?this.item.value.equal_to(e.item.value):this.item.value===e.item.value}equal_to(e){return this.item.value===this.item.key&&e.item.value===e.item.key?this.item.key.equal_to(e.item.key):this.item.key.equal_to(e.item.key)&&this._value_equal(e)}intersect(e){return this.item.key.intersect(e.item.key)}copy_data(e){this.item.key=e.item.key,this.item.value=e.item.value}update_max(){if(this.max=this.item.key?this.item.key.max:void 0,this.right&&this.right.max){const e=this.item.key.constructor.comparable_max;this.max=e(this.max,this.right.max)}if(this.left&&this.left.max){const e=this.item.key.constructor.comparable_max;this.max=e(this.max,this.left.max)}}not_intersect_left_subtree(e){const t=this.item.key.constructor.comparable_less_than;let a=this.left.max.high!==void 0?this.left.max.high:this.left.max;return t(a,e.item.key.low)}not_intersect_right_subtree(e){const t=this.item.key.constructor.comparable_less_than;let a=this.right.max.low!==void 0?this.right.max.low:this.right.item.key.low;return t(e.item.key.high,a)}}class ve{constructor(){this.root=null,this.nil_node=new J}get size(){let e=0;return this.tree_walk(this.root,()=>e++),e}get keys(){let e=[];return this.tree_walk(this.root,t=>e.push(t.item.key.output?t.item.key.output():t.item.key)),e}get values(){let e=[];return this.tree_walk(this.root,t=>e.push(t.item.value)),e}get items(){let e=[];return this.tree_walk(this.root,t=>e.push({key:t.item.key.output?t.item.key.output():t.item.key,value:t.item.value})),e}isEmpty(){return this.root==null||this.root===this.nil_node}clear(){this.root=null}insert(e,t=e){if(e===void 0)return;let a=new J(e,t,this.nil_node,this.nil_node,null,A);return this.tree_insert(a),this.recalc_max(a),a}exist(e,t=e){let a=new J(e,t);return!!this.tree_search(this.root,a)}remove(e,t=e){let a=new J(e,t),r=this.tree_search(this.root,a);return r&&this.tree_delete(r),r}search(e,t=(a,r)=>a===r?r.output():a){let a=new J(e),r=[];return this.tree_search_interval(this.root,a,r),r.map(n=>t(n.item.value,n.item.key))}intersect_any(e){let t=new J(e);return this.tree_find_any_interval(this.root,t)}forEach(e){this.tree_walk(this.root,t=>e(t.item.key,t.item.value))}map(e){const t=new ve;return this.tree_walk(this.root,a=>t.insert(a.item.key,e(a.item.value,a.item.key))),t}*iterate(e,t=(a,r)=>a===r?r.output():a){let a;for(e?a=this.tree_search_nearest_forward(this.root,new J(e)):this.root&&(a=this.local_minimum(this.root));a;)yield t(a.item.value,a.item.key),a=this.tree_successor(a)}recalc_max(e){let t=e;for(;t.parent!=null;)t.parent.update_max(),t=t.parent}tree_insert(e){let t=this.root,a=null;if(this.root==null||this.root===this.nil_node)this.root=e;else{for(;t!==this.nil_node;)a=t,e.less_than(t)?t=t.left:t=t.right;e.parent=a,e.less_than(a)?a.left=e:a.right=e}this.insert_fixup(e)}insert_fixup(e){let t,a;for(t=e;t!==this.root&&t.parent.color===A;)t.parent===t.parent.parent.left?(a=t.parent.parent.right,a.color===A?(t.parent.color=D,a.color=D,t.parent.parent.color=A,t=t.parent.parent):(t===t.parent.right&&(t=t.parent,this.rotate_left(t)),t.parent.color=D,t.parent.parent.color=A,this.rotate_right(t.parent.parent))):(a=t.parent.parent.left,a.color===A?(t.parent.color=D,a.color=D,t.parent.parent.color=A,t=t.parent.parent):(t===t.parent.left&&(t=t.parent,this.rotate_right(t)),t.parent.color=D,t.parent.parent.color=A,this.rotate_left(t.parent.parent)));this.root.color=D}tree_delete(e){let t,a;e.left===this.nil_node||e.right===this.nil_node?t=e:t=this.tree_successor(e),t.left!==this.nil_node?a=t.left:a=t.right,a.parent=t.parent,t===this.root?this.root=a:(t===t.parent.left?t.parent.left=a:t.parent.right=a,t.parent.update_max()),this.recalc_max(a),t!==e&&(e.copy_data(t),e.update_max(),this.recalc_max(e)),t.color===D&&this.delete_fixup(a)}delete_fixup(e){let t=e,a;for(;t!==this.root&&t.parent!=null&&t.color===D;)t===t.parent.left?(a=t.parent.right,a.color===A&&(a.color=D,t.parent.color=A,this.rotate_left(t.parent),a=t.parent.right),a.left.color===D&&a.right.color===D?(a.color=A,t=t.parent):(a.right.color===D&&(a.color=A,a.left.color=D,this.rotate_right(a),a=t.parent.right),a.color=t.parent.color,t.parent.color=D,a.right.color=D,this.rotate_left(t.parent),t=this.root)):(a=t.parent.left,a.color===A&&(a.color=D,t.parent.color=A,this.rotate_right(t.parent),a=t.parent.left),a.left.color===D&&a.right.color===D?(a.color=A,t=t.parent):(a.left.color===D&&(a.color=A,a.right.color=D,this.rotate_left(a),a=t.parent.left),a.color=t.parent.color,t.parent.color=D,a.left.color=D,this.rotate_right(t.parent),t=this.root));t.color=D}tree_search(e,t){if(!(e==null||e===this.nil_node))return t.equal_to(e)?e:t.less_than(e)?this.tree_search(e.left,t):this.tree_search(e.right,t)}tree_search_nearest_forward(e,t){let a,r=e;for(;r&&r!==this.nil_node;)r.less_than(t)?r.intersect(t)?(a=r,r=r.left):r=r.right:((!a||r.less_than(a))&&(a=r),r=r.left);return a||null}tree_search_interval(e,t,a){e!=null&&e!==this.nil_node&&(e.left!==this.nil_node&&!e.not_intersect_left_subtree(t)&&this.tree_search_interval(e.left,t,a),e.intersect(t)&&a.push(e),e.right!==this.nil_node&&!e.not_intersect_right_subtree(t)&&this.tree_search_interval(e.right,t,a))}tree_find_any_interval(e,t){let a=!1;return e!=null&&e!==this.nil_node&&(e.left!==this.nil_node&&!e.not_intersect_left_subtree(t)&&(a=this.tree_find_any_interval(e.left,t)),a||(a=e.intersect(t)),!a&&e.right!==this.nil_node&&!e.not_intersect_right_subtree(t)&&(a=this.tree_find_any_interval(e.right,t))),a}local_minimum(e){let t=e;for(;t.left!=null&&t.left!==this.nil_node;)t=t.left;return t}local_maximum(e){let t=e;for(;t.right!=null&&t.right!==this.nil_node;)t=t.right;return t}tree_successor(e){let t,a,r;if(e.right!==this.nil_node)t=this.local_minimum(e.right);else{for(a=e,r=e.parent;r!=null&&r.right===a;)a=r,r=r.parent;t=r}return t}rotate_left(e){let t=e.right;e.right=t.left,t.left!==this.nil_node&&(t.left.parent=e),t.parent=e.parent,e===this.root?this.root=t:e===e.parent.left?e.parent.left=t:e.parent.right=t,t.left=e,e.parent=t,e!=null&&e!==this.nil_node&&e.update_max(),t=e.parent,t!=null&&t!==this.nil_node&&t.update_max()}rotate_right(e){let t=e.left;e.left=t.right,t.right!==this.nil_node&&(t.right.parent=e),t.parent=e.parent,e===this.root?this.root=t:e===e.parent.left?e.parent.left=t:e.parent.right=t,t.right=e,e.parent=t,e!==null&&e!==this.nil_node&&e.update_max(),t=e.parent,t!=null&&t!==this.nil_node&&t.update_max()}tree_walk(e,t){e!=null&&e!==this.nil_node&&(this.tree_walk(e.left,t),t(e),this.tree_walk(e.right,t))}testRedBlackProperty(){let e=!0;return this.tree_walk(this.root,function(t){t.color===A&&(t.left.color===D&&t.right.color===D||(e=!1))}),e}testBlackHeightProperty(e){let t=0,a=0,r=0;if(e.color===D&&t++,e.left!==this.nil_node?a=this.testBlackHeightProperty(e.left):a=1,e.right!==this.nil_node?r=this.testBlackHeightProperty(e.right):r=1,a!==r)throw new Error("Red-black height property violated");return t+=a,t}}class Re{constructor(e,t,a,r,n=!1){b(this,"_map");b(this,"_tree",new Map);b(this,"_dirty",!0);b(this,"_buildTree",()=>{if(!this._dirty||this._disableTree)return;const e=new Map;this._map.forEach((a,r)=>{a.forEach(n=>{for(let o=n.startColumn;o<=n.endColumn;o++){let l=e.get(o);l||(l=[],e.set(o,l)),l.push({startRow:n.startRow,endRow:n.endRow,ruleId:r})}})});const t=new Map;e.forEach((a,r)=>{const n=new ve;a.forEach(o=>{n.insert([o.startRow,o.endRow],o.ruleId)}),t.set(r,n)}),this._tree=t,this._dirty=!1});b(this,"_debonceBuildTree",i.debounce(this._buildTree,0));this._unitId=t,this._subUnitId=a,this._univerInstanceService=r,this._disableTree=n,this._map=e,this._buildTree()}get _worksheet(){var e;return(e=this._univerInstanceService.getUnit(this._unitId,i.UniverInstanceType.UNIVER_SHEET))==null?void 0:e.getSheetBySheetId(this._subUnitId)}addRule(e){if(!this._worksheet)return;const t=e.uid,a=e.ranges.map(r=>i.Range.transformRange(r,this._worksheet));this._map.forEach((r,n)=>{const o=i.Rectangle.subtractMulti(r,a);o.length===0?this._map.delete(n):this._map.set(n,o)}),this._dirty=!0,this._map.set(t,a),this._debonceBuildTree()}removeRange(e){if(!this._worksheet)return;const t=e.map(a=>i.Range.transformRange(a,this._worksheet));this._map.forEach((a,r)=>{const n=i.Rectangle.subtractMulti(a,t);n.length===0?this._map.delete(r):this._map.set(r,n)}),this._dirty=!0,this._debonceBuildTree()}removeRule(e){this._map.delete(e.uid),this._dirty=!0,this._debonceBuildTree()}updateRange(e,t){if(!this._worksheet)return;this._map.delete(e);const a=t.map(r=>i.Range.transformRange(r,this._worksheet));this._map.forEach((r,n)=>{const o=i.Rectangle.subtractMulti(r,a);o.length===0?this._map.delete(n):this._map.set(n,o)}),this._map.set(e,a),this._dirty=!0,this._debonceBuildTree()}addRangeRules(e){e.forEach(({id:t,ranges:a})=>{if(!a.length)return;let r=this._map.get(t);r?(this._map.set(t,i.Rectangle.mergeRanges([...r,...a])),r=this._map.get(t)):(r=a,this._map.set(t,r)),this._map.forEach((n,o)=>{if(o===t)return;const l=i.Rectangle.subtractMulti(n,a);l.length===0?this._map.delete(o):this._map.set(o,l)})}),this._dirty=!0,this._debonceBuildTree()}diff(e){const t=[];let a=0;return e.forEach((r,n)=>{var u;const o=(u=this._map.get(r.uid))!=null?u:[],l=r.ranges;o.length!==0&&(o.length!==l.length||o.some((h,m)=>!i.Rectangle.equals(h,l[m])))&&t.push({type:"update",ruleId:r.uid,oldRanges:l,newRanges:i.Rectangle.sort(o),rule:r}),o.length===0&&(t.push({type:"delete",rule:r,index:n-a}),a++)}),t}diffWithAddition(e,t){const a=[];let r=0;return e.forEach((n,o)=>{var h;const l=(h=this._map.get(n.uid))!=null?h:[],u=n.ranges;l.length!==0&&(l.length!==u.length||l.some((m,f)=>!i.Rectangle.equals(m,u[f])))&&a.push({type:"update",ruleId:n.uid,oldRanges:u,newRanges:i.Rectangle.sort(l),rule:n}),l.length===0&&(a.push({type:"delete",rule:n,index:o-r}),r++)}),Array.from(t).forEach(n=>{var l;const o=(l=this._map.get(n.uid))!=null?l:[];a.push({type:"add",rule:{...n,ranges:i.Rectangle.sort(o)}})}),a}clone(){return new Re(new Map(i.Tools.deepClone(Array.from(this._map.entries()))),this._unitId,this._subUnitId,this._univerInstanceService,!0)}getValue(e,t){this._dirty&&this._buildTree();const a=this._tree.get(t);if(!a)return;const r=a.search([e,e]);return r.length>0?r[0]:void 0}}var Ge=Object.defineProperty,Qe=Object.getOwnPropertyDescriptor,Ye=(s,e,t,a)=>{for(var r=a>1?void 0:a?Qe(e,t):e,n=s.length-1,o;n>=0;n--)(o=s[n])&&(r=(a?o(e,t,r):o(r))||r);return a&&r&&Ge(e,t,r),r},Z=(s,e)=>(t,a)=>e(t,a,s);let j=class extends i.Disposable{constructor(e,t,a,r,n,o,l){super();b(this,"_ruleMatrixMap",new Map);b(this,"_validStatusChange$",new Y.Subject);b(this,"_ruleChange$",new Y.Subject);b(this,"ruleChange$",this._ruleChange$.asObservable());b(this,"validStatusChange$",this._validStatusChange$.asObservable());this._dataValidationModel=e,this._univerInstanceService=t,this._dataValidatorRegistryService=a,this._dataValidationCacheService=r,this._dataValidationFormulaService=n,this._dataValidationCustomFormulaService=o,this._commandService=l,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===W.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 o of n)this._addRule(t,r,o),this._ruleChange$.next({type:"add",unitId:t,subUnitId:r,rule:o,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 Re(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.uid,a.formula1,a.formula2,a.ranges),a.type===i.DataValidationType.CUSTOM&&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 o=this._ensureRuleMatrix(e,t);n.type===v.UpdateRuleType.RANGE?(o.updateRange(a,n.payload),this._dataValidationCacheService.updateRuleRanges(e,t,a,n.payload,r.ranges),r.type===i.DataValidationType.CUSTOM&&(this._dataValidationCustomFormulaService.deleteByRuleId(e,t,a),this._dataValidationCustomFormulaService.addRule(e,t,{...r,ranges:n.payload}))):n.type===v.UpdateRuleType.SETTING&&(this._dataValidationCacheService.markRangeDirty(e,t,r.ranges),this._dataValidationFormulaService.updateRuleFormulaText(e,t,a,n.payload.formula1,n.payload.formula2,r.ranges),r.type===i.DataValidationType.CUSTOM?(this._dataValidationCustomFormulaService.deleteByRuleId(e,t,a),this._dataValidationCustomFormulaService.addRule(e,t,{...r,...n.payload})):n.payload.type===i.DataValidationType.CUSTOM&&this._dataValidationCustomFormulaService.addRule(e,t,{...r,...n.payload}))}_removeRule(e,t,a){this._ensureRuleMatrix(e,t).removeRule(a),this._dataValidationCacheService.removeRule(e,t,a),a.type===i.DataValidationType.CUSTOM&&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:o,subUnitId:l,worksheet:u}=t,h=e.uid,m=e.formula1,f=e.formula2,M=(x,w)=>{a&&a(x,w),w&&this._validStatusChange$.next({unitId:o,subUnitId:l,ruleId:e.uid,status:x,row:n,col:r})},E=u.getCellValueOnly(n,r),C=this.getValidator(e.type),B=u.getCellRaw(n,r),q=me(B),S=me(E);if(C){const x=this._dataValidationCacheService.ensureCache(o,l),w=x.getValue(n,r);return!w||w.value!==q||w.interceptValue!==S||w.ruleId!==h||w.formula1!==m||w.formula2!==f?(x.setValue(n,r,{value:q,interceptValue:S,status:i.DataValidationStatus.VALIDATING,ruleId:h,formula1:m||"",formula2:f||""}),C.validator({value:q,unitId:o,subUnitId:l,row:n,column:r,worksheet:t.worksheet,workbook:t.workbook,interceptValue:me(E),t:B==null?void 0:B.t},e).then(L=>{const k=L?i.DataValidationStatus.VALID:i.DataValidationStatus.INVALID;x.setValue(n,r,{value:q,status:k,ruleId:h,interceptValue:S,formula1:m||"",formula2:f||""}),M(k,!0)}),i.DataValidationStatus.VALIDATING):(M(w.status,!1),w.status)}else return M(i.DataValidationStatus.VALID,!1),i.DataValidationStatus.VALID}getRuleErrorMsg(e,t,a){const r=this._dataValidationModel.getRuleById(e,t,a);if(!r)return"";const n=this._dataValidatorRegistryService.getValidatorItem(r.type);return r.error?r.error:n?n.getRuleFinalError(r):""}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()}};j=Ye([Z(0,i.Inject(v.DataValidationModel)),Z(1,i.IUniverInstanceService),Z(2,i.Inject(v.DataValidatorRegistryService)),Z(3,i.Inject(ie)),Z(4,i.Inject(fe)),Z(5,i.Inject(_e)),Z(6,i.ICommandService)],j);const Se=1,ye=0;var Ke=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},Xe={exports:{}};(function(s,e){(function(t,a){s.exports=a()})(Ke,function(){var t=1e3,a=6e4,r=36e5,n="millisecond",o="second",l="minute",u="hour",h="day",m="week",f="month",M="quarter",E="year",C="date",B="Invalid Date",q=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,S=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,x={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(g){var c=["th","st","nd","rd"],d=g%100;return"["+g+(c[(d-20)%10]||c[d]||c[0])+"]"}},w=function(g,c,d){var _=String(g);return!_||_.length>=c?g:""+Array(c+1-_.length).join(d)+g},L={s:w,z:function(g){var c=-g.utcOffset(),d=Math.abs(c),_=Math.floor(d/60),p=d%60;return(c<=0?"+":"-")+w(_,2,"0")+":"+w(p,2,"0")},m:function g(c,d){if(c.date()<d.date())return-g(d,c);var _=12*(d.year()-c.year())+(d.month()-c.month()),p=c.clone().add(_,f),R=d-p<0,V=c.clone().add(_+(R?-1:1),f);return+(-(_+(d-p)/(R?p-V:V-p))||0)},a:function(g){return g<0?Math.ceil(g)||0:Math.floor(g)},p:function(g){return{M:f,y:E,w:m,d:h,D:C,h:u,m:l,s:o,ms:n,Q:M}[g]||String(g||"").toLowerCase().replace(/s$/,"")},u:function(g){return g===void 0}},k="en",F={};F[k]=x;var G="$isDayjsObject",K=function(g){return g instanceof ae||!(!g||!g[G])},P=function g(c,d,_){var p;if(!c)return k;if(typeof c=="string"){var R=c.toLowerCase();F[R]&&(p=R),d&&(F[R]=d,p=R);var V=c.split("-");if(!p&&V.length>1)return g(V[0])}else{var T=c.name;F[T]=c,p=T}return!_&&p&&(k=p),p||!_&&k},I=function(g,c){if(K(g))return g.clone();var d=typeof c=="object"?c:{};return d.date=g,d.args=arguments,new ae(d)},y=L;y.l=P,y.i=K,y.w=function(g,c){return I(g,{locale:c.$L,utc:c.$u,x:c.$x,$offset:c.$offset})};var ae=function(){function g(d){this.$L=P(d.locale,null,!0),this.parse(d),this.$x=this.$x||d.x||{},this[G]=!0}var c=g.prototype;return c.parse=function(d){this.$d=function(_){var p=_.date,R=_.utc;if(p===null)return new Date(NaN);if(y.u(p))return new Date;if(p instanceof Date)return new Date(p);if(typeof p=="string"&&!/Z$/i.test(p)){var V=p.match(q);if(V){var T=V[2]-1||0,O=(V[7]||"0").substring(0,3);return R?new Date(Date.UTC(V[1],T,V[3]||1,V[4]||0,V[5]||0,V[6]||0,O)):new Date(V[1],T,V[3]||1,V[4]||0,V[5]||0,V[6]||0,O)}}return new Date(p)}(d),this.init()},c.init=function(){var d=this.$d;this.$y=d.getFullYear(),this.$M=d.getMonth(),this.$D=d.getDate(),this.$W=d.getDay(),this.$H=d.getHours(),this.$m=d.getMinutes(),this.$s=d.getSeconds(),this.$ms=d.getMilliseconds()},c.$utils=function(){return y},c.isValid=function(){return this.$d.toString()!==B},c.isSame=function(d,_){var p=I(d);return this.startOf(_)<=p&&p<=this.endOf(_)},c.isAfter=function(d,_){return I(d)<this.startOf(_)},c.isBefore=function(d,_){return this.endOf(_)<I(d)},c.$g=function(d,_,p){return y.u(d)?this[_]:this.set(p,d)},c.unix=function(){return Math.floor(this.valueOf()/1e3)},c.valueOf=function(){return this.$d.getTime()},c.startOf=function(d,_){var p=this,R=!!y.u(_)||_,V=y.p(d),T=function(z,N){var Q=y.w(p.$u?Date.UTC(p.$y,N,z):new Date(p.$y,N,z),p);return R?Q:Q.endOf(h)},O=function(z,N){return y.w(p.toDate()[z].apply(p.toDate("s"),(R?[0,0,0,0]:[23,59,59,999]).slice(N)),p)},$=this.$W,U=this.$M,H=this.$D,re="set"+(this.$u?"UTC":"");switch(V){case E:return R?T(1,0):T(31,11);case f:return R?T(1,U):T(0,U+1);case m:var X=this.$locale().weekStart||0,ne=($<X?$+7:$)-X;return T(R?H-ne:H+(6-ne),U);case h:case C:return O(re+"Hours",0);case u:return O(re+"Minutes",1);case l:return O(re+"Seconds",2);case o:return O(re+"Milliseconds",3);default:return this.clone()}},c.endOf=function(d){return this.startOf(d,!1)},c.$set=function(d,_){var p,R=y.p(d),V="set"+(this.$u?"UTC":""),T=(p={},p[h]=V+"Date",p[C]=V+"Date",p[f]=V+"Month",p[E]=V+"FullYear",p[u]=V+"Hours",p[l]=V+"Minutes",p[o]=V+"Seconds",p[n]=V+"Milliseconds",p)[R],O=R===h?this.$D+(_-this.$W):_;if(R===f||R===E){var $=this.clone().set(C,1);$.$d[T](O),$.init(),this.$d=$.set(C,Math.min(this.$D,$.daysInMonth())).$d}else T&&this.$d[T](O);return this.init(),this},c.set=function(d,_){return this.clone().$set(d,_)},c.get=function(d){return this[y.p(d)]()},c.add=function(d,_){var p,R=this;d=Number(d);var V=y.p(_),T=function(U){var H=I(R);return y.w(H.date(H.date()+Math.round(U*d)),R)};if(V===f)return this.set(f,this.$M+d);if(V===E)return this.set(E,this.$y+d);if(V===h)return T(1);if(V===m)return T(7);var O=(p={},p[l]=a,p[u]=r,p[o]=t,p)[V]||1,$=this.$d.getTime()+d*O;return y.w($,this)},c.subtract=function(d,_){return this.add(-1*d,_)},c.format=function(d){var _=this,p=this.$locale();if(!this.isValid())return p.invalidDate||B;var R=d||"YYYY-MM-DDTHH:mm:ssZ",V=y.z(this),T=this.$H,O=this.$m,$=this.$M,U=p.weekdays,H=p.months,re=p.meridiem,X=function(N,Q,oe,de){return N&&(N[Q]||N(_,R))||oe[Q].slice(0,de)},ne=function(N){return y.s(T%12||12,N,"0")},z=re||function(N,Q,oe){var de=N<12?"AM":"PM";return oe?de.toLowerCase():de};return R.replace(S,function(N,Q){return Q||function(oe){switch(oe){case"YY":return String(_.$y).slice(-2);case"YYYY":return y.s(_.$y,4,"0");case"M":return $+1;case"MM":return y.s($+1,2,"0");case"MMM":return X(p.monthsShort,$,H,3);case"MMMM":return X(H,$);case"D":return _.$D;case"DD":return y.s(_.$D,2,"0");case"d":return String(_.$W);case"dd":return X(p.weekdaysMin,_.$W,U,2);case"ddd":return X(p.weekdaysShort,_.$W,U,3);case"dddd":return U[_.$W];case"H":return String(T);case"HH":return y.s(T,2,"0");case"h":return ne(1);case"hh":return ne(2);case"a":return z(T,O,!0);case"A":return z(T,O,!1);case"m":return String(O);case"mm":return y.s(O,2,"0");case"s":return String(_.$s);case"ss":return y.s(_.$s,2,"0");case"SSS":return y.s(_.$ms,3,"0");case"Z":return V}return null}(N)||V.replace(":","")})},c.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},c.diff=function(d,_,p){var R,V=this,T=y.p(_),O=I(d),$=(O.utcOffset()-this.utcOffset())*a,U=this-O,H=function(){return y.m(V,O)};switch(T){case E:R=H()/12;break;case f:R=H();break;case M:R=H()/3;break;case m:R=(U-$)/6048e5;break;case h:R=(U-$)/864e5;break;case u:R=U/r;break;case l:R=U/a;break;case o:R=U/t;break;default:R=U}return p?R:y.a(R)},c.daysInMonth=function(){return this.endOf(f).$D},c.$locale=function(){return F[this.$L]},c.locale=function(d,_){if(!d)return this.$L;var p=this.clone(),R=P(d,_,!0);return R&&(p.$L=R),p},c.clone=function(){return y.w(this.$d,this)},c.toDate=function(){return new Date(this.valueOf())},c.toJSON=function(){return this.isValid()?this.toISOString():null},c.toISOString=function(){return this.$d.toISOString()},c.toString=function(){return this.$d.toUTCString()},g}(),ue=ae.prototype;return I.prototype=ue,[["$ms",n],["$s",o],["$m",l],["$H",u],["$W",h],["$M",f],["$y",E],["$D",C]].forEach(function(g){ue[g[1]]=function(c){return this.$g(c,g[0],g[1])}}),I.extend=function(g,c){return g.$i||(g(c,ae,I),g.$i=!0),I},I.locale=P,I.isDayjs=K,I.unix=function(g){return I(1e3*g)},I.en=F[k],I.Ls=F,I.p={},I})})(Xe);i.DataValidationOperator.BETWEEN+"",i.DataValidationOperator.EQUAL+"",i.DataValidationOperator.GREATER_THAN+"",i.DataValidationOperator.GREATER_THAN_OR_EQUAL+"",i.DataValidationOperator.LESS_THAN+"",i.DataValidationOperator.LESS_THAN_OR_EQUAL+"",i.DataValidationOperator.NOT_BETWEEN+"",i.DataValidationOperator.NOT_EQUAL+"";i.DataValidationOperator.BETWEEN+"",i.DataValidationOperator.EQUAL+"",i.DataValidationOperator.GREATER_THAN+"",i.DataValidationOperator.GREATER_THAN_OR_EQUAL+"",i.DataValidationOperator.LESS_THAN+"",i.DataValidationOperator.LESS_THAN_OR_EQUAL+"",i.DataValidationOperator.NOT_BETWEEN+"",i.DataValidationOperator.NOT_EQUAL+"";i.DataValidationOperator.BETWEEN+"",i.DataValidationOperator.EQUAL+"",i.DataValidationOperator.GREATER_THAN+"",i.DataValidationOperator.GREATER_THAN_OR_EQUAL+"",i.DataValidationOperator.LESS_THAN+"",i.DataValidationOperator.LESS_THAN_OR_EQUAL+"",i.DataValidationOperator.NOT_BETWEEN+"",i.DataValidationOperator.NOT_EQUAL+"";i.DataValidationOperator.BETWEEN+"",i.DataValidationOperator.EQUAL+"",i.DataValidationOperator.GREATER_THAN+"",i.DataValidationOperator.GREATER_THAN_OR_EQUAL+"",i.DataValidationOperator.LESS_THAN+"",i.DataValidationOperator.LESS_THAN_OR_EQUAL+"",i.DataValidationOperator.NOT_BETWEEN+"",i.DataValidationOperator.NOT_EQUAL+"";i.DataValidationOperator.BETWEEN,i.DataValidationOperator.NOT_BETWEEN;function Ee(s){var t,a;return s?s.p?!((a=(t=s.p.body)==null?void 0:t.dataStream)!=null?a:"").slice(0,-2).trim():i.Tools.isBlank(s.v):!0}function Ve(s,e,t,a,r="command",n=!0){const o=a.get(De.LexerTreeBuilder),l=[],u=[],h=a.get(j),m=a.get(i.IUniverInstanceService),f=W.getSheetCommandTarget(m,{unitId:s,subUnitId:e});if(!f)return{redoMutations:l,undoMutations:u};const{worksheet:M}=f,E=new i.ObjectMatrix;function C(S,x){n&&S.forEach(w=>{i.Range.foreach(w,(L,k)=>{const F=M.getCellRaw(L,k),G=Te(F);(Ee(F)||G===x)&&E.setValue(L,k,{v:x,p:null})})})}t.forEach(S=>{switch(S.type){case"delete":l.push({id:v.RemoveDataValidationMutation.id,params:{unitId:s,subUnitId:e,ruleId:S.rule.uid,source:r}}),u.unshift({id:v.AddDataValidationMutation.id,params:{unitId:s,subUnitId:e,rule:S.rule,index:S.index,source:r}});break;case"update":{if(l.push({id:v.UpdateDataValidationMutation.id,params:{unitId:s,subUnitId:e,ruleId:S.ruleId,payload:{type:v.UpdateRuleType.RANGE,payload:S.newRanges},source:r}}),u.unshift({id:v.UpdateDataValidationMutation.id,params:{unitId:s,subUnitId:e,ruleId:S.ruleId,payload:{type:v.UpdateRuleType.RANGE,payload:S.oldRanges},source:r}}),S.rule.type===i.DataValidationType.CUSTOM){const w=S.oldRanges[0].startRow,L=S.oldRanges[0].startColumn,k=S.newRanges[0].startRow,F=S.newRanges[0].startColumn,G=k-w,K=F-L,P=o.moveFormulaRefOffset(S.rule.formula1,K,G);P!==S.rule.formula1&&(l.push({id:v.UpdateDataValidationMutation.id,params:{unitId:s,subUnitId:e,ruleId:S.ruleId,payload:{type:v.UpdateRuleType.SETTING,payload:{...v.getRuleSetting(S.rule),formula1:P}}}}),u.unshift({id:v.UpdateDataValidationMutation.id,params:{unitId:s,subUnitId:e,ruleId:S.ruleId,payload:{type:v.UpdateRuleType.SETTING,payload:v.getRuleSetting(S.rule)}}}))}const x=h.getRuleById(s,e,S.ruleId);if(x&&x.type===i.DataValidationType.CHECKBOX){const L=h.getValidator(i.DataValidationType.CHECKBOX).parseFormulaSync(x,s,e);C(S.newRanges,L.formula2)}break}case"add":{if(l.push({id:v.AddDataValidationMutation.id,params:{unitId:s,subUnitId:e,rule:S.rule,source:r}}),u.unshift({id:v.RemoveDataValidationMutation.id,params:{unitId:s,subUnitId:e,ruleId:S.rule.uid,source:r}}),S.rule.type===i.DataValidationType.CHECKBOX){const w=h.getValidator(i.DataValidationType.CHECKBOX).parseFormulaSync(S.rule,s,e);C(S.rule.ranges,w.originFormula2)}break}}});const B={id:W.SetRangeValuesMutation.id,params:{unitId:s,subUnitId:e,cellValue:E.getData()}},q={id:W.SetRangeValuesMutation.id,params:W.SetRangeValuesUndoMutationFactory(a,B.params)};return l.push(B),u.push(q),{redoMutations:l,undoMutations:u}}const we={type:i.CommandType.COMMAND,id:"sheet.command.updateDataValidationRuleRange",handler(s,e){if(!e)return!1;const{unitId:t,subUnitId:a,ranges:r,ruleId:n}=e,o=s.get(j),l=s.get(i.ICommandService),u=s.get(i.IUndoRedoService);if(!o.getRuleById(t,a,n))return!1;const m=o.getRuleObjectMatrix(t,a).clone();m.updateRange(n,r);const f=m.diff(o.getRules(t,a)),{redoMutations:M,undoMutations:E}=Ve(t,a,f,s);return u.pushUndoRedo({undoMutations:E,redoMutations:M,unitID:t}),i.sequenceExecute(M,l),!0}},Oe={type:i.CommandType.COMMAND,id:"sheet.command.addDataValidation",handler(s,e){if(!e)return!1;const{unitId:t,subUnitId:a,rule:r}=e,n=s.get(j),o=s.get(i.ICommandService),l=s.get(i.IUndoRedoService),u=n.getRuleObjectMatrix(t,a).clone();u.addRule(r);const h=u.diff(n.getRules(t,a)),m={unitId:t,subUnitId:a,rule:r},{redoMutations:f,undoMutations:M}=Ve(t,a,h,s);return f.push({id:v.AddDataValidationMutation.id,params:m}),M.unshift({id:v.RemoveDataValidationMutation.id,params:{unitId:t,subUnitId:a,ruleId:r.uid}}),l.pushUndoRedo({unitID:t,redoMutations:f,undoMutations:M}),i.sequenceExecute(f,o),!0}},Ie={type:i.CommandType.COMMAND,id:"sheets.command.update-data-validation-setting",handler(s,e){if(!e)return!1;const t=s.get(i.ICommandService),a=s.get(i.IUndoRedoService),r=s.get(j),n=s.get(v.DataValidatorRegistryService),{unitId:o,subUnitId:l,ruleId:u,setting:h}=e,m=n.getValidatorItem(h.type);if(!m)return!1;const f=r.getRuleById(o,l,u);if(!f)return!1;const M={...f,...h};if(!m.validatorFormula(M,o,l).success)return!1;const E={unitId:o,subUnitId:l,ruleId:u,payload:{type:v.UpdateRuleType.SETTING,payload:{...h,...m.normalizeFormula(M,o,l)}}},C=[{id:v.UpdateDataValidationMutation.id,params:E}],B={unitId:o,subUnitId:l,ruleId:u,payload:{type:v.UpdateRuleType.SETTING,payload:v.getRuleSetting(f)}},q=[{id:v.UpdateDataValidationMutation.id,params:B}];if(h.type===i.DataValidationType.CHECKBOX){const x=f.ranges,w=s.get(i.IUniverInstanceService),L=W.getSheetCommandTarget(w,{unitId:o,subUnitId:l});if(L){const k=new i.ObjectMatrix,{worksheet:F}=L,{formula2:G=ye,formula1:K=Se}=f,{formula2:P=ye,formula1:I=Se}=h;x.forEach(ue=>{i.Range.foreach(ue,(g,c)=>{const d=F.getCellRaw(g,c),_=Te(d);Ee(d)||_===String(G)?k.setValue(g,c,{v:P,p:null}):_===String(K)&&k.setValue(g,c,{v:I,p:null})})});const y={id:W.SetRangeValuesMutation.id,params:{unitId:o,subUnitId:l,cellValue:k.getData()}},ae={id:W.SetRangeValuesMutation.id,params:W.SetRangeValuesUndoMutationFactory(s,y.params)};C.push(y),q.push(ae)}}return i.sequenceExecute(C,t).result?(a.pushUndoRedo({unitID:o,redoMutations:C,undoMutations:q}),!0):!1}},Ce={type:i.CommandType.COMMAND,id:"sheets.command.update-data-validation-options",handler(s,e){if(!e)return!1;const t=s.get(i.ICommandService),a=s.get(i.IUndoRedoService),r=s.get(j),{unitId:n,subUnitId:o,ruleId:l,options:u}=e,h=r.getRuleById(n,o,l);if(!h)return!1;const m={unitId:n,subUnitId:o,ruleId:l,payload:{type:v.UpdateRuleType.OPTIONS,payload:u}},f=[{id:v.UpdateDataValidationMutation.id,params:m}],M={unitId:n,subUnitId:o,ruleId:l,payload:{type:v.UpdateRuleType.OPTIONS,payload:v.getRuleOptions(h)}},E=[{id:v.UpdateDataValidationMutation.id,params:M}];return a.pushUndoRedo({unitID:n,redoMutations:f,undoMutations:E}),t.executeCommand(v.UpdateDataValidationMutation.id,m),!0}},ze={type:i.CommandType.COMMAND,id:"sheets.command.clear-range-data-validation",handler(s,e){if(!e)return!1;const{unitId:t,subUnitId:a,ranges:r}=e,n=s.get(i.ICommandService),o=s.get(i.IUniverInstanceService),l=W.getSheetCommandTarget(o,{unitId:t,subUnitId:a}),u=s.get(j);if(!l)return!1;const h=s.get(i.IUndoRedoService),m=u.getRuleObjectMatrix(t,a).clone();m.removeRange(r);const f=m.diff(u.getRules(t,a)),{redoMutations:M,undoMutations:E}=Ve(t,a,f,s);return h.pushUndoRedo({unitID:t,redoMutations:M,undoMutations:E}),i.sequenceExecute(M,n).result}},Je={type:i.CommandType.COMMAND,id:"sheet.command.remove-all-data-validation",handler(s,e){if(!e)return!1;const{unitId:t,subUnitId:a}=e,r=s.get(i.ICommandService),n=s.get(j),o=s.get(i.IUndoRedoService),l=[...n.getRules(t,a)],u={unitId:t,subUnitId:a,ruleId:l.map(f=>f.uid)},h=[{id:v.RemoveDataValidationMutation.id,params:u}],m=[{id:v.AddDataValidationMutation.id,params:{unitId:t,subUnitId:a,rule:l}}];return o.pushUndoRedo({redoMutations:h,undoMutations:m,unitID:t}),r.executeCommand(v.RemoveDataValidationMutation.id,u),!0}},be={type:i.CommandType.COMMAND,id:"sheet.command.remove-data-validation-rule",handler(s,e){if(!e)return!1;const{unitId:t,subUnitId:a,ruleId:r}=e,n=s.get(i.ICommandService),o=s.get(i.IUndoRedoService),l=s.get(j),u=[{id:v.RemoveDataValidationMutation.id,params:e}],h=[{id:v.AddDataValidationMutation.id,params:{unitId:t,subUnitId:a,rule:{...l.getRuleById(t,a,r)},index:l.getRuleIndex(t,a,r)}}];return o.pushUndoRedo({undoMutations:h,redoMutations:u,unitID:e.unitId}),n.executeCommand(v.RemoveDataValidationMutation.id,e),!0}};var Ze=Object.defineProperty,et=Object.getOwnPropertyDescriptor,tt=(s,e,t,a)=>{for(var r=a>1?void 0:a?et(e,t):e,n=s.length-1,o;n>=0;n--)(o=s[n])&&(r=(a?o(e,t,r):o(r))||r);return a&&r&&Ze(e,t,r),r},pe=(s,e)=>(t,a)=>e(t,a,s);let ee=class extends i.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(i.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 o=this._univerInstanceService.getUnit(n.unitId,i.UniverInstanceType.UNIVER_SHEET),l=o==null?void 0:o.getSheetBySheetId(n.subUnitId);l&&r[n.unitId][n.subUnitId].push(...n.ranges.map(u=>i.Range.transformRange(u,l)))}),Object.entries(r).forEach(([n,o])=>{Object.entries(o).forEach(([l,u])=>{(t==null?void 0:t.getUnitId())===n&&(a==null?void 0:a.getSheetId())===l?this.validatorRanges(n,l,u):requestIdleCallback(()=>{this.validatorRanges(n,l,u)})})})};this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.pipe(Y.bufferWhen(()=>this._lifecycleService.lifecycle$.pipe(Y.filter(e=>e===i.LifecycleStages.Rendered)))).subscribe(s)),this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.pipe(Y.filter(()=>this._lifecycleService.stage>=i.LifecycleStages.Rendered),i.bufferDebounceTime(20)).subscribe(s))}async validatorCell(s,e,t,a){const r=this._univerInstanceService.getUnit(s,i.UniverInstanceType.UNIVER_SHEET);if(!r)throw new Error(`cannot find current workbook, unitId: ${s}`);const n=r.getSheetBySheetId(e);if(!n)throw new Error(`cannot find current worksheet, sheetId: ${e}`);if(!i.Tools.isDefine(t)||!i.Tools.isDefine(a))throw new Error(`row or col is not defined, row: ${t}, col: ${a}`);const o=this._sheetDataValidationModel.getRuleByLocation(s,e,t,a);return o?new Promise(l=>{this._sheetDataValidationModel.validator(o,{unitId:s,subUnitId:e,row:t,col:a,worksheet:n,workbook:r},u=>{l(u)})}):i.DataValidationStatus.VALID}validatorRanges(s,e,t){return Promise.all(t.map(a=>{const r=[];return i.Range.foreach(a,(n,o)=>{r.push(this.validatorCell(s,e,n,o))}),r}))}async validatorWorksheet(s,e){const t=this._sheetDataValidationModel.getRules(s,e);return await Promise.all(t.map(a=>Promise.all(a.ranges.map(r=>{const n=[];return i.Range.foreach(r,(o,l)=>{n.push(this.validatorCell(s,e,o,l))}),n})))),this._dataValidationCacheService.ensureCache(s,e)}async validatorWorkbook(s){const e=this._sheetDataValidationModel.getSubUnitIds(s),t=await Promise.all(e.map(r=>this.validatorWorksheet(s,r))),a={};return t.forEach((r,n)=>{a[e[n]]=r}),a}getDataValidations(s,e,t){const a=this._sheetDataValidationModel.getRuleObjectMatrix(s,e),r=new Set;return t.forEach(o=>{i.Range.foreach(o,(l,u)=>{const h=a.getValue(l,u);h&&r.add(h)})}),Array.from(r).map(o=>this._sheetDataValidationModel.getRuleById(s,e,o)).filter(Boolean)}getDataValidation(s,e,t){return this.getDataValidations(s,e,t)[0]}};ee=tt([pe(0,i.IUniverInstanceService),pe(1,i.Inject(j)),pe(2,i.Inject(ie)),pe(3,i.Inject(i.LifecycleService))],ee);class le{constructor(e){b(this,"_rule");this._rule=e!=null?e:{uid:i.generateRandomId(),ranges:void 0,type:i.DataValidationType.CUSTOM}}build(){return new se(this._rule)}copy(){return new le({...this._rule,uid:i.generateRandomId()})}getAllowInvalid(){return this._rule.errorStyle!==i.DataValidationErrorStyle.STOP}getCriteriaType(){return this._rule.type}getCriteriaValues(){return[this._rule.operator,this._rule.formula1,this._rule.formula2]}getHelpText(){return this._rule.error}requireCheckbox(e,t){return this._rule.type=i.DataValidationType.CHECKBOX,this._rule.formula1=e,this._rule.formula2=t,this}requireDateAfter(e){return this._rule.type=i.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.operator=i.DataValidationOperator.GREATER_THAN,this}requireDateBefore(e){return this._rule.type=i.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=i.DataValidationOperator.LESS_THAN,this}requireDateBetween(e,t){return this._rule.type=i.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=t.toLocaleDateString(),this._rule.operator=i.DataValidationOperator.BETWEEN,this}requireDateEqualTo(e){return this._rule.type=i.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=i.DataValidationOperator.EQUAL,this}requireDateNotBetween(e,t){return this._rule.type=i.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=t.toLocaleDateString(),this._rule.operator=i.DataValidationOperator.NOT_BETWEEN,this}requireDateOnOrAfter(e){return this._rule.type=i.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=i.DataValidationOperator.GREATER_THAN_OR_EQUAL,this}requireDateOnOrBefore(e){return this._rule.type=i.DataValidationType.DATE,this._rule.formula1=e.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=i.DataValidationOperator.LESS_THAN_OR_EQUAL,this}requireFormulaSatisfied(e){return this._rule.type=i.DataValidationType.CUSTOM,this._rule.formula1=e,this._rule.formula2=void 0,this}requireNumberBetween(e,t,a){return this._rule.formula1=`${e}`,this._rule.formula2=`${t}`,this._rule.operator=i.DataValidationOperator.BETWEEN,this._rule.type=a?i.DataValidationType.WHOLE:i.DataValidationType.DECIMAL,this}requireNumberEqualTo(e,t){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=i.DataValidationOperator.EQUAL,this._rule.type=t?i.DataValidationType.WHOLE:i.DataValidationType.DECIMAL,this}requireNumberGreaterThan(e,t){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=i.DataValidationOperator.GREATER_THAN,this._rule.type=t?i.DataValidationType.WHOLE:i.DataValidationType.DECIMAL,this}requireNumberGreaterThanOrEqualTo(e,t){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=i.DataValidationOperator.GREATER_THAN_OR_EQUAL,this._rule.type=t?i.DataValidationType.WHOLE:i.DataValidationType.DECIMAL,this}requireNumberLessThan(e,t){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=i.DataValidationOperator.LESS_THAN,this._rule.type=t?i.DataValidationType.WHOLE:i.DataValidationType.DECIMAL,this}requireNumberLessThanOrEqualTo(e,t){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=i.DataValidationOperator.LESS_THAN_OR_EQUAL,this._rule.type=t?i.DataValidationType.WHOLE:i.DataValidationType.DECIMAL,this}requireNumberNotBetween(e,t,a){return this._rule.formula1=`${e}`,this._rule.formula2=`${t}`,this._rule.operator=i.DataValidationOperator.NOT_BETWEEN,this._rule.type=a?i.DataValidationType.WHOLE:i.DataValidationType.DECIMAL,this}requireNumberNotEqualTo(e,t){return this._rule.formula1=`${e}`,this._rule.formula2=void 0,this._rule.operator=i.DataValidationOperator.NOT_EQUAL,this._rule.type=t?i.DataValidationType.WHOLE:i.DataValidationType.DECIMAL,this}requireValueInList(e,t,a){return this._rule.type=t?i.DataValidationType.LIST_MULTIPLE:i.DataValidationType.LIST,this._rule.formula1=e.join(","),this._rule.formula2=void 0,this._rule.showDropDown=a!=null?a:!0,this}requireValueInRange(e,t,a){return this._rule.type=t?i.DataValidationType.LIST_MULTIPLE:i.DataValidationType.LIST,this._rule.formula1=`=${De.serializeRangeToRefString({unitId:e.getUnitId(),sheetName:e.getSheetName(),range:e.getRange()})}`,this._rule.formula2=void 0,this._rule.showDropDown=a!=null?a:!0,this}setAllowInvalid(e){return this._rule.errorStyle=e?i.DataValidationErrorStyle.WARNING:i.DataValidationErrorStyle.STOP,this}setHelpText(e){return this._rule.error=e,this._rule.showErrorMessage=!0,this}withCriteriaValues(e,t){return this._rule.type=e,this._rule.operator=t[0],this._rule.formula1=t[1],this._rule.formula2=t[2],this}setOptions(e){return Object.assign(this._rule,e),this}}class se{constructor(e,t){b(this,"rule");b(this,"_worksheet");this.rule=e,this._worksheet=t}getAllowInvalid(){return this.rule.errorStyle!==i.DataValidationErrorStyle.STOP}getCriteriaType(){return this.rule.type}getCriteriaValues(){return[this.rule.operator,this.rule.formula1,this.rule.formula2]}getHelpText(){return this.rule.error}copy(){return new le(this.rule)}getApplied(){if(!this._worksheet)return!1;const t=this._worksheet.getInject().get(v.DataValidationModel).getRuleById(this._worksheet.getWorkbook().getUnitId(),this._worksheet.getSheetId(),this.rule.uid);return!!(t&&t.ranges.length)}getRanges(){var r;if(!this.getAllowInvalid())return[];const e=(r=this._worksheet)==null?void 0:r.getWorkbook(),t=this.getSheetId();if(!t)return[];const a=e==null?void 0:e.getSheetBySheetId(t);return!e||!a?[]:this.rule.ranges.map(n=>{var o;return(o=this._worksheet)==null?void 0:o.getInject().createInstance(te.FRange,e,a,n)})}getUnitId(){var e;return(e=this._worksheet)==null?void 0:e.getWorkbook().getUnitId()}getSheetId(){var e;return(e=this._worksheet)==null?void 0:e.getSheetId()}setCriteria(e,t){return this.getApplied()&&!this._worksheet.getInject().get(i.ICommandService).syncExecuteCommand(Ie.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,setting:{operator:t[0],formula1:t[1],formula2:t[2],type:this.rule.type}})?!1:(this.rule.operator=t[0],this.rule.formula1=t[1],this.rule.formula2=t[2],this.rule.type=e,!0)}setOptions(e){return this.getApplied()&&!this._worksheet.getInject().get(i.ICommandService).syncExecuteCommand(Ce.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,options:{...v.getRuleOptions(this.rule),...e}})?!1:(Object.assign(this.rule,e),!0)}setRanges(e){return this.getApplied()&&!this._worksheet.getInject().get(i.ICommandService).syncExecuteCommand(we.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,ranges:e.map(r=>r.getRange())})?!1:(this.rule.ranges=e,!0)}delete(){return this.getApplied()?this._worksheet.getInject().get(i.ICommandService).syncExecuteCommand(be.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid}):!1}}class at extends te.FRange{async setDataValidation(e){if(!e)return this._commandService.executeCommand(ze.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),ranges:[this._range]}),this;const t={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),rule:{...e.rule,ranges:[this._range]}};return await this._commandService.executeCommand(Oe.id,t),this}getDataValidation(){const t=this._injector.get(ee).getDataValidation(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]);return t&&new se(t)}getDataValidations(){return this._injector.get(ee).getDataValidations(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]).map(t=>new se(t))}async getValidatorStatus(){return this._injector.get(ee).validatorRanges(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range])}}te.FRange.extend(at);class rt{static newDataValidation(){return new le}}i.FUniver.extend(rt);class it extends te.FWorkbook{_initialize(){Object.defineProperty(this,"_dataValidationModel",{get(){return this._injector.get(j)}})}getValidatorStatus(){return this._injector.get(ee).validatorWorkbook(this._workbook.getUnitId())}onDataValidationChange(e){return i.toDisposable(this._dataValidationModel.ruleChange$.pipe(Y.filter(t=>t.unitId===this._workbook.getUnitId())).subscribe(e))}onDataValidationStatusChange(e){return i.toDisposable(this._dataValidationModel.validStatusChange$.pipe(Y.filter(t=>t.unitId===this._workbook.getUnitId())).subscribe(e))}onBeforeAddDataValidation(e){return i.toDisposable(this._commandService.beforeCommandExecuted((t,a)=>{const r=t.params;if(t.id===Oe.id){if(r.unitId!==this._workbook.getUnitId())return;if(e(r,a)===!1)throw new Error("Command is stopped by the hook onBeforeAddDataValidation")}}))}onBeforeUpdateDataValidationCriteria(e){return i.toDisposable(this._commandService.beforeCommandExecuted((t,a)=>{const r=t.params;if(t.id===Ie.id){if(r.unitId!==this._workbook.getUnitId())return;if(e(r,a)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationCriteria")}}))}onBeforeUpdateDataValidationRange(e){return i.toDisposable(this._commandService.beforeCommandExecuted((t,a)=>{const r=t.params;if(t.id===we.id){if(r.unitId!==this._workbook.getUnitId())return;if(e(r,a)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationRange")}}))}onBeforeUpdateDataValidationOptions(e){return i.toDisposable(this._commandService.beforeCommandExecuted((t,a)=>{const r=t.params;if(t.id===Ce.id){if(r.unitId!==this._workbook.getUnitId())return;if(e(r,a)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationOptions")}}))}onBeforeDeleteDataValidation(e){return i.toDisposable(this._commandService.beforeCommandExecuted((t,a)=>{const r=t.params;if(t.id===be.id){if(r.unitId!==this._workbook.getUnitId())return;if(e(r,a)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteDataValidation")}}))}onBeforeDeleteAllDataValidation(e){return i.toDisposable(this._commandService.beforeCommandExecuted((t,a)=>{const r=t.params;if(t.id===Je.id){if(r.unitId!==this._workbook.getUnitId())return;if(e(r,a)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteAllDataValidation")}}))}}te.FWorkbook.extend(it);class nt extends te.FWorksheet{getDataValidations(){return this._injector.get(v.DataValidationModel).getRules(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(t=>new se(t))}getValidatorStatus(){return this._injector.get(ee).validatorWorksheet(this._workbook.getUnitId(),this._worksheet.getSheetId())}}te.FWorksheet.extend(nt);exports.FDataValidation=se;exports.FDataValidationBuilder=le;
|
|
1
|
+
"use strict";var c=Object.defineProperty;var g=(n,t,e)=>t in n?c(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var u=(n,t,e)=>g(n,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("@univerjs/sheets/facade"),o=require("@univerjs/sheets-data-validation"),a=require("@univerjs/core"),h=require("@univerjs/data-validation"),D=require("@univerjs/engine-formula"),m=require("rxjs");class d{constructor(t){u(this,"_rule");this._rule=t!=null?t:{uid:a.generateRandomId(),ranges:void 0,type:a.DataValidationType.CUSTOM}}build(){return new l(this._rule)}copy(){return new d({...this._rule,uid:a.generateRandomId()})}getAllowInvalid(){return this._rule.errorStyle!==a.DataValidationErrorStyle.STOP}getCriteriaType(){return this._rule.type}getCriteriaValues(){return[this._rule.operator,this._rule.formula1,this._rule.formula2]}getHelpText(){return this._rule.error}requireCheckbox(t,e){return this._rule.type=a.DataValidationType.CHECKBOX,this._rule.formula1=t,this._rule.formula2=e,this}requireDateAfter(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.operator=a.DataValidationOperator.GREATER_THAN,this}requireDateBefore(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN,this}requireDateBetween(t,e){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=e.toLocaleDateString(),this._rule.operator=a.DataValidationOperator.BETWEEN,this}requireDateEqualTo(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.EQUAL,this}requireDateNotBetween(t,e){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=e.toLocaleDateString(),this._rule.operator=a.DataValidationOperator.NOT_BETWEEN,this}requireDateOnOrAfter(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.GREATER_THAN_OR_EQUAL,this}requireDateOnOrBefore(t){return this._rule.type=a.DataValidationType.DATE,this._rule.formula1=t.toLocaleDateString(),this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN_OR_EQUAL,this}requireFormulaSatisfied(t){return this._rule.type=a.DataValidationType.CUSTOM,this._rule.formula1=t,this._rule.formula2=void 0,this}requireNumberBetween(t,e,r){return this._rule.formula1=`${t}`,this._rule.formula2=`${e}`,this._rule.operator=a.DataValidationOperator.BETWEEN,this._rule.type=r?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.EQUAL,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberGreaterThan(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.GREATER_THAN,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberGreaterThanOrEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.GREATER_THAN_OR_EQUAL,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberLessThan(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberLessThanOrEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.LESS_THAN_OR_EQUAL,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberNotBetween(t,e,r){return this._rule.formula1=`${t}`,this._rule.formula2=`${e}`,this._rule.operator=a.DataValidationOperator.NOT_BETWEEN,this._rule.type=r?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireNumberNotEqualTo(t,e){return this._rule.formula1=`${t}`,this._rule.formula2=void 0,this._rule.operator=a.DataValidationOperator.NOT_EQUAL,this._rule.type=e?a.DataValidationType.WHOLE:a.DataValidationType.DECIMAL,this}requireValueInList(t,e,r){return this._rule.type=e?a.DataValidationType.LIST_MULTIPLE:a.DataValidationType.LIST,this._rule.formula1=t.join(","),this._rule.formula2=void 0,this._rule.showDropDown=r!=null?r:!0,this}requireValueInRange(t,e,r){return this._rule.type=e?a.DataValidationType.LIST_MULTIPLE:a.DataValidationType.LIST,this._rule.formula1=`=${D.serializeRangeToRefString({unitId:t.getUnitId(),sheetName:t.getSheetName(),range:t.getRange()})}`,this._rule.formula2=void 0,this._rule.showDropDown=r!=null?r:!0,this}setAllowInvalid(t){return this._rule.errorStyle=t?a.DataValidationErrorStyle.WARNING:a.DataValidationErrorStyle.STOP,this}setHelpText(t){return this._rule.error=t,this._rule.showErrorMessage=!0,this}withCriteriaValues(t,e){return this._rule.type=t,this._rule.operator=e[0],this._rule.formula1=e[1],this._rule.formula2=e[2],this}setOptions(t){return Object.assign(this._rule,t),this}}class l{constructor(t,e){u(this,"rule");u(this,"_worksheet");this.rule=t,this._worksheet=e}getAllowInvalid(){return this.rule.errorStyle!==a.DataValidationErrorStyle.STOP}getCriteriaType(){return this.rule.type}getCriteriaValues(){return[this.rule.operator,this.rule.formula1,this.rule.formula2]}getHelpText(){return this.rule.error}copy(){return new d(this.rule)}getApplied(){if(!this._worksheet)return!1;const e=this._worksheet.getInject().get(h.DataValidationModel).getRuleById(this._worksheet.getWorkbook().getUnitId(),this._worksheet.getSheetId(),this.rule.uid);return!!(e&&e.ranges.length)}getRanges(){var i;if(!this.getAllowInvalid())return[];const t=(i=this._worksheet)==null?void 0:i.getWorkbook(),e=this.getSheetId();if(!e)return[];const r=t==null?void 0:t.getSheetBySheetId(e);return!t||!r?[]:this.rule.ranges.map(p=>{var _;return(_=this._worksheet)==null?void 0:_.getInject().createInstance(s.FRange,t,r,p)})}getUnitId(){var t;return(t=this._worksheet)==null?void 0:t.getWorkbook().getUnitId()}getSheetId(){var t;return(t=this._worksheet)==null?void 0:t.getSheetId()}setCriteria(t,e){return this.getApplied()&&!this._worksheet.getInject().get(a.ICommandService).syncExecuteCommand(o.UpdateSheetDataValidationSettingCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,setting:{operator:e[0],formula1:e[1],formula2:e[2],type:this.rule.type}})?!1:(this.rule.operator=e[0],this.rule.formula1=e[1],this.rule.formula2=e[2],this.rule.type=t,!0)}setOptions(t){return this.getApplied()&&!this._worksheet.getInject().get(a.ICommandService).syncExecuteCommand(o.UpdateSheetDataValidationOptionsCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,options:{...h.getRuleOptions(this.rule),...t}})?!1:(Object.assign(this.rule,t),!0)}setRanges(t){return this.getApplied()&&!this._worksheet.getInject().get(a.ICommandService).syncExecuteCommand(o.UpdateSheetDataValidationRangeCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid,ranges:t.map(i=>i.getRange())})?!1:(this.rule.ranges=t,!0)}delete(){return this.getApplied()?this._worksheet.getInject().get(a.ICommandService).syncExecuteCommand(o.RemoveSheetDataValidationCommand.id,{unitId:this.getUnitId(),subUnitId:this.getSheetId(),ruleId:this.rule.uid}):!1}}class V extends s.FRange{async setDataValidation(t){if(!t)return this._commandService.executeCommand(o.ClearRangeDataValidationCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),ranges:[this._range]}),this;const e={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),rule:{...t.rule,ranges:[this._range]}};return await this._commandService.executeCommand(o.AddSheetDataValidationCommand.id,e),this}getDataValidation(){const e=this._injector.get(o.SheetsDataValidationValidatorService).getDataValidation(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]);return e&&new l(e)}getDataValidations(){return this._injector.get(o.SheetsDataValidationValidatorService).getDataValidations(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range]).map(e=>new l(e))}async getValidatorStatus(){return this._injector.get(o.SheetsDataValidationValidatorService).validatorRanges(this._workbook.getUnitId(),this._worksheet.getSheetId(),[this._range])}}s.FRange.extend(V);class f{static newDataValidation(){return new d}}a.FUniver.extend(f);class S extends s.FWorkbook{_initialize(){Object.defineProperty(this,"_dataValidationModel",{get(){return this._injector.get(o.SheetDataValidationModel)}})}getValidatorStatus(){return this._injector.get(o.SheetsDataValidationValidatorService).validatorWorkbook(this._workbook.getUnitId())}onDataValidationChange(t){return a.toDisposable(this._dataValidationModel.ruleChange$.pipe(m.filter(e=>e.unitId===this._workbook.getUnitId())).subscribe(t))}onDataValidationStatusChange(t){return a.toDisposable(this._dataValidationModel.validStatusChange$.pipe(m.filter(e=>e.unitId===this._workbook.getUnitId())).subscribe(t))}onBeforeAddDataValidation(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const i=e.params;if(e.id===o.AddSheetDataValidationCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeAddDataValidation")}}))}onBeforeUpdateDataValidationCriteria(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const i=e.params;if(e.id===o.UpdateSheetDataValidationSettingCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationCriteria")}}))}onBeforeUpdateDataValidationRange(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const i=e.params;if(e.id===o.UpdateSheetDataValidationRangeCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationRange")}}))}onBeforeUpdateDataValidationOptions(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const i=e.params;if(e.id===o.UpdateSheetDataValidationOptionsCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeUpdateDataValidationOptions")}}))}onBeforeDeleteDataValidation(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const i=e.params;if(e.id===o.RemoveSheetDataValidationCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteDataValidation")}}))}onBeforeDeleteAllDataValidation(t){return a.toDisposable(this._commandService.beforeCommandExecuted((e,r)=>{const i=e.params;if(e.id===o.RemoveSheetAllDataValidationCommand.id){if(i.unitId!==this._workbook.getUnitId())return;if(t(i,r)===!1)throw new Error("Command is stopped by the hook onBeforeDeleteAllDataValidation")}}))}}s.FWorkbook.extend(S);class I extends s.FWorksheet{getDataValidations(){return this._injector.get(h.DataValidationModel).getRules(this._workbook.getUnitId(),this._worksheet.getSheetId()).map(e=>new l(e))}getValidatorStatus(){return this._injector.get(o.SheetsDataValidationValidatorService).validatorWorksheet(this._workbook.getUnitId(),this._worksheet.getSheetId())}}s.FWorksheet.extend(I);exports.FDataValidation=l;exports.FDataValidationBuilder=d;
|