@univerjs/preset-sheets-data-validation 0.12.3 → 0.12.4-experimental.20251208-c4b8a44

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/umd/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
 
5
5
  // @univerjs/sheets-data-validation/index
6
- (function(m,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("@univerjs/core"),require("@univerjs/data-validation"),require("@univerjs/engine-formula"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/sheets-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/data-validation","@univerjs/engine-formula","@univerjs/sheets","rxjs","@univerjs/sheets-formula"],r):(m=typeof globalThis<"u"?globalThis:m||self,r(m.UniverSheetsDataValidation={},m.UniverCore,m.UniverDataValidation,m.UniverEngineFormula,m.UniverSheets,m.rxjs,m.UniverSheetsFormula))})(this,(function(m,r,p,y,D,A,Z){"use strict";var It=Object.defineProperty;var Ct=(m,r,p)=>r in m?It(m,r,{enumerable:!0,configurable:!0,writable:!0,value:p}):m[r]=p;var S=(m,r,p)=>Ct(m,typeof r!="symbol"?r+"":r,p);var He=Object.getOwnPropertyDescriptor,We=(o,s,e,t)=>{for(var a=t>1?void 0:t?He(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},de=(o,s)=>(e,t)=>s(e,t,o);m.DataValidationCacheService=class extends r.Disposable{constructor(e,t,a){super();S(this,"_cacheMatrix",new Map);S(this,"_dirtyRanges$",new A.Subject);S(this,"dirtyRanges$",this._dirtyRanges$.asObservable());this._commandService=e,this._univerInstanceService=t,this._sheetDataValidationModel=a,this._initDirtyRanges(),this._initSheetRemove()}_initDirtyRanges(){this.disposeWithMe(this._commandService.onCommandExecuted((e,t)=>{if(e.id===D.SetRangeValuesMutation.id&&!(t!=null&&t.onlyLocal)){const{cellValue:a,unitId:i,subUnitId:n}=e.params;if(a){const l=new r.ObjectMatrix(a).getDataRange();if(l.endRow===-1)return;const c=this._sheetDataValidationModel.getRules(i,n).map(h=>h.ranges).flat().map(h=>r.getIntersectRange(h,l)).filter(Boolean);c.length&&this.markRangeDirty(i,n,c,!0)}}}))}_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,i){const n=this._ensureCache(e,t);a.forEach(l=>{r.Range.foreach(l,(u,d)=>{n.getValue(u,d)!==void 0&&n.setValue(u,d,void 0)})}),this._dirtyRanges$.next({unitId:e,subUnitId:t,ranges:a,isSetRange:i})}_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=We([de(0,r.Inject(r.ICommandService)),de(1,r.Inject(r.IUniverInstanceService)),de(2,r.Inject(p.DataValidationModel))],m.DataValidationCacheService);function U(o){var s,e;return(e=(s=o==null?void 0:o[0])==null?void 0:s[0])==null?void 0:e.v}function j(o){var s;return(s=o==null?void 0:o[0])==null?void 0:s[0]}function E(o){return!y.ERROR_TYPE_SET.has(o)}function P(o,s){var t;const e=s.getValidatorItem(o);return(t=e==null?void 0:e.offsetFormulaByRange)!=null?t:!1}var $e=Object.getOwnPropertyDescriptor,ke=(o,s,e,t)=>{for(var a=t>1?void 0:t?$e(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},H=(o,s)=>(e,t)=>s(e,t,o);m.DataValidationCustomFormulaService=class extends r.Disposable{constructor(e,t,a,i,n){super();S(this,"_ruleFormulaMap",new Map);S(this,"_ruleFormulaMap2",new Map);this._instanceSrv=e,this._registerOtherFormulaService=t,this._dataValidationModel=a,this._dataValidationCacheService=i,this._validatorRegistryService=n,this._initFormulaResultHandler(),this._initDirtyRanges()}dispose(){super.dispose(),this._ruleFormulaMap.clear(),this._ruleFormulaMap2.clear()}_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 g,f;const c=u.get((g=d.extra)==null?void 0:g.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})}_handleDirtyRanges(e,t,a){this._dataValidationModel.getRules(e,t).forEach(n=>{const l=n.ranges;r.Rectangle.doAnyRangesIntersect(l,a)&&this.makeRuleDirty(e,t,n.uid)})}_initDirtyRanges(){this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.subscribe(e=>{e.isSetRange&&this._handleDirtyRanges(e.unitId,e.subUnitId,e.ranges)}))}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 g=this._registerFormula(e,t,a,i,l);u.set(a,{formula:i,originCol:h,originRow:c,formulaId:g})}if(n&&r.isFormulaString(n)){const g=this._registerFormula(e,t,a,n,l);d.set(a,{formula:n,originCol:h,originRow:c,formulaId:g})}}addRule(e,t,a){if(P(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 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,g=i-c,f=n-h;return j((_=(R=d==null?void 0:d.result)==null?void 0:R[g])==null?void 0:_[f])}async getCellFormula2Value(e,t,a,i,n){var 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,g=i-c,f=n-h;return j((_=(R=d==null?void 0:d.result)==null?void 0:R[g])==null?void 0:_[f])}getCellFormulaValueSync(e,t,a,i,n){var 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,g=i-c,f=n-h;return j((_=(R=d==null?void 0:d.result)==null?void 0:R[g])==null?void 0:_[f])}getCellFormula2ValueSync(e,t,a,i,n){var 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,g=i-c,f=n-h;return j((_=(R=d==null?void 0:d.result)==null?void 0:R[g])==null?void 0:_[f])}getRuleFormulaInfo(e,t,a){const{ruleFormulaMap:i}=this._ensureMaps(e,t);return i.get(a)}makeRuleDirty(e,t,a){var l,u,d,c;const i=(u=(l=this._ruleFormulaMap.get(e))==null?void 0:l.get(t))==null?void 0:u.get(a),n=(c=(d=this._ruleFormulaMap2.get(e))==null?void 0:d.get(t))==null?void 0:c.get(a);i&&this._registerOtherFormulaService.markFormulaDirty(e,t,i.formulaId),n&&this._registerOtherFormulaService.markFormulaDirty(e,t,n.formulaId)}},m.DataValidationCustomFormulaService=ke([H(0,r.IUniverInstanceService),H(1,r.Inject(Z.RegisterOtherFormulaService)),H(2,r.Inject(p.DataValidationModel)),H(3,r.Inject(m.DataValidationCacheService)),H(4,r.Inject(p.DataValidatorRegistryService))],m.DataValidationCustomFormulaService);var xe=Object.getOwnPropertyDescriptor,qe=(o,s,e,t)=>{for(var a=t>1?void 0:t?xe(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},W=(o,s)=>(e,t)=>s(e,t,o);m.DataValidationFormulaService=class extends r.Disposable{constructor(e,t,a,i,n){super();S(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 g=this._dataValidationModel.getRuleById(t,n,(h=d.extra)==null?void 0:h.ruleId);g&&this._dataValidationCacheService.markRangeDirty(t,n,g.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(!P(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 g=this._registerSingleFormula(e,t,i,l);h[0]={id:g,text:i}}if(d){const g=this._registerSingleFormula(e,t,n,l);h[1]={id:g,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=qe([W(0,r.IUniverInstanceService),W(1,r.Inject(Z.RegisterOtherFormulaService)),W(2,r.Inject(m.DataValidationCacheService)),W(3,r.Inject(p.DataValidationModel)),W(4,r.Inject(p.DataValidatorRegistryService))],m.DataValidationFormulaService);function w(o){return r.getOriginCellValue(o)}function Ve(o){var s;return String((s=w(o))!=null?s:"")}class ce{constructor(s,e,t,a,i=!1){S(this,"_map");S(this,"_tree",new r.RBush);S(this,"_dirty",!0);S(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});S(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=r.Rectangle.mergeRanges(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 ce(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 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=n(a)||a);return a},N=(o,s)=>(e,t)=>s(e,t,o);m.SheetDataValidationModel=class extends r.Disposable{constructor(e,t,a,i,n,l,u){super();S(this,"_ruleMatrixMap",new Map);S(this,"_validStatusChange$",new A.Subject);S(this,"_ruleChange$",new A.Subject);S(this,"ruleChange$",this._ruleChange$.asObservable());S(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 ce(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===p.UpdateRuleType.RANGE?l.updateRange(a,n.payload):n.type===p.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=(_,V)=>{a&&a(_,V),V&&this._validStatusChange$.next({unitId:l,subUnitId:u,ruleId:e.uid,status:_,row:n,col:i})},h=d.getCellValueOnly(n,i),g=this.getValidator(e.type),f=d.getCellRaw(n,i),R=w(f);if(g){const _=this._dataValidationCacheService.ensureCache(l,u),V=_.getValue(n,i);return V==null?(_.setValue(n,i,r.DataValidationStatus.VALIDATING),g.validator({value:R,unitId:l,subUnitId:u,row:n,column:i,worksheet:t.worksheet,workbook:t.workbook,interceptValue:w(h),t:f==null?void 0:f.t},e).then(v=>{const M=v?r.DataValidationStatus.VALID:r.DataValidationStatus.INVALID,T=_.getValue(n,i);M===r.DataValidationStatus.VALID?_.realDeleteValue(n,i):_.setValue(n,i,M),c(M,V!==T)}),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=Ge([N(0,r.Inject(p.DataValidationModel)),N(1,r.IUniverInstanceService),N(2,r.Inject(p.DataValidatorRegistryService)),N(3,r.Inject(m.DataValidationCacheService)),N(4,r.Inject(m.DataValidationFormulaService)),N(5,r.Inject(m.DataValidationCustomFormulaService)),N(6,r.ICommandService)],m.SheetDataValidationModel);const $=1,k=0;function De(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 Me extends p.BaseDataValidator{constructor(){super(...arguments);S(this,"id",r.DataValidationType.CHECKBOX);S(this,"title","dataValidation.checkbox.title");S(this,"operators",[]);S(this,"scopes",["sheet"]);S(this,"order",41);S(this,"offsetFormulaByRange",!1);S(this,"_formulaService",this.injector.get(m.DataValidationFormulaService));S(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=De(i,this.localeService),d=De(n,this.localeService);return{success:!u&&!d,formula1:u,formula2:d}}async parseFormula(e,t,a){var h,g,f,R;const{formula1:i=$,formula2:n=k}=e,l=await this._formulaService.getRuleFormulaResult(t,a,e.uid),u=r.isFormulaString(i)?U((g=(h=l==null?void 0:l[0])==null?void 0:h.result)==null?void 0:g[0][0]):i,d=r.isFormulaString(n)?U((R=(f=l==null?void 0:l[1])==null?void 0:f.result)==null?void 0:R[0][0]):n,c=E(String(u))&&E(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,g,f,R;const{formula1:i=$,formula2:n=k}=e,l=this._formulaService.getRuleFormulaResultSync(t,a,e.uid),u=r.isFormulaString(i)?U((g=(h=l==null?void 0:l[0])==null?void 0:h.result)==null?void 0:g[0][0]):i,d=r.isFormulaString(n)?U((R=(f=l==null?void 0:l[1])==null?void 0:f.result)==null?void 0:R[0][0]):n,c=E(String(u))&&E(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")}generateRuleName(e){return this.titleStr}}const Ye={[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 Ee={[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",NONE:"dataValidation.date.ruleName.legal"},Xe={[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",NONE:"dataValidation.date.errorMsg.legal"},J=[r.DataValidationOperator.BETWEEN,r.DataValidationOperator.NOT_BETWEEN],q="{FORMULA1}",Q="{FORMULA2}";function Ke(o){return o.filter(Boolean).join(",")}function G(o){return o.split(",").filter(Boolean)}function ze(o){const s=w(o);return s==null?"":s.toString()}function Y(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 me=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 ye extends p.BaseDataValidator{constructor(){super(...arguments);S(this,"id",r.DataValidationType.DATE);S(this,"title","dataValidation.date.title");S(this,"order",40);S(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]);S(this,"scopes",["sheet"]);S(this,"_customFormulaService",this.injector.get(m.DataValidationCustomFormulaService));S(this,"_lexerTreeBuilder",this.injector.get(y.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=E(String(l==null?void 0:l.v))&&E(String(u==null?void 0:u.v));return{formula1:me(r.isFormulaString(d)?l==null?void 0:l.v:d),formula2:me(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"||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:!0};const n=this._validatorSingleFormula(e.formula1),l=this.localeService.t("dataValidation.validFail.date");if(J.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 g=(h=r.numfmt.parseDate(d))==null?void 0:h.v;if(g==null)return"";c=r.numfmt.dateFromSerial(g)}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:me(i)}}get operatorNames(){return this.operators.map(e=>this.localeService.t(Ye[e]))}generateRuleName(e){var a,i;if(!e.operator)return this.localeService.t(Ee.NONE);const t=this.localeService.t(Ee[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}=Y(this._lexerTreeBuilder,e,t);return`${this.localeService.t(Xe[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 ee={[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",NONE:"dataValidation.errorMsg.legal"};function X(o){return+o}class Ze extends p.BaseDataValidator{constructor(){super(...arguments);S(this,"_customFormulaService",this.injector.get(m.DataValidationCustomFormulaService));S(this,"id",r.DataValidationType.DECIMAL);S(this,"_lexerTreeBuilder",this.injector.get(y.LexerTreeBuilder));S(this,"title","dataValidation.decimal.title");S(this,"order",20);S(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]);S(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(X(i))}transform(e,t,a){const{value:i}=e;return{...e,value:X(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=E(String(l==null?void 0:l.v))&&E(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:!0};const n=r.Tools.isDefine(e.formula1)&&this._isFormulaOrNumber(e.formula1),l=r.Tools.isDefine(e.formula2)&&this._isFormulaOrNumber(e.formula2),u=J.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.localeService.t(ee.NONE).replace("{TYPE}",this.titleStr);const{transformedFormula1:a,transformedFormula2:i}=Y(this._lexerTreeBuilder,e,t);return`${this.localeService.t(ee[e.operator]).replace(q,a!=null?a:"").replace(Q,i!=null?i:"")}`}}function he(o){if(!o)return[];const s=new Set;return o.forEach(e=>{e.forEach(t=>{var i,n;const a=w(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}E(a.toString())&&s.add(a.toString())}})}),[...s]}const Je=["if","indirect","choose","offset"];function et(o,s){if(!r.isFormulaString(o)||y.isReferenceString(o.slice(1)))return!0;const t=s.sequenceNodesBuilder(o);return t&&t.some(a=>typeof a=="object"&&a.nodeType===y.sequenceNodeType.FUNCTION&&Je.indexOf(a.token.toLowerCase())>-1)}function tt(o,s){const{formula1:e="",ranges:t}=o;if(y.isReferenceString(e.slice(1))){const i=y.deserializeRangeWithSheet(e.slice(1));if((!i.sheetName||i.sheetName===s)&&t.some(n=>r.Rectangle.intersects(n,i.range)))return!0}return!1}class ge extends p.BaseDataValidator{constructor(){super(...arguments);S(this,"formulaService",this.injector.get(m.DataValidationFormulaService));S(this,"_lexer",this.injector.get(y.LexerTreeBuilder));S(this,"_univerInstanceService",this.injector.get(r.IUniverInstanceService));S(this,"order",50);S(this,"offsetFormulaByRange",!1);S(this,"id",r.DataValidationType.LIST);S(this,"title","dataValidation.list.title");S(this,"operators",[]);S(this,"scopes",["sheet"]);S(this,"skipDefaultFontRender",e=>e.renderMode!==r.DataValidationRenderMode.TEXT)}validatorFormula(e,t,a){var d,c,h;const i=!r.Tools.isBlank(e.formula1),n=et((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=tt(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=U((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:E(String(n))}}async isValidType(e,t,a){var g,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)?he((f=(g=d==null?void 0:d[0])==null?void 0:g.result)==null?void 0:f[0][0]):G(u);return this.parseCellValue(i).every(R=>c.includes(R))}generateRuleName(){return this.localeService.t("dataValidation.list.name")}generateRuleErrorMessage(){return this.localeService.t("dataValidation.list.error")}getList(e,t,a){var g,f,R,_;const{formula1:i=""}=e,n=this.injector.get(r.IUniverInstanceService),l=(g=t?n.getUniverSheetInstance(t):void 0)!=null?g: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)?he((_=(R=h==null?void 0:h[0])==null?void 0:R.result)==null?void 0:_[0][0]):G(i)}async getListAsync(e,t,a){var g,f,R,_;const{formula1:i=""}=e,n=this.injector.get(r.IUniverInstanceService),l=(g=t?n.getUniverSheetInstance(t):void 0)!=null?g: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)?he((_=(R=h==null?void 0:h[0])==null?void 0:R.result)==null?void 0:_[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 at extends p.BaseDataValidator{constructor(){super(...arguments);S(this,"id",r.DataValidationType.TEXT_LENGTH);S(this,"title","dataValidation.textLength.title");S(this,"_lexerTreeBuilder",this.injector.get(y.LexerTreeBuilder));S(this,"order",30);S(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]);S(this,"scopes",["sheet"]);S(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=J.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=E(String(l==null?void 0:l.v))&&E(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}=Y(this._lexerTreeBuilder,e,t);return`${this.localeService.t(p.TextLengthErrorTitleMap[e.operator]).replace(q,a!=null?a:"").replace(Q,i!=null?i:"")}`}}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():r.Tools.isBlank(o.v):!0}function K(o,s,e,t,a="command",i=!0){const n=t.get(y.LexerTreeBuilder),l=t.get(p.DataValidatorRegistryService),u=[],d=[],c=t.get(m.SheetDataValidationModel),h=t.get(r.IUniverInstanceService),g=D.getSheetCommandTarget(h,{unitId:o,subUnitId:s});if(!g)return{redoMutations:u,undoMutations:d};const{worksheet:f}=g,R=new r.ObjectMatrix;let _=!1;function V(v,M){i&&v.forEach(T=>{r.Range.foreach(T,(O,I)=>{const F=f.getCellRaw(O,I),B=Ve(F);(Te(F)||B===M)&&!(F!=null&&F.p)&&(_=!0,R.setValue(O,I,{v:M,p:null}))})})}if(e.forEach(v=>{switch(v.type){case"delete":u.push({id:p.RemoveDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:v.rule.uid,source:a}}),d.unshift({id:p.AddDataValidationMutation.id,params:{unitId:o,subUnitId:s,rule:v.rule,index:v.index,source:a}});break;case"update":{if(P(v.rule.type,l)){const T=v.oldRanges[0].startRow,O=v.oldRanges[0].startColumn,I=v.newRanges[0].startRow,F=v.newRanges[0].startColumn,B=I-T,oe=F-O,se=r.isFormulaString(v.rule.formula1)?n.moveFormulaRefOffset(v.rule.formula1,oe,B):v.rule.formula1,le=r.isFormulaString(v.rule.formula2)?n.moveFormulaRefOffset(v.rule.formula2,oe,B):v.rule.formula2;se!==v.rule.formula1||le!==v.rule.formula2||!r.isRangesEqual(v.newRanges,v.oldRanges)?(u.push({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:v.ruleId,payload:{type:p.UpdateRuleType.ALL,payload:{formula1:se,formula2:le,ranges:v.newRanges}}}}),d.unshift({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:v.ruleId,payload:{type:p.UpdateRuleType.ALL,payload:{formula1:v.rule.formula1,formula2:v.rule.formula2,ranges:v.oldRanges}}}})):(u.push({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:v.ruleId,payload:{type:p.UpdateRuleType.RANGE,payload:v.newRanges},source:a}}),d.unshift({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:v.ruleId,payload:{type:p.UpdateRuleType.RANGE,payload:v.oldRanges},source:a}}))}else u.push({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:v.ruleId,payload:{type:p.UpdateRuleType.RANGE,payload:v.newRanges},source:a}}),d.unshift({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:v.ruleId,payload:{type:p.UpdateRuleType.RANGE,payload:v.oldRanges},source:a}});const M=c.getRuleById(o,s,v.ruleId);if(M&&M.type===r.DataValidationType.CHECKBOX){const O=c.getValidator(r.DataValidationType.CHECKBOX).parseFormulaSync(M,o,s);V(v.newRanges,O.formula2)}break}case"add":{if(u.push({id:p.AddDataValidationMutation.id,params:{unitId:o,subUnitId:s,rule:v.rule,source:a}}),d.unshift({id:p.RemoveDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:v.rule.uid,source:a}}),v.rule.type===r.DataValidationType.CHECKBOX){const T=c.getValidator(r.DataValidationType.CHECKBOX).parseFormulaSync(v.rule,o,s);V(v.rule.ranges,T.originFormula2)}break}}}),_){const v={id:D.SetRangeValuesMutation.id,params:{unitId:o,subUnitId:s,cellValue:R.getData()}},M={id:D.SetRangeValuesMutation.id,params:D.SetRangeValuesUndoMutationFactory(t,v.params)};u.push(v),d.push(M)}return{redoMutations:u,undoMutations:d}}const Oe={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:g,undoMutations:f}=K(e,t,h,o);return u.pushUndoRedo({undoMutations:f,redoMutations:g,unitID:e}),r.sequenceExecute(g,l),!0}},Fe={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:g,undoMutations:f}=K(e,t,d,o);return g.push({id:p.AddDataValidationMutation.id,params:h}),f.unshift({id:p.RemoveDataValidationMutation.id,params:{unitId:e,subUnitId:t,ruleId:a.uid}}),l.pushUndoRedo({unitID:e,redoMutations:g,undoMutations:f}),r.sequenceExecute(g,n),!0}},Ie={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(p.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 g={...h,...d};if(!c.validatorFormula(g,n,l).success)return!1;const f={unitId:n,subUnitId:l,ruleId:u,payload:{type:p.UpdateRuleType.SETTING,payload:{...d,...c.normalizeFormula(g,n,l)}}},R=[{id:p.UpdateDataValidationMutation.id,params:f}],_={unitId:n,subUnitId:l,ruleId:u,payload:{type:p.UpdateRuleType.SETTING,payload:p.getRuleSetting(h)}},V=[{id:p.UpdateDataValidationMutation.id,params:_}];if(d.type===r.DataValidationType.CHECKBOX){const M=h.ranges,T=o.get(r.IUniverInstanceService),O=D.getSheetCommandTarget(T,{unitId:n,subUnitId:l});if(O){const I=new r.ObjectMatrix,{worksheet:F}=O,{formula2:B=k,formula1:oe=$}=h,{formula2:se=k,formula1:le=$}=d;let Re=!1;if(M.forEach(ue=>{r.Range.foreach(ue,(z,_e)=>{const C=F.getCellRaw(z,_e),Pe=Ve(C);(Te(C)||Pe===String(B))&&!(C!=null&&C.p)?(I.setValue(z,_e,{v:se,p:null}),Re=!0):Pe===String(oe)&&!(C!=null&&C.p)&&(I.setValue(z,_e,{v:le,p:null}),Re=!0)})}),Re){const ue={id:D.SetRangeValuesMutation.id,params:{unitId:n,subUnitId:l,cellValue:I.getData()}},z={id:D.SetRangeValuesMutation.id,params:D.SetRangeValuesUndoMutationFactory(o,ue.params)};R.push(ue),V.push(z)}}}return r.sequenceExecute(R,e).result?(t.pushUndoRedo({unitID:n,redoMutations:R,undoMutations:V}),!0):!1}},Ce={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:p.UpdateRuleType.OPTIONS,payload:u}},h=[{id:p.UpdateDataValidationMutation.id,params:c}],g={unitId:i,subUnitId:n,ruleId:l,payload:{type:p.UpdateRuleType.OPTIONS,payload:p.getRuleOptions(d)}},f=[{id:p.UpdateDataValidationMutation.id,params:g}];return t.pushUndoRedo({unitID:i,redoMutations:h,undoMutations:f}),e.executeCommand(p.UpdateDataValidationMutation.id,c),!0}},Ne={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:g,undoMutations:f}=K(e,t,h,o);return d.pushUndoRedo({unitID:e,redoMutations:g,undoMutations:f}),r.sequenceExecute(g,i).result}},Ae={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: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}},it=(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: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,i)},index:e.getRuleIndex(t,a,i)}}]},Ue={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:p.RemoveDataValidationMutation.id,params:s}],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:s.unitId}),i.executeCommand(p.RemoveDataValidationMutation.id,s),!0}},we="SHEET_DATA_VALIDATION_PLUGIN";var Le=(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))(Le||{}),rt=Object.getOwnPropertyDescriptor,nt=(o,s,e,t)=>{for(var a=t>1?void 0:t?rt(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},pe=(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=y.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:g,endRow:f,startColumn:R,endColumn:_}=u.range;for(let V=g;V<=f;V++)for(let v=R;v<=_;v++){const M=(a=(t=c.getCell(V,v))==null?void 0:t.selectionProtection)==null?void 0:a[0];if((M==null?void 0:M[Le.View])===!1)return!1}}return!0}},m.DataValidationFormulaController=nt([pe(0,r.IUniverInstanceService),pe(1,r.IPermissionService),pe(2,r.Inject(y.LexerTreeBuilder))],m.DataValidationFormulaController);const ot="sheets-data-validation.config",be={};var st=Object.getOwnPropertyDescriptor,lt=(o,s,e,t)=>{for(var a=t>1?void 0:t?st(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},Se=(o,s)=>(e,t)=>s(e,t,o);let te=class extends r.Disposable{constructor(s,e,t){super();S(this,"_disposableMap",new Map);S(this,"registerRule",(s,e,t)=>{P(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:p.AddDataValidationMutation.id,params:{unitId:s,subUnitId:e,rule:t,source:"patched"}}],redos:[{id:p.RemoveDataValidationMutation.id,params:{unitId:s,subUnitId:e,ruleId:t.uid,source:"patched"}}]};const c=[],h=[],g=d[0];c.push({id:p.UpdateDataValidationMutation.id,params:{unitId:s,subUnitId:e,ruleId:t.uid,payload:{type:p.UpdateRuleType.ALL,payload:{ranges:g.ranges,formula1:g.formulas[0],formula2:g.formulas[1]}},source:"patched"}}),h.push({id:p.UpdateDataValidationMutation.id,params:{unitId:s,subUnitId:e,ruleId:t.uid,payload:{type:p.UpdateRuleType.ALL,payload:{ranges:a,formula1:i,formula2:n}},source:"patched"}});for(let f=1;f<d.length;f++){const R=d[f],_=r.generateRandomId();c.push({id:p.AddDataValidationMutation.id,params:{unitId:s,subUnitId:e,rule:{...t,uid:_,formula1:R.formulas[0],formula2:R.formulas[1],ranges:R.ranges},source:"patched"}}),h.push({id:p.RemoveDataValidationMutation.id,params:{unitId:s,subUnitId:e,ruleId:_,source:"patched"}})}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()}))}};te=lt([Se(0,r.Inject(m.SheetDataValidationModel)),Se(1,r.Inject(Z.FormulaRefRangeService)),Se(2,r.Inject(p.DataValidatorRegistryService))],te);var ut=Object.getOwnPropertyDescriptor,dt=(o,s,e,t)=>{for(var a=t>1?void 0:t?ut(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},L=(o,s)=>(e,t)=>s(e,t,o);let ae=class extends r.Disposable{constructor(s,e,t,a,i,n){super();S(this,"_disposableMap",new Map);S(this,"registerRule",(s,e,t)=>{P(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 g=this._dataValidationModel.getRuleById(s,e,a);if(!g)return{redos:[],undos:[]};const f=g[c];if(!f||f===h)return{redos:[],undos:[]};const R={unitId:s,subUnitId:e,ruleId:t.uid,payload:{type:p.UpdateRuleType.SETTING,payload:{type:g.type,formula1:g.formula1,formula2:g.formula2,[c]:h}},source:"patched"},_={unitId:s,subUnitId:e,ruleId:t.uid,payload:{type:p.UpdateRuleType.SETTING,payload:{type:g.type,formula1:g.formula1,formula2:g.formula2}},source:"patched"},V=[{id:p.UpdateDataValidationMutation.id,params:R}],v=[{id:p.UpdateDataValidationMutation.id,params:_}];return{redos:V,undos:v}},u=this._dataValidationFormulaService.getRuleFormulaInfo(s,e,a);if(u){const[c,h]=u;if(c){const g=this._formulaRefRangeService.registerFormula(s,e,c.text,f=>l("formula1",f));n.add(()=>g.dispose())}if(h){const g=this._formulaRefRangeService.registerFormula(s,e,h.text,f=>l("formula2",f));n.add(()=>g.dispose())}}}register(s,e,t){var u;const a=d=>{const c=[...t.ranges],g=c.map(R=>D.handleCommonDefaultRangeChangeWithEffectRefCommands(R,d)).filter(R=>!!R).flat();if(r.isRangesEqual(g,c))return{redos:[],undos:[]};if(g.length){const R={unitId:s,subUnitId:e,ruleId:t.uid,payload:{type:p.UpdateRuleType.RANGE,payload:g},source:"patched"},_=[{id:p.UpdateDataValidationMutation.id,params:R}],V=[{id:p.UpdateDataValidationMutation.id,params:{unitId:s,subUnitId:e,ruleId:t.uid,payload:{type:p.UpdateRuleType.RANGE,payload:c},source:"patched"}}];return{redos:_,undos:V}}else{const R={unitId:s,subUnitId:e,ruleId:t.uid},_=[{id:p.RemoveDataValidationMutation.id,params:R}],V=it(this._injector,R);return{redos:_,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()}))}};ae=dt([L(0,r.Inject(m.SheetDataValidationModel)),L(1,r.Inject(r.Injector)),L(2,r.Inject(D.RefRangeService)),L(3,r.Inject(m.DataValidationFormulaService)),L(4,r.Inject(Z.FormulaRefRangeService)),L(5,r.Inject(p.DataValidatorRegistryService))],ae);var ct=Object.getOwnPropertyDescriptor,mt=(o,s,e,t)=>{for(var a=t>1?void 0:t?ct(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},fe=(o,s)=>(e,t)=>s(e,t,o);let ie=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:p.RemoveDataValidationMutation.id,params:u}],undos:[{id:p.AddDataValidationMutation.id,params:d}]}}else if(o.id===D.CopySheetCommand.id){const e=o.params,{unitId:t,subUnitId:a,targetSubUnitId:i}=e;if(!t||!a||!i)return{redos:[],undos:[]};const n=this._sheetDataValidationModel.getRules(t,a);if(n.length===0)return{redos:[],undos:[]};const l=n.map(u=>({...u,uid:r.generateRandomId(6)}));return{redos:[{id:p.AddDataValidationMutation.id,params:{unitId:t,subUnitId:i,rule:l,source:"patched"}}],undos:[{id:p.RemoveDataValidationMutation.id,params:{unitId:t,subUnitId:i,ruleId:l.map(u=>u.uid),source:"patched"}}]}}return{redos:[],undos:[]}}}))}};ie=mt([fe(0,r.Inject(D.SheetInterceptorService)),fe(1,r.Inject(r.IUniverInstanceService)),fe(2,r.Inject(m.SheetDataValidationModel))],ie);class ht extends p.BaseDataValidator{constructor(){super(...arguments);S(this,"id",r.DataValidationType.ANY);S(this,"title","dataValidation.any.title");S(this,"operators",[]);S(this,"scopes",["sheet"]);S(this,"order",0);S(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 gt extends p.BaseDataValidator{constructor(){super(...arguments);S(this,"id",r.DataValidationType.CUSTOM);S(this,"title","dataValidation.custom.title");S(this,"operators",[]);S(this,"scopes",["sheet"]);S(this,"order",60);S(this,"_customFormulaService",this.injector.get(m.DataValidationCustomFormulaService));S(this,"_lexerTreeBuilder",this.injector.get(y.LexerTreeBuilder))}validatorFormula(e,t,a){var d;const i=r.isFormulaString(e.formula1),n=(d=e.formula1)!=null?d:"",u=this._lexerTreeBuilder.checkIfAddBracket(n)===0&&n.startsWith(y.operatorToken.EQUALS);return{success:i&&u,formula1:i&&u?"":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 E(String(c))&&r.Tools.isDefine(c)&&c!==""?d.t===r.CellValueType.BOOLEAN?!!c:typeof c=="boolean"?c:typeof c=="number"?!!c:typeof c=="string"?E(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 ge{constructor(){super(...arguments);S(this,"id",r.DataValidationType.LIST_MULTIPLE);S(this,"title","dataValidation.listMultiple.title");S(this,"offsetFormulaByRange",!1);S(this,"skipDefaultFontRender",()=>!0)}}class pt extends p.BaseDataValidator{constructor(){super(...arguments);S(this,"_customFormulaService",this.injector.get(m.DataValidationCustomFormulaService));S(this,"_lexerTreeBuilder",this.injector.get(y.LexerTreeBuilder));S(this,"id",r.DataValidationType.WHOLE);S(this,"title","dataValidation.whole.title");S(this,"order",10);S(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]);S(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=X(i);return!Number.isNaN(n)&&Number.isInteger(n)}transform(e,t,a){const{value:i}=e;return{...e,value:X(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,g=r.isFormulaString(c)?u==null?void 0:u.v:c,f=E(`${h}`)&&E(`${g}`);return{formula1:this._parseNumber(h),formula2:this._parseNumber(g),isFormulaValid:f}}validatorFormula(e,t,a){const i=e.operator;if(!i)return{success:!0};const n=r.Tools.isDefine(e.formula1)&&this._isFormulaOrInt(e.formula1),l=r.Tools.isDefine(e.formula2)&&this._isFormulaOrInt(e.formula2),u=J.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.localeService.t(ee.NONE).replace("{TYPE}",this.titleStr);const{transformedFormula1:a,transformedFormula2:i}=Y(this._lexerTreeBuilder,e,t);return`${this.localeService.t(ee[e.operator]).replace(q,a!=null?a:"").replace(Q,i!=null?i:"")}`}}var St=Object.getOwnPropertyDescriptor,ft=(o,s,e,t)=>{for(var a=t>1?void 0:t?St(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},b=(o,s)=>(e,t)=>s(e,t,o);let re=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(){[ht,Ze,pt,at,ye,Me,ge,Be,gt].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:[]}}})}};re=ft([b(0,r.IUniverInstanceService),b(1,r.Inject(p.DataValidatorRegistryService)),b(2,r.Inject(r.Injector)),b(3,r.Inject(D.SheetsSelectionsService)),b(4,r.Inject(D.SheetInterceptorService)),b(5,r.Inject(m.SheetDataValidationModel))],re);var 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=n(a)||a);return a},ne=(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(A.bufferWhen(()=>this._lifecycleService.lifecycle$.pipe(A.filter(e=>e===r.LifecycleStages.Rendered)))).subscribe(s)),this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.pipe(A.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}`);const l=this._sheetDataValidationModel.getRules(s,e).map(d=>d.ranges).flat(),u=t.map(d=>l.map(c=>r.getIntersectRange(d,c))).flat().filter(Boolean);return Promise.all(u.map(d=>{const c=[];return r.Range.foreach(d,(h,g)=>{c.push(this._validatorByCell(a,i,h,g))}),Promise.all(c)}))}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))}),Promise.all(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=Rt([ne(0,r.IUniverInstanceService),ne(1,r.Inject(m.SheetDataValidationModel)),ne(2,r.Inject(m.DataValidationCacheService)),ne(3,r.Inject(r.LifecycleService))],m.SheetsDataValidationValidatorService);var _t=Object.defineProperty,Vt=Object.getOwnPropertyDescriptor,Dt=(o,s,e)=>s in o?_t(o,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[s]=e,Mt=(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=n(a)||a);return a},ve=(o,s)=>(e,t)=>s(e,t,o),je=(o,s,e)=>Dt(o,typeof s!="symbol"?s+"":s,e);m.UniverSheetsDataValidationPlugin=class extends r.Plugin{constructor(s=be,e,t,a){super(),this._config=s,this._injector=e,this._commandService=t,this._configService=a;const{...i}=r.merge({},be,this._config);this._configService.setConfig(ot,i)}onStarting(){[[m.DataValidationCacheService],[m.DataValidationFormulaService],[m.DataValidationCustomFormulaService],[m.SheetsDataValidationValidatorService],[m.SheetDataValidationModel],[re],[m.DataValidationFormulaController],[ie],[ae],[te]].forEach(s=>{this._injector.add(s)}),[Fe,Oe,Ie,Ce,Ue,Ae,Ne].forEach(s=>{this._commandService.registerCommand(s)}),this._injector.get(m.DataValidationCacheService),this._injector.get(m.SheetsDataValidationValidatorService),this._injector.get(re),this._injector.get(te),this._injector.get(ae)}onReady(){this._injector.get(ie)}onRendered(){this._injector.get(m.DataValidationFormulaController)}},je(m.UniverSheetsDataValidationPlugin,"pluginName",we),je(m.UniverSheetsDataValidationPlugin,"type",r.UniverInstanceType.UNIVER_SHEET),m.UniverSheetsDataValidationPlugin=Mt([r.DependentOn(p.UniverDataValidationPlugin),ve(1,r.Inject(r.Injector)),ve(2,r.ICommandService),ve(3,r.IConfigService)],m.UniverSheetsDataValidationPlugin);function Et(o){const e=o.get(D.SheetsSelectionsService).getCurrentSelections().map(i=>i.range);return{uid:r.generateRandomId(6),type:r.DataValidationType.DECIMAL,operator:r.DataValidationOperator.EQUAL,formula1:"100",ranges:e!=null?e:[{startColumn:0,endColumn:0,startRow:0,endRow:0}]}}const yt="data-validation.custom-formula-input",Tt="data-validation.formula-input",Ot="data-validation.list-formula-input",Ft="data-validation.checkbox-formula-input";m.AddSheetDataValidationCommand=Fe,m.BASE_FORMULA_INPUT_NAME=Tt,m.CHECKBOX_FORMULA_1=$,m.CHECKBOX_FORMULA_2=k,m.CHECKBOX_FORMULA_INPUT_NAME=Ft,m.CUSTOM_FORMULA_INPUT_NAME=yt,m.CheckboxValidator=Me,m.ClearRangeDataValidationCommand=Ne,m.DATA_VALIDATION_PLUGIN_NAME=we,m.DateValidator=ye,m.LIST_FORMULA_INPUT_NAME=Ot,m.ListMultipleValidator=Be,m.ListValidator=ge,m.RemoveSheetAllDataValidationCommand=Ae,m.RemoveSheetDataValidationCommand=Ue,m.UpdateSheetDataValidationOptionsCommand=Ce,m.UpdateSheetDataValidationRangeCommand=Oe,m.UpdateSheetDataValidationSettingCommand=Ie,m.createDefaultNewRule=Et,m.deserializeListOptions=G,m.getCellValueNumber=X,m.getCellValueOrigin=w,m.getDataValidationCellValue=ze,m.getDataValidationDiffMutations=K,m.getFormulaCellData=j,m.getFormulaResult=U,m.getTransformedFormula=Y,m.isLegalFormulaResult=E,m.serializeListOptions=Ke,m.transformCheckboxValue=x,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})}));
6
+ (function(h,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("@univerjs/core"),require("@univerjs/data-validation"),require("@univerjs/engine-formula"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/sheets-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/data-validation","@univerjs/engine-formula","@univerjs/sheets","rxjs","@univerjs/sheets-formula"],r):(h=typeof globalThis<"u"?globalThis:h||self,r(h.UniverSheetsDataValidation={},h.UniverCore,h.UniverDataValidation,h.UniverEngineFormula,h.UniverSheets,h.rxjs,h.UniverSheetsFormula))})(this,(function(h,r,p,y,D,U,Z){"use strict";var At=Object.defineProperty;var Ut=(h,r,p)=>r in h?At(h,r,{enumerable:!0,configurable:!0,writable:!0,value:p}):h[r]=p;var S=(h,r,p)=>Ut(h,typeof r!="symbol"?r+"":r,p);var He=Object.getOwnPropertyDescriptor,We=(o,s,e,t)=>{for(var a=t>1?void 0:t?He(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},de=(o,s)=>(e,t)=>s(e,t,o);h.DataValidationCacheService=class extends r.Disposable{constructor(e,t,a){super();S(this,"_cacheMatrix",new Map);S(this,"_dirtyRanges$",new U.Subject);S(this,"dirtyRanges$",this._dirtyRanges$.asObservable());this._commandService=e,this._univerInstanceService=t,this._sheetDataValidationModel=a,this._initDirtyRanges(),this._initSheetRemove()}_initDirtyRanges(){this.disposeWithMe(this._commandService.onCommandExecuted((e,t)=>{if(e.id===D.SetRangeValuesMutation.id&&!(t!=null&&t.onlyLocal)){const{cellValue:a,unitId:i,subUnitId:n}=e.params;if(a){const l=new r.ObjectMatrix(a).getDataRange();if(l.endRow===-1)return;const c=this._sheetDataValidationModel.getRules(i,n).map(m=>m.ranges).flat().map(m=>r.getIntersectRange(m,l)).filter(Boolean);c.length&&this.markRangeDirty(i,n,c,!0)}}}))}_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,i){const n=this._ensureCache(e,t);a.forEach(l=>{r.Range.foreach(l,(u,d)=>{n.getValue(u,d)!==void 0&&n.setValue(u,d,void 0)})}),this._dirtyRanges$.next({unitId:e,subUnitId:t,ranges:a,isSetRange:i})}_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)}},h.DataValidationCacheService=We([de(0,r.Inject(r.ICommandService)),de(1,r.Inject(r.IUniverInstanceService)),de(2,r.Inject(p.DataValidationModel))],h.DataValidationCacheService);function w(o){var s,e;return(e=(s=o==null?void 0:o[0])==null?void 0:s[0])==null?void 0:e.v}function P(o){var s;return(s=o==null?void 0:o[0])==null?void 0:s[0]}function E(o){return!y.ERROR_TYPE_SET.has(o)}function H(o,s){var t;const e=s.getValidatorItem(o);return(t=e==null?void 0:e.offsetFormulaByRange)!=null?t:!1}var $e=Object.getOwnPropertyDescriptor,ke=(o,s,e,t)=>{for(var a=t>1?void 0:t?$e(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},W=(o,s)=>(e,t)=>s(e,t,o);h.DataValidationCustomFormulaService=class extends r.Disposable{constructor(e,t,a,i,n){super();S(this,"_ruleFormulaMap",new Map);S(this,"_ruleFormulaMap2",new Map);this._instanceSrv=e,this._registerOtherFormulaService=t,this._dataValidationModel=a,this._dataValidationCacheService=i,this._validatorRegistryService=n,this._initFormulaResultHandler(),this._initDirtyRanges()}dispose(){super.dispose(),this._ruleFormulaMap.clear(),this._ruleFormulaMap2.clear()}_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 g,v;const c=u.get((g=d.extra)==null?void 0:g.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),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})}_handleDirtyRanges(e,t,a){this._dataValidationModel.getRules(e,t).forEach(n=>{const l=n.ranges;r.Rectangle.doAnyRangesIntersect(l,a)&&this.makeRuleDirty(e,t,n.uid)})}_initDirtyRanges(){this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.subscribe(e=>{e.isSetRange&&this._handleDirtyRanges(e.unitId,e.subUnitId,e.ranges)}))}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,m=l[0].startColumn;if(i&&r.isFormulaString(i)){const g=this._registerFormula(e,t,a,i,l);u.set(a,{formula:i,originCol:m,originRow:c,formulaId:g})}if(n&&r.isFormulaString(n)){const g=this._registerFormula(e,t,a,n,l);d.set(a,{formula:n,originCol:m,originRow:c,formulaId:g})}}addRule(e,t,a){if(H(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 _,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,g=i-c,v=n-m;return P((R=(_=d==null?void 0:d.result)==null?void 0:_[g])==null?void 0:R[v])}async getCellFormula2Value(e,t,a,i,n){var _,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,g=i-c,v=n-m;return P((R=(_=d==null?void 0:d.result)==null?void 0:_[g])==null?void 0:R[v])}getCellFormulaValueSync(e,t,a,i,n){var _,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,g=i-c,v=n-m;return P((R=(_=d==null?void 0:d.result)==null?void 0:_[g])==null?void 0:R[v])}getCellFormula2ValueSync(e,t,a,i,n){var _,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,g=i-c,v=n-m;return P((R=(_=d==null?void 0:d.result)==null?void 0:_[g])==null?void 0:R[v])}getRuleFormulaInfo(e,t,a){const{ruleFormulaMap:i}=this._ensureMaps(e,t);return i.get(a)}makeRuleDirty(e,t,a){var l,u,d,c;const i=(u=(l=this._ruleFormulaMap.get(e))==null?void 0:l.get(t))==null?void 0:u.get(a),n=(c=(d=this._ruleFormulaMap2.get(e))==null?void 0:d.get(t))==null?void 0:c.get(a);i&&this._registerOtherFormulaService.markFormulaDirty(e,t,i.formulaId),n&&this._registerOtherFormulaService.markFormulaDirty(e,t,n.formulaId)}},h.DataValidationCustomFormulaService=ke([W(0,r.IUniverInstanceService),W(1,r.Inject(Z.RegisterOtherFormulaService)),W(2,r.Inject(p.DataValidationModel)),W(3,r.Inject(h.DataValidationCacheService)),W(4,r.Inject(p.DataValidatorRegistryService))],h.DataValidationCustomFormulaService);function N(o){return r.getOriginCellValue(o)}function Re(o){var s;return String((s=N(o))!=null?s:"")}function qe(o){return o.filter(Boolean).join(",")}function $(o){return o.split(",").filter(Boolean)}function xe(o){const s=N(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}}var 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=n(a)||a);return a},Ve=(o,s)=>(e,t)=>s(e,t,o);h.DataValidationListCacheService=class extends r.Disposable{constructor(e,t){super();S(this,"_cache",new Map);this._injector=e,this._dataValidationModel=t,this._initRuleChangeListener()}_initRuleChangeListener(){this.disposeWithMe(this._dataValidationModel.ruleChange$.subscribe(e=>{(e.type==="remove"||e.type==="update")&&this.markRuleDirty(e.unitId,e.subUnitId,e.rule.uid)}))}getOrCompute(e,t,a){const i=this.getCache(e,t,a.uid);if(i)return i;const l=this._injector.get(h.DataValidationFormulaService).getRuleFormulaResultSync(e,t,a.uid);return this.computeAndCache(e,t,a,l)}_ensureCache(e,t){let a=this._cache.get(e);a||(a=new Map,this._cache.set(e,a));let i=a.get(t);return i||(i=new Map,a.set(t,i)),i}getCache(e,t,a){var i,n;return(n=(i=this._cache.get(e))==null?void 0:i.get(t))==null?void 0:n.get(a)}setCache(e,t,a,i){this._ensureCache(e,t).set(a,i)}markRuleDirty(e,t,a){var i,n;(n=(i=this._cache.get(e))==null?void 0:i.get(t))==null||n.delete(a)}clear(){this._cache.clear()}computeAndCache(e,t,a,i){var _,R,V;const{formula1:n="",formula2:l=""}=a,u=r.isFormulaString(n)?this._getRuleFormulaResultSet((V=(R=(_=i==null?void 0:i[0])==null?void 0:_.result)==null?void 0:R[0])==null?void 0:V[0]):$(n),d=l.split(","),c=u.map((f,M)=>({label:f,color:d[M]||""})),m={};for(const f of c)f.color&&(m[f.label]=f.color);const g=new Set(u),v={list:u,listWithColor:c,colorMap:m,set:g};return this.setCache(e,t,a.uid,v),v}_getRuleFormulaResultSet(e){var a,i;if(!e)return[];const t=new Set;for(let n=0,l=e.length;n<l;n++){const u=e[n];if(u)for(let d=0,c=u.length;d<c;d++){const m=u[d],g=N(m);if(g!=null){if(typeof g!="string"&&typeof(m==null?void 0:m.s)=="object"&&((i=(a=m.s)==null?void 0:a.n)!=null&&i.pattern)){t.add(r.numfmt.format(m.s.n.pattern,g,{throws:!1}));continue}const v=typeof g=="string"?g:String(g);E(v)&&t.add(v)}}}return[...t]}},h.DataValidationListCacheService=Ge([Ve(0,r.Inject(r.Injector)),Ve(1,r.Inject(p.DataValidationModel))],h.DataValidationListCacheService);var 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=n(a)||a);return a},b=(o,s)=>(e,t)=>s(e,t,o);h.DataValidationFormulaService=class extends r.Disposable{constructor(e,t,a,i,n,l){super();S(this,"_formulaRuleMap",new Map);this._instanceService=e,this._registerOtherFormulaService=t,this._dataValidationCacheService=a,this._dataValidationModel=i,this._validatorRegistryService=n,this._listCacheService=l,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 m;const c=(m=d.extra)==null?void 0:m.ruleId;if(c&&u.get(c)){const g=this._dataValidationModel.getRuleById(t,n,c);g&&(this._listCacheService.markRuleDirty(t,n,c),this._dataValidationCacheService.markRangeDirty(t,n,g.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(!H(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),m=[void 0,void 0];if(u){const g=this._registerSingleFormula(e,t,i,l);m[0]={id:g,text:i}}if(d){const g=this._registerSingleFormula(e,t,n,l);m[1]={id:g,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=Xe([b(0,r.IUniverInstanceService),b(1,r.Inject(Z.RegisterOtherFormulaService)),b(2,r.Inject(h.DataValidationCacheService)),b(3,r.Inject(p.DataValidationModel)),b(4,r.Inject(p.DataValidatorRegistryService)),b(5,r.Inject(h.DataValidationListCacheService))],h.DataValidationFormulaService);class ce{constructor(s,e,t,a,i=!1){S(this,"_map");S(this,"_tree",new r.RBush);S(this,"_dirty",!0);S(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});S(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=r.Rectangle.mergeRanges(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,m)=>!r.Rectangle.equals(c,u[m])))&&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 ce(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.getOwnPropertyDescriptor,ze=(o,s,e,t)=>{for(var a=t>1?void 0:t?Ke(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},A=(o,s)=>(e,t)=>s(e,t,o);h.SheetDataValidationModel=class extends r.Disposable{constructor(e,t,a,i,n,l,u){super();S(this,"_ruleMatrixMap",new Map);S(this,"_validStatusChange$",new U.Subject);S(this,"_ruleChange$",new U.Subject);S(this,"ruleChange$",this._ruleChange$.asObservable());S(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 ce(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===p.UpdateRuleType.RANGE?l.updateRange(a,n.payload):n.type===p.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})},m=d.getCellValueOnly(n,i),g=this.getValidator(e.type),v=d.getCellRaw(n,i),_=N(v);if(g){const R=this._dataValidationCacheService.ensureCache(l,u),V=R.getValue(n,i);return V==null?(R.setValue(n,i,r.DataValidationStatus.VALIDATING),g.validator({value:_,unitId:l,subUnitId:u,row:n,column:i,worksheet:t.worksheet,workbook:t.workbook,interceptValue:N(m),t:v==null?void 0:v.t},e).then(f=>{const M=f?r.DataValidationStatus.VALID:r.DataValidationStatus.INVALID,T=R.getValue(n,i);M===r.DataValidationStatus.VALID?R.realDeleteValue(n,i):R.setValue(n,i,M),c(M,V!==T)}),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()}},h.SheetDataValidationModel=ze([A(0,r.Inject(p.DataValidationModel)),A(1,r.IUniverInstanceService),A(2,r.Inject(p.DataValidatorRegistryService)),A(3,r.Inject(h.DataValidationCacheService)),A(4,r.Inject(h.DataValidationFormulaService)),A(5,r.Inject(h.DataValidationCustomFormulaService)),A(6,r.ICommandService)],h.SheetDataValidationModel);const q=1,x=0;function De(o,s){return r.Tools.isBlank(o)?s.t("dataValidation.validFail.value"):r.isFormulaString(o)?s.t("dataValidation.validFail.primitive"):""}const Q=o=>r.Tools.isDefine(o)&&String(o).toLowerCase()==="true"?"1":String(o).toLowerCase()==="false"?"0":o;class Me extends p.BaseDataValidator{constructor(){super(...arguments);S(this,"id",r.DataValidationType.CHECKBOX);S(this,"title","dataValidation.checkbox.title");S(this,"operators",[]);S(this,"scopes",["sheet"]);S(this,"order",41);S(this,"offsetFormulaByRange",!1);S(this,"_formulaService",this.injector.get(h.DataValidationFormulaService));S(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=De(i,this.localeService),d=De(n,this.localeService);return{success:!u&&!d,formula1:u,formula2:d}}async parseFormula(e,t,a){var m,g,v,_;const{formula1:i=q,formula2:n=x}=e,l=await this._formulaService.getRuleFormulaResult(t,a,e.uid),u=r.isFormulaString(i)?w((g=(m=l==null?void 0:l[0])==null?void 0:m.result)==null?void 0:g[0][0]):i,d=r.isFormulaString(n)?w((_=(v=l==null?void 0:l[1])==null?void 0:v.result)==null?void 0:_[0][0]):n,c=E(String(u))&&E(String(d));return{formula1:Q(u),formula2:Q(d),originFormula1:u,originFormula2:d,isFormulaValid:c}}getExtraStyle(e,t){return{tb:r.WrapStrategy.CLIP}}parseFormulaSync(e,t,a){var m,g,v,_;const{formula1:i=q,formula2:n=x}=e,l=this._formulaService.getRuleFormulaResultSync(t,a,e.uid),u=r.isFormulaString(i)?w((g=(m=l==null?void 0:l[0])==null?void 0:m.result)==null?void 0:g[0][0]):i,d=r.isFormulaString(n)?w((_=(v=l==null?void 0:l[1])==null?void 0:v.result)==null?void 0:_[0][0]):n,c=E(String(u))&&E(String(d));return{formula1:Q(u),formula2:Q(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:m}=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(m!=null?m:""))}generateRuleErrorMessage(e){return this.localeService.t("dataValidation.checkbox.error")}generateRuleName(e){return this.titleStr}}const Ze={[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 Ee={[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",NONE:"dataValidation.date.ruleName.legal"},Je={[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",NONE:"dataValidation.date.errorMsg.legal"},J=[r.DataValidationOperator.BETWEEN,r.DataValidationOperator.NOT_BETWEEN],G="{FORMULA1}",Y="{FORMULA2}",he=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 ye extends p.BaseDataValidator{constructor(){super(...arguments);S(this,"id",r.DataValidationType.DATE);S(this,"title","dataValidation.date.title");S(this,"order",40);S(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]);S(this,"scopes",["sheet"]);S(this,"_customFormulaService",this.injector.get(h.DataValidationCustomFormulaService));S(this,"_lexerTreeBuilder",this.injector.get(y.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,m=E(String(l==null?void 0:l.v))&&E(String(u==null?void 0:u.v));return{formula1:he(r.isFormulaString(d)?l==null?void 0:l.v:d),formula2:he(r.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"||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:!0};const n=this._validatorSingleFormula(e.formula1),l=this.localeService.t("dataValidation.validFail.date");if(J.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 m;if(!d)return d;let c;if(!Number.isNaN(+d))c=r.numfmt.dateFromSerial(+d);else{const g=(m=r.numfmt.parseDate(d))==null?void 0:m.v;if(g==null)return"";c=r.numfmt.dateFromSerial(g)}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:he(i)}}get operatorNames(){return this.operators.map(e=>this.localeService.t(Ze[e]))}generateRuleName(e){var a,i;if(!e.operator)return this.localeService.t(Ee.NONE);const t=this.localeService.t(Ee[e.operator]).replace(G,(a=e.formula1)!=null?a:"").replace(Y,(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(Je[e.operator]).replace(G,a!=null?a:"").replace(Y,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 ee={[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",NONE:"dataValidation.errorMsg.legal"};function X(o){return+o}class et extends p.BaseDataValidator{constructor(){super(...arguments);S(this,"_customFormulaService",this.injector.get(h.DataValidationCustomFormulaService));S(this,"id",r.DataValidationType.DECIMAL);S(this,"_lexerTreeBuilder",this.injector.get(y.LexerTreeBuilder));S(this,"title","dataValidation.decimal.title");S(this,"order",20);S(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]);S(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(X(i))}transform(e,t,a){const{value:i}=e;return{...e,value:X(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,m=E(String(l==null?void 0:l.v))&&E(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:m}}validatorFormula(e,t,a){const i=e.operator;if(!i)return{success:!0};const n=r.Tools.isDefine(e.formula1)&&this._isFormulaOrNumber(e.formula1),l=r.Tools.isDefine(e.formula2)&&this._isFormulaOrNumber(e.formula2),u=J.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.localeService.t(ee.NONE).replace("{TYPE}",this.titleStr);const{transformedFormula1:a,transformedFormula2:i}=k(this._lexerTreeBuilder,e,t);return`${this.localeService.t(ee[e.operator]).replace(G,a!=null?a:"").replace(Y,i!=null?i:"")}`}}function tt(o){var e,t;if(!o)return[];const s=new Set;for(let a=0,i=o.length;a<i;a++){const n=o[a];if(n)for(let l=0,u=n.length;l<u;l++){const d=n[l],c=N(d);if(c!=null){if(typeof c!="string"&&typeof(d==null?void 0:d.s)=="object"&&((t=(e=d.s)==null?void 0:e.n)!=null&&t.pattern)){s.add(r.numfmt.format(d.s.n.pattern,c,{throws:!1}));continue}const m=typeof c=="string"?c:String(c);E(m)&&s.add(m)}}}return[...s]}const at=["if","indirect","choose","offset"];function it(o,s){if(!r.isFormulaString(o)||y.isReferenceString(o.slice(1)))return!0;const t=s.sequenceNodesBuilder(o);return t&&t.some(a=>typeof a=="object"&&a.nodeType===y.sequenceNodeType.FUNCTION&&at.indexOf(a.token.toLowerCase())>-1)}function rt(o,s){const{formula1:e="",ranges:t}=o;if(y.isReferenceString(e.slice(1))){const i=y.deserializeRangeWithSheet(e.slice(1));if((!i.sheetName||i.sheetName===s)&&t.some(n=>r.Rectangle.intersects(n,i.range)))return!0}return!1}class me extends p.BaseDataValidator{constructor(){super(...arguments);S(this,"formulaService",this.injector.get(h.DataValidationFormulaService));S(this,"_lexer",this.injector.get(y.LexerTreeBuilder));S(this,"_univerInstanceService",this.injector.get(r.IUniverInstanceService));S(this,"_listCacheService",this.injector.get(h.DataValidationListCacheService));S(this,"order",50);S(this,"offsetFormulaByRange",!1);S(this,"id",r.DataValidationType.LIST);S(this,"title","dataValidation.list.title");S(this,"operators",[]);S(this,"scopes",["sheet"]);S(this,"skipDefaultFontRender",e=>e.renderMode!==r.DataValidationRenderMode.TEXT)}validatorFormula(e,t,a){var d,c,m;const i=!r.Tools.isBlank(e.formula1),n=it((d=e.formula1)!=null?d:"",this._lexer),l=(m=(c=this._univerInstanceService.getUnit(t,r.UniverInstanceType.UNIVER_SHEET))==null?void 0:c.getSheetBySheetId(a))==null?void 0:m.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 $(t)}async parseFormula(e,t,a){var u,d;const i=await this.formulaService.getRuleFormulaResult(t,a,e.uid),n=w((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:E(String(n))}}async isValidType(e,t,a){const{value:i,unitId:n,subUnitId:l}=e,{formula1:u=""}=a,d=r.isFormulaString(u)?this._listCacheService.getOrCompute(n,l,a).list:$(u);return this.parseCellValue(i).every(m=>d.includes(m))}generateRuleName(){return this.localeService.t("dataValidation.list.name")}generateRuleErrorMessage(){return this.localeService.t("dataValidation.list.error")}_getUnitAndSubUnit(e,t){var n,l;const a=(n=e?this._univerInstanceService.getUniverSheetInstance(e):void 0)!=null?n:this._univerInstanceService.getCurrentUnitForType(r.UniverInstanceType.UNIVER_SHEET);if(!a)return null;const i=(l=t?a.getSheetBySheetId(t):void 0)!=null?l:a.getActiveSheet();return i?{unitId:a.getUnitId(),subUnitId:i.getSheetId()}:null}getList(e,t,a){const i=this._getUnitAndSubUnit(t,a);if(!i)return[];const{unitId:n,subUnitId:l}=i;return this._listCacheService.getOrCompute(n,l,e).list}async getListAsync(e,t,a){var c,m;const{formula1:i=""}=e,n=this._getUnitAndSubUnit(t,a);if(!n)return[];const{unitId:l,subUnitId:u}=n,d=await this.formulaService.getRuleFormulaResult(l,u,e.uid);return r.isFormulaString(i)?tt((m=(c=d==null?void 0:d[0])==null?void 0:c.result)==null?void 0:m[0][0]):$(i)}getListWithColor(e,t,a){const i=this._getUnitAndSubUnit(t,a);if(!i)return[];const{unitId:n,subUnitId:l}=i;return this._listCacheService.getOrCompute(n,l,e).listWithColor}getListWithColorMap(e,t,a){const i=this._getUnitAndSubUnit(t,a);if(!i)return{};const{unitId:n,subUnitId:l}=i;return this._listCacheService.getOrCompute(n,l,e).colorMap}}class nt extends p.BaseDataValidator{constructor(){super(...arguments);S(this,"id",r.DataValidationType.TEXT_LENGTH);S(this,"title","dataValidation.textLength.title");S(this,"_lexerTreeBuilder",this.injector.get(y.LexerTreeBuilder));S(this,"order",30);S(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]);S(this,"scopes",["sheet"]);S(this,"_customFormulaService",this.injector.get(h.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=J.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,m=E(String(l==null?void 0:l.v))&&E(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:m}}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(p.TextLengthErrorTitleMap[e.operator]).replace(G,a!=null?a:"").replace(Y,i!=null?i:"")}`}}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():r.Tools.isBlank(o.v):!0}function K(o,s,e,t,a="command",i=!0){const n=t.get(y.LexerTreeBuilder),l=t.get(p.DataValidatorRegistryService),u=[],d=[],c=t.get(h.SheetDataValidationModel),m=t.get(r.IUniverInstanceService),g=D.getSheetCommandTarget(m,{unitId:o,subUnitId:s});if(!g)return{redoMutations:u,undoMutations:d};const{worksheet:v}=g,_=new r.ObjectMatrix;let R=!1;function V(f,M){i&&f.forEach(T=>{r.Range.foreach(T,(O,F)=>{const C=v.getCellRaw(O,F),j=Re(C);(Te(C)||j===M)&&!(C!=null&&C.p)&&(R=!0,_.setValue(O,F,{v:M,p:null}))})})}if(e.forEach(f=>{switch(f.type){case"delete":u.push({id:p.RemoveDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.rule.uid,source:a}}),d.unshift({id:p.AddDataValidationMutation.id,params:{unitId:o,subUnitId:s,rule:f.rule,index:f.index,source:a}});break;case"update":{if(H(f.rule.type,l)){const T=f.oldRanges[0].startRow,O=f.oldRanges[0].startColumn,F=f.newRanges[0].startRow,C=f.newRanges[0].startColumn,j=F-T,oe=C-O,se=r.isFormulaString(f.rule.formula1)?n.moveFormulaRefOffset(f.rule.formula1,oe,j):f.rule.formula1,le=r.isFormulaString(f.rule.formula2)?n.moveFormulaRefOffset(f.rule.formula2,oe,j):f.rule.formula2;se!==f.rule.formula1||le!==f.rule.formula2||!r.isRangesEqual(f.newRanges,f.oldRanges)?(u.push({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.ruleId,payload:{type:p.UpdateRuleType.ALL,payload:{formula1:se,formula2:le,ranges:f.newRanges}}}}),d.unshift({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.ruleId,payload:{type:p.UpdateRuleType.ALL,payload:{formula1:f.rule.formula1,formula2:f.rule.formula2,ranges:f.oldRanges}}}})):(u.push({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.ruleId,payload:{type:p.UpdateRuleType.RANGE,payload:f.newRanges},source:a}}),d.unshift({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.ruleId,payload:{type:p.UpdateRuleType.RANGE,payload:f.oldRanges},source:a}}))}else u.push({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.ruleId,payload:{type:p.UpdateRuleType.RANGE,payload:f.newRanges},source:a}}),d.unshift({id:p.UpdateDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.ruleId,payload:{type:p.UpdateRuleType.RANGE,payload:f.oldRanges},source:a}});const M=c.getRuleById(o,s,f.ruleId);if(M&&M.type===r.DataValidationType.CHECKBOX){const O=c.getValidator(r.DataValidationType.CHECKBOX).parseFormulaSync(M,o,s);V(f.newRanges,O.formula2)}break}case"add":{if(u.push({id:p.AddDataValidationMutation.id,params:{unitId:o,subUnitId:s,rule:f.rule,source:a}}),d.unshift({id:p.RemoveDataValidationMutation.id,params:{unitId:o,subUnitId:s,ruleId:f.rule.uid,source:a}}),f.rule.type===r.DataValidationType.CHECKBOX){const T=c.getValidator(r.DataValidationType.CHECKBOX).parseFormulaSync(f.rule,o,s);V(f.rule.ranges,T.originFormula2)}break}}}),R){const f={id:D.SetRangeValuesMutation.id,params:{unitId:o,subUnitId:s,cellValue:_.getData()}},M={id:D.SetRangeValuesMutation.id,params:D.SetRangeValuesUndoMutationFactory(t,f.params)};u.push(f),d.push(M)}return{redoMutations:u,undoMutations:d}}const Oe={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(h.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 m=c.diff(n.getRules(e,t)),{redoMutations:g,undoMutations:v}=K(e,t,m,o);return u.pushUndoRedo({undoMutations:v,redoMutations:g,unitID:e}),r.sequenceExecute(g,l),!0}},Ce={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(h.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),m={unitId:e,subUnitId:t,rule:{...a,...c==null?void 0:c.normalizeFormula(a,e,t)}},{redoMutations:g,undoMutations:v}=K(e,t,d,o);return g.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:g,undoMutations:v}),r.sequenceExecute(g,n),!0}},Fe={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(h.SheetDataValidationModel),i=o.get(p.DataValidatorRegistryService),{unitId:n,subUnitId:l,ruleId:u,setting:d}=s,c=i.getValidatorItem(d.type);if(!c)return!1;const m=a.getRuleById(n,l,u);if(!m)return!1;const g={...m,...d};if(!c.validatorFormula(g,n,l).success)return!1;const v={unitId:n,subUnitId:l,ruleId:u,payload:{type:p.UpdateRuleType.SETTING,payload:{...d,...c.normalizeFormula(g,n,l)}}},_=[{id:p.UpdateDataValidationMutation.id,params:v}],R={unitId:n,subUnitId:l,ruleId:u,payload:{type:p.UpdateRuleType.SETTING,payload:p.getRuleSetting(m)}},V=[{id:p.UpdateDataValidationMutation.id,params:R}];if(d.type===r.DataValidationType.CHECKBOX){const M=m.ranges,T=o.get(r.IUniverInstanceService),O=D.getSheetCommandTarget(T,{unitId:n,subUnitId:l});if(O){const F=new r.ObjectMatrix,{worksheet:C}=O,{formula2:j=x,formula1:oe=q}=m,{formula2:se=x,formula1:le=q}=d;let ve=!1;if(M.forEach(ue=>{r.Range.foreach(ue,(z,_e)=>{const I=C.getCellRaw(z,_e),Pe=Re(I);(Te(I)||Pe===String(j))&&!(I!=null&&I.p)?(F.setValue(z,_e,{v:se,p:null}),ve=!0):Pe===String(oe)&&!(I!=null&&I.p)&&(F.setValue(z,_e,{v:le,p:null}),ve=!0)})}),ve){const ue={id:D.SetRangeValuesMutation.id,params:{unitId:n,subUnitId:l,cellValue:F.getData()}},z={id:D.SetRangeValuesMutation.id,params:D.SetRangeValuesUndoMutationFactory(o,ue.params)};_.push(ue),V.push(z)}}}return r.sequenceExecute(_,e).result?(t.pushUndoRedo({unitID:n,redoMutations:_,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(h.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:p.UpdateRuleType.OPTIONS,payload:u}},m=[{id:p.UpdateDataValidationMutation.id,params:c}],g={unitId:i,subUnitId:n,ruleId:l,payload:{type:p.UpdateRuleType.OPTIONS,payload:p.getRuleOptions(d)}},v=[{id:p.UpdateDataValidationMutation.id,params:g}];return t.pushUndoRedo({unitID:i,redoMutations:m,undoMutations:v}),e.executeCommand(p.UpdateDataValidationMutation.id,c),!0}},Ne={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(h.SheetDataValidationModel);if(!l)return!1;const d=o.get(r.IUndoRedoService),c=u.getRuleObjectMatrix(e,t).clone();c.removeRange(a);const m=c.diff(u.getRules(e,t)),{redoMutations:g,undoMutations:v}=K(e,t,m,o);return d.pushUndoRedo({unitID:e,redoMutations:g,undoMutations:v}),r.sequenceExecute(g,i).result}},Ae={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(h.SheetDataValidationModel),n=o.get(r.IUndoRedoService),l=[...i.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}},ot=(o,s)=>{const e=o.get(h.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: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,i)},index:e.getRuleIndex(t,a,i)}}]},Ue={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(h.SheetDataValidationModel),u=[{id:p.RemoveDataValidationMutation.id,params:s}],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:s.unitId}),i.executeCommand(p.RemoveDataValidationMutation.id,s),!0}},we="SHEET_DATA_VALIDATION_PLUGIN";var be=(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))(be||{}),st=Object.getOwnPropertyDescriptor,lt=(o,s,e,t)=>{for(var a=t>1?void 0:t?st(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},ge=(o,s)=>(e,t)=>s(e,t,o);h.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=y.deserializeRangeWithSheetWithCache(l),d=this._univerInstanceService.getCurrentUnitForType(r.UniverInstanceType.UNIVER_SHEET);let c=d.getActiveSheet();const m=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(m,V).id))return!1}if(!c)return!1;const{startRow:g,endRow:v,startColumn:_,endColumn:R}=u.range;for(let V=g;V<=v;V++)for(let f=_;f<=R;f++){const M=(a=(t=c.getCell(V,f))==null?void 0:t.selectionProtection)==null?void 0:a[0];if((M==null?void 0:M[be.View])===!1)return!1}}return!0}},h.DataValidationFormulaController=lt([ge(0,r.IUniverInstanceService),ge(1,r.IPermissionService),ge(2,r.Inject(y.LexerTreeBuilder))],h.DataValidationFormulaController);const ut="sheets-data-validation.config",Le={};var 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=n(a)||a);return a},pe=(o,s)=>(e,t)=>s(e,t,o);let te=class extends r.Disposable{constructor(s,e,t){super();S(this,"_disposableMap",new Map);S(this,"registerRule",(s,e,t)=>{H(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:p.AddDataValidationMutation.id,params:{unitId:s,subUnitId:e,rule:t,source:"patched"}}],redos:[{id:p.RemoveDataValidationMutation.id,params:{unitId:s,subUnitId:e,ruleId:t.uid,source:"patched"}}]};const c=[],m=[],g=d[0];c.push({id:p.UpdateDataValidationMutation.id,params:{unitId:s,subUnitId:e,ruleId:t.uid,payload:{type:p.UpdateRuleType.ALL,payload:{ranges:g.ranges,formula1:g.formulas[0],formula2:g.formulas[1]}},source:"patched"}}),m.push({id:p.UpdateDataValidationMutation.id,params:{unitId:s,subUnitId:e,ruleId:t.uid,payload:{type:p.UpdateRuleType.ALL,payload:{ranges:a,formula1:i,formula2:n}},source:"patched"}});for(let v=1;v<d.length;v++){const _=d[v],R=r.generateRandomId();c.push({id:p.AddDataValidationMutation.id,params:{unitId:s,subUnitId:e,rule:{...t,uid:R,formula1:_.formulas[0],formula2:_.formulas[1],ranges:_.ranges},source:"patched"}}),m.push({id:p.RemoveDataValidationMutation.id,params:{unitId:s,subUnitId:e,ruleId:R,source:"patched"}})}return{undos:m,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()}))}};te=ct([pe(0,r.Inject(h.SheetDataValidationModel)),pe(1,r.Inject(Z.FormulaRefRangeService)),pe(2,r.Inject(p.DataValidatorRegistryService))],te);var ht=Object.getOwnPropertyDescriptor,mt=(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=n(a)||a);return a},L=(o,s)=>(e,t)=>s(e,t,o);let ae=class extends r.Disposable{constructor(s,e,t,a,i,n){super();S(this,"_disposableMap",new Map);S(this,"registerRule",(s,e,t)=>{H(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,m)=>{const g=this._dataValidationModel.getRuleById(s,e,a);if(!g)return{redos:[],undos:[]};const v=g[c];if(!v||v===m)return{redos:[],undos:[]};const _={unitId:s,subUnitId:e,ruleId:t.uid,payload:{type:p.UpdateRuleType.SETTING,payload:{type:g.type,formula1:g.formula1,formula2:g.formula2,[c]:m}},source:"patched"},R={unitId:s,subUnitId:e,ruleId:t.uid,payload:{type:p.UpdateRuleType.SETTING,payload:{type:g.type,formula1:g.formula1,formula2:g.formula2}},source:"patched"},V=[{id:p.UpdateDataValidationMutation.id,params:_}],f=[{id:p.UpdateDataValidationMutation.id,params:R}];return{redos:V,undos:f}},u=this._dataValidationFormulaService.getRuleFormulaInfo(s,e,a);if(u){const[c,m]=u;if(c){const g=this._formulaRefRangeService.registerFormula(s,e,c.text,v=>l("formula1",v));n.add(()=>g.dispose())}if(m){const g=this._formulaRefRangeService.registerFormula(s,e,m.text,v=>l("formula2",v));n.add(()=>g.dispose())}}}register(s,e,t){var u;const a=d=>{const c=[...t.ranges],g=c.map(_=>D.handleCommonDefaultRangeChangeWithEffectRefCommands(_,d)).filter(_=>!!_).flat();if(r.isRangesEqual(g,c))return{redos:[],undos:[]};if(g.length){const _={unitId:s,subUnitId:e,ruleId:t.uid,payload:{type:p.UpdateRuleType.RANGE,payload:g},source:"patched"},R=[{id:p.UpdateDataValidationMutation.id,params:_}],V=[{id:p.UpdateDataValidationMutation.id,params:{unitId:s,subUnitId:e,ruleId:t.uid,payload:{type:p.UpdateRuleType.RANGE,payload:c},source:"patched"}}];return{redos:R,undos:V}}else{const _={unitId:s,subUnitId:e,ruleId:t.uid},R=[{id:p.RemoveDataValidationMutation.id,params:_}],V=ot(this._injector,_);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()}))}};ae=mt([L(0,r.Inject(h.SheetDataValidationModel)),L(1,r.Inject(r.Injector)),L(2,r.Inject(D.RefRangeService)),L(3,r.Inject(h.DataValidationFormulaService)),L(4,r.Inject(Z.FormulaRefRangeService)),L(5,r.Inject(p.DataValidatorRegistryService))],ae);var gt=Object.getOwnPropertyDescriptor,pt=(o,s,e,t)=>{for(var a=t>1?void 0:t?gt(s,e):s,i=o.length-1,n;i>=0;i--)(n=o[i])&&(a=n(a)||a);return a},Se=(o,s)=>(e,t)=>s(e,t,o);let ie=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:p.RemoveDataValidationMutation.id,params:u}],undos:[{id:p.AddDataValidationMutation.id,params:d}]}}else if(o.id===D.CopySheetCommand.id){const e=o.params,{unitId:t,subUnitId:a,targetSubUnitId:i}=e;if(!t||!a||!i)return{redos:[],undos:[]};const n=this._sheetDataValidationModel.getRules(t,a);if(n.length===0)return{redos:[],undos:[]};const l=n.map(u=>({...u,uid:r.generateRandomId(6)}));return{redos:[{id:p.AddDataValidationMutation.id,params:{unitId:t,subUnitId:i,rule:l,source:"patched"}}],undos:[{id:p.RemoveDataValidationMutation.id,params:{unitId:t,subUnitId:i,ruleId:l.map(u=>u.uid),source:"patched"}}]}}return{redos:[],undos:[]}}}))}};ie=pt([Se(0,r.Inject(D.SheetInterceptorService)),Se(1,r.Inject(r.IUniverInstanceService)),Se(2,r.Inject(h.SheetDataValidationModel))],ie);class St extends p.BaseDataValidator{constructor(){super(...arguments);S(this,"id",r.DataValidationType.ANY);S(this,"title","dataValidation.any.title");S(this,"operators",[]);S(this,"scopes",["sheet"]);S(this,"order",0);S(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 ft extends p.BaseDataValidator{constructor(){super(...arguments);S(this,"id",r.DataValidationType.CUSTOM);S(this,"title","dataValidation.custom.title");S(this,"operators",[]);S(this,"scopes",["sheet"]);S(this,"order",60);S(this,"_customFormulaService",this.injector.get(h.DataValidationCustomFormulaService));S(this,"_lexerTreeBuilder",this.injector.get(y.LexerTreeBuilder))}validatorFormula(e,t,a){var d;const i=r.isFormulaString(e.formula1),n=(d=e.formula1)!=null?d:"",u=this._lexerTreeBuilder.checkIfAddBracket(n)===0&&n.startsWith(y.operatorToken.EQUALS);return{success:i&&u,formula1:i&&u?"":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 E(String(c))&&r.Tools.isDefine(c)&&c!==""?d.t===r.CellValueType.BOOLEAN?!!c:typeof c=="boolean"?c:typeof c=="number"?!!c:typeof c=="string"?E(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 me{constructor(){super(...arguments);S(this,"id",r.DataValidationType.LIST_MULTIPLE);S(this,"title","dataValidation.listMultiple.title");S(this,"offsetFormulaByRange",!1);S(this,"skipDefaultFontRender",()=>!0)}}class vt extends p.BaseDataValidator{constructor(){super(...arguments);S(this,"_customFormulaService",this.injector.get(h.DataValidationCustomFormulaService));S(this,"_lexerTreeBuilder",this.injector.get(y.LexerTreeBuilder));S(this,"id",r.DataValidationType.WHOLE);S(this,"title","dataValidation.whole.title");S(this,"order",10);S(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]);S(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=X(i);return!Number.isNaN(n)&&Number.isInteger(n)}transform(e,t,a){const{value:i}=e;return{...e,value:X(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,m=r.isFormulaString(d)?l==null?void 0:l.v:d,g=r.isFormulaString(c)?u==null?void 0:u.v:c,v=E(`${m}`)&&E(`${g}`);return{formula1:this._parseNumber(m),formula2:this._parseNumber(g),isFormulaValid:v}}validatorFormula(e,t,a){const i=e.operator;if(!i)return{success:!0};const n=r.Tools.isDefine(e.formula1)&&this._isFormulaOrInt(e.formula1),l=r.Tools.isDefine(e.formula2)&&this._isFormulaOrInt(e.formula2),u=J.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.localeService.t(ee.NONE).replace("{TYPE}",this.titleStr);const{transformedFormula1:a,transformedFormula2:i}=k(this._lexerTreeBuilder,e,t);return`${this.localeService.t(ee[e.operator]).replace(G,a!=null?a:"").replace(Y,i!=null?i:"")}`}}var _t=Object.getOwnPropertyDescriptor,Rt=(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=n(a)||a);return a},B=(o,s)=>(e,t)=>s(e,t,o);let re=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(){[St,et,vt,nt,ye,Me,me,Be,ft].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(m=>m.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:[]}}})}};re=Rt([B(0,r.IUniverInstanceService),B(1,r.Inject(p.DataValidatorRegistryService)),B(2,r.Inject(r.Injector)),B(3,r.Inject(D.SheetsSelectionsService)),B(4,r.Inject(D.SheetInterceptorService)),B(5,r.Inject(h.SheetDataValidationModel))],re);var Vt=Object.getOwnPropertyDescriptor,Dt=(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=n(a)||a);return a},ne=(o,s)=>(e,t)=>s(e,t,o);h.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(U.bufferWhen(()=>this._lifecycleService.lifecycle$.pipe(U.filter(e=>e===r.LifecycleStages.Rendered)))).subscribe(s)),this.disposeWithMe(this._dataValidationCacheService.dirtyRanges$.pipe(U.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}`);const l=this._sheetDataValidationModel.getRules(s,e).map(d=>d.ranges).flat(),u=t.map(d=>l.map(c=>r.getIntersectRange(d,c))).flat().filter(Boolean);return Promise.all(u.map(d=>{const c=[];return r.Range.foreach(d,(m,g)=>{c.push(this._validatorByCell(a,i,m,g))}),Promise.all(c)}))}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))}),Promise.all(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]}},h.SheetsDataValidationValidatorService=Dt([ne(0,r.IUniverInstanceService),ne(1,r.Inject(h.SheetDataValidationModel)),ne(2,r.Inject(h.DataValidationCacheService)),ne(3,r.Inject(r.LifecycleService))],h.SheetsDataValidationValidatorService);var Mt=Object.defineProperty,Et=Object.getOwnPropertyDescriptor,yt=(o,s,e)=>s in o?Mt(o,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[s]=e,Tt=(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=n(a)||a);return a},fe=(o,s)=>(e,t)=>s(e,t,o),je=(o,s,e)=>yt(o,typeof s!="symbol"?s+"":s,e);h.UniverSheetsDataValidationPlugin=class extends r.Plugin{constructor(s=Le,e,t,a){super(),this._config=s,this._injector=e,this._commandService=t,this._configService=a;const{...i}=r.merge({},Le,this._config);this._configService.setConfig(ut,i)}onStarting(){[[h.DataValidationCacheService],[h.DataValidationListCacheService],[h.DataValidationFormulaService],[h.DataValidationCustomFormulaService],[h.SheetsDataValidationValidatorService],[h.SheetDataValidationModel],[re],[h.DataValidationFormulaController],[ie],[ae],[te]].forEach(s=>{this._injector.add(s)}),[Ce,Oe,Fe,Ie,Ue,Ae,Ne].forEach(s=>{this._commandService.registerCommand(s)}),this._injector.get(h.DataValidationCacheService),this._injector.get(h.SheetsDataValidationValidatorService),this._injector.get(re),this._injector.get(te),this._injector.get(ae)}onReady(){this._injector.get(ie)}onRendered(){this._injector.get(h.DataValidationFormulaController)}},je(h.UniverSheetsDataValidationPlugin,"pluginName",we),je(h.UniverSheetsDataValidationPlugin,"type",r.UniverInstanceType.UNIVER_SHEET),h.UniverSheetsDataValidationPlugin=Tt([r.DependentOn(p.UniverDataValidationPlugin),fe(1,r.Inject(r.Injector)),fe(2,r.ICommandService),fe(3,r.IConfigService)],h.UniverSheetsDataValidationPlugin);function Ot(o){const e=o.get(D.SheetsSelectionsService).getCurrentSelections().map(i=>i.range);return{uid:r.generateRandomId(6),type:r.DataValidationType.DECIMAL,operator:r.DataValidationOperator.EQUAL,formula1:"100",ranges:e!=null?e:[{startColumn:0,endColumn:0,startRow:0,endRow:0}]}}const Ct="data-validation.custom-formula-input",Ft="data-validation.formula-input",It="data-validation.list-formula-input",Nt="data-validation.checkbox-formula-input";h.AddSheetDataValidationCommand=Ce,h.BASE_FORMULA_INPUT_NAME=Ft,h.CHECKBOX_FORMULA_1=q,h.CHECKBOX_FORMULA_2=x,h.CHECKBOX_FORMULA_INPUT_NAME=Nt,h.CUSTOM_FORMULA_INPUT_NAME=Ct,h.CheckboxValidator=Me,h.ClearRangeDataValidationCommand=Ne,h.DATA_VALIDATION_PLUGIN_NAME=we,h.DateValidator=ye,h.LIST_FORMULA_INPUT_NAME=It,h.ListMultipleValidator=Be,h.ListValidator=me,h.RemoveSheetAllDataValidationCommand=Ae,h.RemoveSheetDataValidationCommand=Ue,h.UpdateSheetDataValidationOptionsCommand=Ie,h.UpdateSheetDataValidationRangeCommand=Oe,h.UpdateSheetDataValidationSettingCommand=Fe,h.createDefaultNewRule=Ot,h.deserializeListOptions=$,h.getCellValueNumber=X,h.getCellValueOrigin=N,h.getDataValidationCellValue=xe,h.getDataValidationDiffMutations=K,h.getFormulaCellData=P,h.getFormulaResult=w,h.getTransformedFormula=k,h.isLegalFormulaResult=E,h.serializeListOptions=qe,h.transformCheckboxValue=Q,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})}));
7
7
 
8
8
 
9
9
  // @univerjs/sheets-data-validation/facade
@@ -11,11 +11,11 @@
11
11
 
12
12
 
13
13
  // @univerjs/sheets-data-validation-ui/index
14
- (function(U,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("@univerjs/sheets"),require("@univerjs/sheets-data-validation"),require("@univerjs/data-validation"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/sheets-numfmt"),require("@univerjs/sheets-ui"),require("@univerjs/design"),require("react"),require("react/jsx-runtime"),require("@univerjs/engine-formula"),require("@univerjs/sheets-formula-ui")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-render","@univerjs/sheets","@univerjs/sheets-data-validation","@univerjs/data-validation","@univerjs/ui","rxjs","@univerjs/sheets-numfmt","@univerjs/sheets-ui","@univerjs/design","react","react/jsx-runtime","@univerjs/engine-formula","@univerjs/sheets-formula-ui"],o):(U=typeof globalThis<"u"?globalThis:U||self,o(U.UniverSheetsDataValidationUi={},U.UniverCore,U.UniverEngineRender,U.UniverSheets,U.UniverSheetsDataValidation,U.UniverDataValidation,U.UniverUi,U.rxjs,U.UniverSheetsNumfmt,U.UniverSheetsUi,U.UniverDesign,U.React,U.React,U.UniverEngineFormula,U.UniverSheetsFormulaUi))})(this,(function(U,o,O,Y,C,X,b,ae,At,$,M,R,p,Ye,Xe){"use strict";var lr=Object.defineProperty;var dr=(U,o,O)=>o in U?lr(U,o,{enumerable:!0,configurable:!0,writable:!0,value:O}):U[o]=O;var P=(U,o,O)=>dr(U,typeof o!="symbol"?o+"":o,O);var xe;var Lt=Object.getOwnPropertyDescriptor,Pt=(e,t,n,r)=>{for(var a=r>1?void 0:r?Lt(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},ht=(e,t)=>(n,r)=>t(n,r,e);let de=class extends o.Disposable{constructor(t,n){super();P(this,"_open$",new ae.BehaviorSubject(!1));P(this,"open$",this._open$.pipe(ae.distinctUntilChanged()));P(this,"_activeRule");P(this,"_activeRule$",new ae.BehaviorSubject(void 0));P(this,"activeRule$",this._activeRule$.asObservable());P(this,"_closeDisposable",null);this._univerInstanceService=t,this._sidebarService=n,this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(o.UniverInstanceType.UNIVER_SHEET).pipe(ae.filter(r=>!r)).subscribe(()=>{this.close()})),this.disposeWithMe(this._sidebarService.sidebarOptions$.subscribe(r=>{r.id===Pe&&(r.visible||setTimeout(()=>{this._sidebarService.sidebarOptions$.next({visible:!1})}))}))}get activeRule(){return this._activeRule}get isOpen(){return this._open$.getValue()}dispose(){var t;super.dispose(),this._open$.next(!1),this._open$.complete(),this._activeRule$.complete(),(t=this._closeDisposable)==null||t.dispose()}open(){this._open$.next(!0)}close(){var t;this._open$.next(!1),(t=this._closeDisposable)==null||t.dispose()}setCloseDisposable(t){this._closeDisposable=o.toDisposable(()=>{t.dispose(),this._closeDisposable=null})}setActiveRule(t){this._activeRule=t,this._activeRule$.next(t)}};de=Pt([ht(0,o.IUniverInstanceService),ht(1,b.ISidebarService)],de);const ve="#ECECEC",ze="sheets-data-validation-ui.config",Le={};var Ut=Object.getOwnPropertyDescriptor,Ft=(e,t,n,r)=>{for(var a=r>1?void 0:r?Ut(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},Ie=(e,t)=>(n,r)=>t(n,r,e);let Ce=class extends o.Disposable{constructor(e,t,n,r,a,i){super(),this._sheetInterceptorService=e,this._dataValidationModel=t,this._dataValidatorRegistryService=n,this._dialogService=r,this._localeService=a,this._sheetsDataValidationValidatorService=i,this._initEditorBridgeInterceptor()}_initEditorBridgeInterceptor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(Y.VALIDATE_CELL,{handler:async(e,t,n)=>{const r=await e,{row:a,col:i,unitId:s,subUnitId:d}=t,l=this._dataValidationModel.getRuleIdByLocation(s,d,a,i),c=l?this._dataValidationModel.getRuleById(s,d,l):void 0;if(r===!1)return n(Promise.resolve(!1));if(!c||c.errorStyle!==o.DataValidationErrorStyle.STOP)return n(Promise.resolve(!0));const h=this._dataValidatorRegistryService.getValidatorItem(c.type);return!h||await this._sheetsDataValidationValidatorService.validatorCell(s,d,a,i)===o.DataValidationStatus.VALID?n(Promise.resolve(!0)):(this._dialogService.open({width:368,title:{title:this._localeService.t("dataValidation.alert.title")},id:"reject-input-dialog",children:{title:h.getRuleFinalError(c,{row:a,col:i,unitId:s,subUnitId:d})},footer:{title:R.createElement(M.Button,{variant:"primary",onClick:()=>this._dialogService.close("reject-input-dialog")},this._localeService.t("dataValidation.alert.ok"))},onClose:()=>{this._dialogService.close("reject-input-dialog")}}),n(Promise.resolve(!1)))}}))}showReject(e){this._dialogService.open({width:368,title:{title:this._localeService.t("dataValidation.alert.title")},id:"reject-input-dialog",children:{title:e},footer:{title:R.createElement(M.Button,{variant:"primary",onClick:()=>this._dialogService.close("reject-input-dialog")},this._localeService.t("dataValidation.alert.ok"))},onClose:()=>{this._dialogService.close("reject-input-dialog")}})}};Ce=Ft([Ie(0,o.Inject(Y.SheetInterceptorService)),Ie(1,o.Inject(C.SheetDataValidationModel)),Ie(2,o.Inject(X.DataValidatorRegistryService)),Ie(3,b.IDialogService),Ie(4,o.Inject(o.LocaleService)),Ie(5,o.Inject(C.SheetsDataValidationValidatorService))],Ce);var kt=Object.getOwnPropertyDescriptor,Nt=(e,t,n,r)=>{for(var a=r>1?void 0:r?kt(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},oe=(e,t)=>(n,r)=>t(n,r,e);const Ke=e=>{if(e==null||typeof e=="boolean")return;if(e==="")return o.dayjs();if(typeof e=="number"||!Number.isNaN(+e))return o.dayjs(o.numfmt.format("yyyy-MM-dd HH:mm:ss",Number(e)));const t=o.dayjs(e);if(t.isValid())return t};function jt(e,t){const n=At.getPatternType(t);if(e===n)return t;switch(e){case"datetime":return"yyyy-MM-dd hh:mm:ss";case"date":return"yyyy-MM-dd";case"time":return"HH:mm:ss"}}let ge=class extends o.Disposable{constructor(t,n,r,a,i,s,d,l,c,h,g){super();P(this,"_activeDropdown");P(this,"_activeDropdown$",new ae.Subject);P(this,"_currentPopup",null);P(this,"activeDropdown$",this._activeDropdown$.asObservable());P(this,"_zenVisible",!1);this._univerInstanceService=t,this._dataValidatorRegistryService=n,this._zenZoneService=r,this._dataValidationModel=a,this._sheetsSelectionsService=i,this._cellDropdownManagerService=s,this._sheetDataValidationModel=d,this._commandService=l,this._editorBridgeService=c,this._injector=h,this._configService=g,this._init(),this._initSelectionChange(),this.disposeWithMe(()=>{this._activeDropdown$.complete()})}get activeDropdown(){return this._activeDropdown}_init(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(t=>{this._zenVisible=t,t&&this.hideDropdown()}))}_getDropdownByCell(t,n,r,a){const i=t?this._univerInstanceService.getUnit(t,o.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET);if(!i)return;const s=n?i.getSheetBySheetId(n):i.getActiveSheet();if(!s)return;const d=this._dataValidationModel.getRuleByLocation(i.getUnitId(),s.getSheetId(),r,a);if(!d)return;const l=this._dataValidatorRegistryService.getValidatorItem(d.type);return l==null?void 0:l.dropdownType}_initSelectionChange(){this.disposeWithMe(this._sheetsSelectionsService.selectionMoveEnd$.subscribe(t=>{t&&t.every(n=>!(n.primary&&this._getDropdownByCell(n.primary.unitId,n.primary.sheetId,n.primary.actualRow,n.primary.actualColumn)))&&this.hideDropdown()}))}showDropdown(t){var A,T,w,y;const{location:n}=t,{row:r,col:a,unitId:i,subUnitId:s,workbook:d,worksheet:l}=n;if(this._currentPopup&&this._currentPopup.dispose(),this._zenVisible)return;this._activeDropdown=t,this._activeDropdown$.next(this._activeDropdown);const c=this._sheetDataValidationModel.getRuleByLocation(i,s,r,a);if(!c)return;const h=this._dataValidatorRegistryService.getValidatorItem(c.type);if(!(h!=null&&h.dropdownType))return;let g;const u=async(f,D)=>{var L,k,W;if(!f)return!0;const I=f,m=l.getCell(r,a),E=I.format(D==="date"?"YYYY-MM-DD 00:00:00":"YYYY-MM-DD HH:mm:ss"),j=(L=o.numfmt.parseDate(E))==null?void 0:L.v,H=D==="time"?j%1:j,F=d.getStyles().getStyleByCell(m),B=(W=(k=F==null?void 0:F.n)==null?void 0:k.pattern)!=null?W:"";return c.errorStyle!==o.DataValidationErrorStyle.STOP||await h.validator({value:H,unitId:i,subUnitId:s,row:r,column:a,worksheet:l,workbook:d,interceptValue:E.replace("Z","").replace("T"," "),t:o.CellValueType.NUMBER},c)?(await this._commandService.executeCommand(Y.SetRangeValuesCommand.id,{unitId:i,subUnitId:s,range:{startColumn:a,endColumn:a,startRow:r,endRow:r},value:{v:H,t:2,p:null,f:null,si:null,s:{n:{pattern:jt(D,B)}}}}),await this._commandService.executeCommand($.SetCellEditVisibleOperation.id,{visible:!1,eventType:O.DeviceInputEventType.Keyboard,unitId:i,keycode:b.KeyCode.ESC}),!0):(this._injector.has(Ce)&&this._injector.get(Ce).showReject(h.getRuleFinalError(c,{row:r,col:a,unitId:i,subUnitId:s})),!1)};let S;switch(h.dropdownType){case X.DataValidatorDropdownType.DATE:{const f=C.getCellValueOrigin(l.getCellRaw(r,a)),D=Ke(f),I=!!((A=c.bizInfo)!=null&&A.showTime);S={location:n,type:"datepicker",props:{showTime:I,onChange:m=>u(m,I?"datetime":"date"),defaultValue:D,patternType:"date"}};break}case X.DataValidatorDropdownType.TIME:{const f=C.getCellValueOrigin(l.getCellRaw(r,a)),D=Ke(f);S={location:n,type:"datepicker",props:{onChange:I=>u(I,"time"),defaultValue:D,patternType:"time"}};break}case X.DataValidatorDropdownType.DATETIME:{const f=C.getCellValueOrigin(l.getCellRaw(r,a)),D=Ke(f);S={location:n,type:"datepicker",props:{onChange:I=>u(I,"datetime"),defaultValue:D,patternType:"datetime"}};break}case X.DataValidatorDropdownType.LIST:case X.DataValidatorDropdownType.MULTIPLE_LIST:{const f=h.dropdownType===X.DataValidatorDropdownType.MULTIPLE_LIST,D=async F=>{const B=C.serializeListOptions(F),L={unitId:i,subUnitId:s,range:{startColumn:a,endColumn:a,startRow:r,endRow:r},value:{v:B,p:null,f:null,si:null}};return this._commandService.executeCommand(Y.SetRangeValuesCommand.id,L),this._editorBridgeService.isVisible().visible&&await this._commandService.executeCommand($.SetCellEditVisibleOperation.id,{visible:!1,eventType:O.DeviceInputEventType.Keyboard,unitId:i,keycode:b.KeyCode.ESC}),!f},I=(c==null?void 0:c.renderMode)===o.DataValidationRenderMode.CUSTOM||(c==null?void 0:c.renderMode)===void 0,m=h.getListWithColor(c,i,s),E=C.getDataValidationCellValue(l.getCellRaw(r,a)),j=()=>{this._commandService.executeCommand(fe.id,{ruleId:c.uid}),g==null||g.dispose()},H=m.map(F=>({label:F.label,value:F.label,color:I||F.color?F.color||ve:"transparent"}));S={location:n,type:"list",props:{onChange:F=>D(F),options:H,onEdit:j,defaultValue:E,multiple:f,showEdit:(w=(T=this._configService.getConfig(ze))==null?void 0:T.showEditOnDropdown)!=null?w:!0}};break}case X.DataValidatorDropdownType.CASCADE:{S={type:"cascader",props:{onChange:D=>{const I={unitId:i,subUnitId:s,range:{startColumn:a,endColumn:a,startRow:r,endRow:r},value:{v:D.join("/"),p:null,f:null,si:null}};return this._commandService.syncExecuteCommand(Y.SetRangeValuesCommand.id,I),this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand($.SetCellEditVisibleOperation.id,{visible:!1,eventType:O.DeviceInputEventType.Keyboard,unitId:i,keycode:b.KeyCode.ESC}),!0},defaultValue:C.getDataValidationCellValue(l.getCellRaw(r,a)).split("/"),options:JSON.parse((y=c.formula1)!=null?y:"[]")},location:n};break}case X.DataValidatorDropdownType.COLOR:{S={type:"color",props:{onChange:D=>{const I={unitId:i,subUnitId:s,range:{startColumn:a,endColumn:a,startRow:r,endRow:r},value:{v:D,p:null,f:null,si:null}};return this._commandService.syncExecuteCommand(Y.SetRangeValuesCommand.id,I),this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand($.SetCellEditVisibleOperation.id,{visible:!1,eventType:O.DeviceInputEventType.Keyboard,unitId:i,keycode:b.KeyCode.ESC}),!0},defaultValue:C.getDataValidationCellValue(l.getCellRaw(r,a))},location:n};break}default:throw new Error("[DataValidationDropdownManagerService]: unknown type!")}if(g=this._cellDropdownManagerService.showDropdown({...S,onHide:()=>{this._activeDropdown=null,this._activeDropdown$.next(null)}}),!g)throw new Error("[DataValidationDropdownManagerService]: cannot show dropdown!");const v=new o.DisposableCollection;v.add(g),v.add({dispose:()=>{var f,D;(D=(f=this._activeDropdown)==null?void 0:f.onHide)==null||D.call(f)}}),this._currentPopup=v}hideDropdown(){this._activeDropdown&&(this._currentPopup&&this._currentPopup.dispose(),this._currentPopup=null,this._activeDropdown=null,this._activeDropdown$.next(null))}showDataValidationDropdown(t,n,r,a,i){const s=this._univerInstanceService.getUnit(t,o.UniverInstanceType.UNIVER_SHEET);if(!s)return;const d=s.getSheetBySheetId(n);if(!d)return;const l=this._dataValidationModel.getRuleByLocation(s.getUnitId(),d.getSheetId(),r,a);if(!l)return;const c=this._dataValidatorRegistryService.getValidatorItem(l.type);if(!c||!c.dropdownType){this.hideDropdown();return}this.showDropdown({location:{workbook:s,worksheet:d,row:r,col:a,unitId:t,subUnitId:n},onHide:i})}};ge=Nt([oe(0,o.IUniverInstanceService),oe(1,o.Inject(X.DataValidatorRegistryService)),oe(2,b.IZenZoneService),oe(3,o.Inject(C.SheetDataValidationModel)),oe(4,o.Inject(Y.SheetsSelectionsService)),oe(5,o.Inject($.ISheetCellDropdownManagerService)),oe(6,o.Inject(C.SheetDataValidationModel)),oe(7,o.ICommandService),oe(8,$.IEditorBridgeService),oe(9,o.Inject(o.Injector)),oe(10,o.IConfigService)],ge);const Pe="DataValidationPanel",fe={id:"data-validation.operation.open-validation-panel",type:o.CommandType.OPERATION,handler(e,t){if(!t)return!1;const{ruleId:n,isAdd:r}=t,a=e.get(de),i=e.get(X.DataValidationModel),s=e.get(o.IUniverInstanceService),d=e.get(b.ISidebarService),l=Y.getSheetCommandTarget(s);if(!l)return!1;const{unitId:c,subUnitId:h}=l,g=n?i.getRuleById(c,h,n):void 0;a.open(),a.setActiveRule(g&&{unitId:c,subUnitId:h,rule:g});const u=d.open({id:Pe,header:{title:r?"dataValidation.panel.addTitle":"dataValidation.panel.title"},children:{label:Pe},width:312,onClose:()=>a.close()});return a.setCloseDisposable(u),!0}},Ze={id:"data-validation.operation.close-validation-panel",type:o.CommandType.OPERATION,handler(e){return e.get(de).close(),!0}},pt={id:"data-validation.operation.toggle-validation-panel",type:o.CommandType.OPERATION,handler(e){const t=e.get(o.ICommandService),n=e.get(de);return n.open(),n.isOpen?t.executeCommand(Ze.id):t.executeCommand(fe.id),!0}},Ue={type:o.CommandType.OPERATION,id:"sheet.operation.show-data-validation-dropdown",handler(e,t){if(!t)return!1;const n=e.get(ge),{unitId:r,subUnitId:a,row:i,column:s}=t,d=n.activeDropdown,l=d==null?void 0:d.location;return l&&l.unitId===r&&l.subUnitId===a&&l.row===i&&l.col===s||n.showDataValidationDropdown(r,a,i,s),!0}},vt={type:o.CommandType.OPERATION,id:"sheet.operation.hide-data-validation-dropdown",handler(e,t){return t?(e.get(ge).hideDropdown(),!0):!1}},Fe={type:o.CommandType.COMMAND,id:"data-validation.command.addRuleAndOpen",handler(e){const t=e.get(o.IUniverInstanceService),n=Y.getSheetCommandTarget(t);if(!n)return!1;const{workbook:r,worksheet:a}=n,i=C.createDefaultNewRule(e),s=e.get(o.ICommandService),d=r.getUnitId(),l=a.getSheetId(),c={rule:i,unitId:d,subUnitId:l};return s.syncExecuteCommand(C.AddSheetDataValidationCommand.id,c)?(s.syncExecuteCommand(fe.id,{ruleId:i.uid,isAdd:!0}),!0):!1}};var Bt=Object.getOwnPropertyDescriptor,Wt=(e,t,n,r)=>{for(var a=r>1?void 0:r?Bt(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},ye=(e,t)=>(n,r)=>t(n,r,e);const me="SHEET_DATA_VALIDATION_ALERT";let Oe=class extends o.Disposable{constructor(e,t,n,r,a,i){super(),this._hoverManagerService=e,this._cellAlertManagerService=t,this._univerInstanceService=n,this._localeService=r,this._zenZoneService=a,this._dataValidationModel=i,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(ae.debounceTime(100)).subscribe(e=>{var t;if(e){const n=this._univerInstanceService.getUnit(e.location.unitId,o.UniverInstanceType.UNIVER_SHEET),r=n.getSheetBySheetId(e.location.subUnitId);if(!r)return;const a=this._dataValidationModel.getRuleByLocation(e.location.unitId,e.location.subUnitId,e.location.row,e.location.col);if(!a){this._cellAlertManagerService.removeAlert(me);return}if(this._dataValidationModel.validator(a,{...e.location,workbook:n,worksheet:r})===o.DataValidationStatus.INVALID){const s=this._cellAlertManagerService.currentAlert.get(me),d=(t=s==null?void 0:s.alert)==null?void 0:t.location;if(d&&d.row===e.location.row&&d.col===e.location.col&&d.subUnitId===e.location.subUnitId&&d.unitId===e.location.unitId){this._cellAlertManagerService.removeAlert(me);return}const l=this._dataValidationModel.getValidator(a.type);if(!l){this._cellAlertManagerService.removeAlert(me);return}this._cellAlertManagerService.showAlert({type:$.CellAlertType.ERROR,title:this._localeService.t("dataValidation.error.title"),message:l==null?void 0:l.getRuleFinalError(a,e.location),location:e.location,width:200,height:74,key:me});return}}this._cellAlertManagerService.removeAlert(me)}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._cellAlertManagerService.removeAlert(me)}))}};Oe=Wt([ye(0,o.Inject($.HoverManagerService)),ye(1,o.Inject($.CellAlertManagerService)),ye(2,o.IUniverInstanceService),ye(3,o.Inject(o.LocaleService)),ye(4,b.IZenZoneService),ye(5,o.Inject(C.SheetDataValidationModel))],Oe);var $t=Object.getOwnPropertyDescriptor,Ht=(e,t,n,r)=>{for(var a=r>1?void 0:r?$t(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},Ge=(e,t)=>(n,r)=>t(n,r,e);let we=class extends o.Disposable{constructor(e,t,n){super(),this._autoFillService=e,this._sheetDataValidationModel=t,this._injector=n,this._initAutoFill()}_initAutoFill(){const e=()=>({redos:[],undos:[]}),t=(r,a)=>{const{source:i,target:s,unitId:d,subUnitId:l}=r,c=this._sheetDataValidationModel.getRuleObjectMatrix(d,l).clone(),h=$.virtualizeDiscreteRanges([i,s]),[g,u]=h.ranges,{mapFunc:S}=h,v={row:g.startRow,col:g.startColumn},A=$.getAutoFillRepeatRange(g,u),T=new o.ObjectMatrix,w=new Set;A.forEach(m=>{const E=m.repeatStartCell,j=m.relativeRange,H={startRow:v.row,startColumn:v.col,endColumn:v.col,endRow:v.row},F={startRow:E.row,startColumn:E.col,endColumn:E.col,endRow:E.row};o.Range.foreach(j,(B,L)=>{const k=o.Rectangle.getPositionRange({startRow:B,startColumn:L,endColumn:L,endRow:B},H),{row:W,col:K}=S(k.startRow,k.startColumn),J=this._sheetDataValidationModel.getRuleIdByLocation(d,l,W,K)||"",ne=o.Rectangle.getPositionRange({startRow:B,startColumn:L,endColumn:L,endRow:B},F),{row:Z,col:re}=S(ne.startRow,ne.startColumn);T.setValue(Z,re,J),w.add(J)})});const y=Array.from(w).map(m=>({id:m,ranges:o.queryObjectMatrix(T,E=>E===m)}));c.addRangeRules(y);const f=c.diff(this._sheetDataValidationModel.getRules(d,l)),{redoMutations:D,undoMutations:I}=C.getDataValidationDiffMutations(d,l,f,this._injector,"patched",a===$.APPLY_TYPE.ONLY_FORMAT);return{undos:I,redos:D}},n={id:C.DATA_VALIDATION_PLUGIN_NAME,onBeforeFillData:r=>{const{source:a,unitId:i,subUnitId:s}=r;for(const d of a.rows)for(const l of a.cols){const c=this._sheetDataValidationModel.getRuleByLocation(i,s,d,l);if(c&&c.type===o.DataValidationType.CHECKBOX){this._autoFillService.setDisableApplyType($.APPLY_TYPE.SERIES,!0);return}}},onFillData:(r,a,i)=>i===$.APPLY_TYPE.COPY||i===$.APPLY_TYPE.ONLY_FORMAT||i===$.APPLY_TYPE.SERIES?t(r,i):e(),onAfterFillData:()=>{}};this.disposeWithMe(this._autoFillService.addHook(n))}};we=Ht([Ge(0,$.IAutoFillService),Ge(1,o.Inject(C.SheetDataValidationModel)),Ge(2,o.Inject(o.Injector))],we);var xt=Object.getOwnPropertyDescriptor,Yt=(e,t,n,r)=>{for(var a=r>1?void 0:r?xt(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},qe=(e,t)=>(n,r)=>t(n,r,e);let De=class extends o.Disposable{constructor(t,n,r){super();P(this,"_copyInfo");this._sheetClipboardService=t,this._sheetDataValidationModel=n,this._injector=r,this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:C.DATA_VALIDATION_PLUGIN_NAME,onBeforeCopy:(t,n,r)=>this._collect(t,n,r),onPasteCells:(t,n,r,a)=>{const{copyType:i=$.COPY_TYPE.COPY,pasteType:s}=a,{range:d}=t||{},{range:l,unitId:c,subUnitId:h}=n;return this._generateMutations(l,{copyType:i,pasteType:s,copyRange:d,unitId:c,subUnitId:h})}})}_collect(t,n,r){const a=new o.ObjectMatrix;this._copyInfo={unitId:t,subUnitId:n,matrix:a};const i=this._injector.invoke(l=>Y.rangeToDiscreteRange(r,l,t,n));if(!i)return;const{rows:s,cols:d}=i;s.forEach((l,c)=>{d.forEach((h,g)=>{const u=this._sheetDataValidationModel.getRuleIdByLocation(t,n,l,h);a.setValue(c,g,u!=null?u:"")})})}_generateMutations(t,n){if(!this._copyInfo)return{redos:[],undos:[]};if(n.copyType===$.COPY_TYPE.CUT)return this._copyInfo=null,{redos:[],undos:[]};if(!this._copyInfo||!this._copyInfo.matrix.getSizeOf()||!n.copyRange)return{redos:[],undos:[]};if([$.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,$.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,$.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,$.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA].includes(n.pasteType))return{redos:[],undos:[]};const{unitId:a,subUnitId:i}=this._copyInfo;if(n.unitId!==a||i!==n.subUnitId){const s=this._sheetDataValidationModel.getRuleObjectMatrix(n.unitId,n.subUnitId).clone(),d=new o.ObjectMatrix,l=new Set,{ranges:[c,h],mapFunc:g}=$.virtualizeDiscreteRanges([n.copyRange,t]),u=$.getRepeatRange(c,h,!0),S=new Map;u.forEach(({startRange:w})=>{var y;(y=this._copyInfo)==null||y.matrix.forValue((f,D,I)=>{const m=o.Rectangle.getPositionRange({startRow:f,endRow:f,startColumn:D,endColumn:D},w),E=`${i}-${I}`,j=this._sheetDataValidationModel.getRuleById(a,i,I);!this._sheetDataValidationModel.getRuleById(n.unitId,n.subUnitId,E)&&j&&S.set(E,{...j,uid:E});const{row:H,col:F}=g(m.startRow,m.startColumn);l.add(E),d.setValue(H,F,E)})});const v=Array.from(l).map(w=>({id:w,ranges:o.queryObjectMatrix(d,y=>y===w)}));s.addRangeRules(v);const{redoMutations:A,undoMutations:T}=C.getDataValidationDiffMutations(n.unitId,n.subUnitId,s.diffWithAddition(this._sheetDataValidationModel.getRules(n.unitId,n.subUnitId),S.values()),this._injector,"patched",!1);return{redos:A,undos:T}}else{const s=this._sheetDataValidationModel.getRuleObjectMatrix(a,i).clone(),d=new o.ObjectMatrix,l=new Set,{ranges:[c,h],mapFunc:g}=$.virtualizeDiscreteRanges([n.copyRange,t]);$.getRepeatRange(c,h,!0).forEach(({startRange:T})=>{var w;(w=this._copyInfo)==null||w.matrix.forValue((y,f,D)=>{const I=o.Rectangle.getPositionRange({startRow:y,endRow:y,startColumn:f,endColumn:f},T),{row:m,col:E}=g(I.startRow,I.startColumn);d.setValue(m,E,D),l.add(D)})});const S=Array.from(l).map(T=>({id:T,ranges:o.queryObjectMatrix(d,w=>w===T)}));s.addRangeRules(S);const{redoMutations:v,undoMutations:A}=C.getDataValidationDiffMutations(a,i,s.diff(this._sheetDataValidationModel.getRules(a,i)),this._injector,"patched",!1);return{redos:v,undos:A}}}};De=Yt([qe(0,$.ISheetClipboardService),qe(1,o.Inject(C.SheetDataValidationModel)),qe(2,o.Inject(o.Injector))],De);var Xt=Object.getOwnPropertyDescriptor,zt=(e,t,n,r)=>{for(var a=r>1?void 0:r?Xt(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},Je=(e,t)=>(n,r)=>t(n,r,e);let Ee=class extends o.Disposable{constructor(e,t,n){super(),this._localeService=e,this._commandService=t,this._sheetPermissionCheckController=n,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===C.AddSheetDataValidationCommand.id){const{unitId:t,subUnitId:n,rule:{ranges:r}}=e.params;this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[Y.WorkbookEditablePermission],rangeTypes:[Y.RangeProtectionPermissionEditPoint],worksheetTypes:[Y.WorksheetEditPermission,Y.WorksheetSetCellStylePermission]},r,t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("permission.dialog.setStyleErr"))}if(e.id===C.UpdateSheetDataValidationRangeCommand.id){const{unitId:t,subUnitId:n,ranges:r}=e.params;this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[Y.WorkbookEditablePermission],rangeTypes:[Y.RangeProtectionPermissionEditPoint],worksheetTypes:[Y.WorksheetEditPermission,Y.WorksheetSetCellStylePermission]},r,t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("permission.dialog.setStyleErr"))}}))}};Ee=zt([Je(0,o.Inject(o.LocaleService)),Je(1,o.ICommandService),Je(2,o.Inject(Y.SheetPermissionCheckController))],Ee);const gt="sheet.menu.data-validation";function Kt(e){return{id:gt,type:b.MenuItemType.SUBITEMS,icon:"DataValidationIcon",tooltip:"dataValidation.title",hidden$:b.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_SHEET),disabled$:$.getCurrentRangeDisable$(e,{workbookTypes:[Y.WorkbookEditablePermission],worksheetTypes:[Y.WorksheetSetCellStylePermission,Y.WorksheetEditPermission],rangeTypes:[Y.RangeProtectionPermissionEditPoint]})}}function Zt(e){return{id:fe.id,title:"dataValidation.panel.title",type:b.MenuItemType.BUTTON}}function Gt(e){return{id:Fe.id,title:"dataValidation.panel.add",type:b.MenuItemType.BUTTON}}const qt={[b.RibbonDataGroup.RULES]:{[gt]:{order:0,menuItemFactory:Kt,[fe.id]:{order:0,menuItemFactory:Zt},[Fe.id]:{order:1,menuItemFactory:Gt}}}};var Jt=Object.getOwnPropertyDescriptor,ft=(e,t,n,r)=>{for(var a=r>1?void 0:r?Jt(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},G=(e,t)=>(n,r)=>t(n,r,e);const mt={tr:{size:6,color:"#fe4b4b"}};let Me=class extends o.RxDisposable{constructor(e,t,n,r,a,i,s,d,l,c,h){super(),this._commandService=e,this._menuManagerService=t,this._renderManagerService=n,this._univerInstanceService=r,this._autoHeightController=a,this._dropdownManagerService=i,this._sheetDataValidationModel=s,this._dataValidatorRegistryService=d,this._sheetInterceptorService=l,this._dataValidationCacheService=c,this._editorBridgeService=h,this._initMenu(),this._initDropdown(),this._initViewModelIntercept(),this._initAutoHeight()}_initMenu(){this._menuManagerService.mergeMenu(qt)}_initDropdown(){this._editorBridgeService&&this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{var n;if(!e.visible){((n=this._dropdownManagerService.activeDropdown)==null?void 0:n.trigger)==="editor-bridge"&&this._dropdownManagerService.hideDropdown();return}const t=this._editorBridgeService.getEditCellState();if(t){const{unitId:r,sheetId:a,row:i,column:s}=t,d=this._univerInstanceService.getUniverSheetInstance(r);if(!d)return;const l=this._sheetDataValidationModel.getRuleByLocation(r,a,i,s);if(!l)return;const c=this._dataValidatorRegistryService.getValidatorItem(l.type);if(!(c!=null&&c.dropdownType))return;const h=d.getActiveSheet();if(!h)return;const g=this._dropdownManagerService.activeDropdown,u=g==null?void 0:g.location;if(u&&u.unitId===r&&u.subUnitId===a&&u.row===i&&u.col===s)return;this._dropdownManagerService.showDropdown({location:{unitId:r,subUnitId:a,row:i,col:s,workbook:d,worksheet:h},trigger:"editor-bridge",closeOnOutSide:!1})}}))}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(Y.INTERCEPTOR_POINT.CELL_CONTENT,{effect:o.InterceptorEffectEnum.Style,priority:Y.InterceptCellContentPriority.DATA_VALIDATION,handler:(e,t,n)=>{var w,y,f,D,I;const{row:r,col:a,unitId:i,subUnitId:s,workbook:d,worksheet:l}=t,c=this._sheetDataValidationModel.getRuleIdByLocation(i,s,r,a);if(!c)return n(e);const h=this._sheetDataValidationModel.getRuleById(i,s,c);if(!h)return n(e);const g=(w=this._dataValidationCacheService.getValue(i,s,r,a))!=null?w:o.DataValidationStatus.VALID,u=this._dataValidatorRegistryService.getValidatorItem(h.type),S=t.rawData;let v;const A={get value(){var m;return v!==void 0||(v=(m=C.getCellValueOrigin(S))!=null?m:null),v}},T={get value(){var m;return`${(m=A.value)!=null?m:""}`}};return(!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,...g===o.DataValidationStatus.INVALID?mt:null},e.customRender=[...(y=e==null?void 0:e.customRender)!=null?y:[],...u!=null&&u.canvasRender?[u.canvasRender]:[]],e.fontRenderExtension={...e==null?void 0:e.fontRenderExtension,isSkip:((f=e==null?void 0:e.fontRenderExtension)==null?void 0:f.isSkip)||((D=u==null?void 0:u.skipDefaultFontRender)==null?void 0:D.call(u,h,A.value,t))},e.interceptorStyle={...e==null?void 0:e.interceptorStyle,...u==null?void 0:u.getExtraStyle(h,T.value,{get style(){const m=d.getStyles();return(typeof(e==null?void 0:e.s)=="string"?m.get(e==null?void 0:e.s):e==null?void 0:e.s)||{}}},r,a)},e.interceptorAutoHeight=()=>{var H,F,B,L,k,W;const m=(F=(H=this._renderManagerService.getRenderById(i))==null?void 0:H.with($.SheetSkeletonManagerService).getSkeletonParam(s))==null?void 0:F.skeleton;if(!m)return;const E=m.worksheet.getMergedCell(r,a),j={data:e,style:m.getStyles().getStyleByCell(e),primaryWithCoord:m.getCellWithCoordByIndex((B=E==null?void 0:E.startRow)!=null?B:r,(L=E==null?void 0:E.startColumn)!=null?L:a),unitId:i,subUnitId:s,row:r,col:a,workbook:d,worksheet:l};return(W=(k=u==null?void 0:u.canvasRender)==null?void 0:k.calcCellAutoHeight)==null?void 0:W.call(k,j)},e.interceptorAutoWidth=()=>{var H,F,B,L,k,W;const m=(F=(H=this._renderManagerService.getRenderById(i))==null?void 0:H.with($.SheetSkeletonManagerService).getSkeletonParam(s))==null?void 0:F.skeleton;if(!m)return;const E=m.worksheet.getMergedCell(r,a),j={data:e,style:m.getStyles().getStyleByCell(e),primaryWithCoord:m.getCellWithCoordByIndex((B=E==null?void 0:E.startRow)!=null?B:r,(L=E==null?void 0:E.startColumn)!=null?L:a),unitId:i,subUnitId:s,row:r,col:a,workbook:d,worksheet:l};return(W=(k=u==null?void 0:u.canvasRender)==null?void 0:k.calcCellAutoWidth)==null?void 0:W.call(k,j)},e.coverable=((I=e==null?void 0:e.coverable)!=null?I:!0)&&!(h.type===o.DataValidationType.LIST||h.type===o.DataValidationType.LIST_MULTIPLE),n(e)}}))}_initAutoHeight(){this._sheetDataValidationModel.ruleChange$.pipe(ae.filter(e=>e.source==="command"),ae.bufferTime(100)).subscribe(e=>{if(e.length===0)return;const t=[];if(e.forEach(n=>{var r;(n.rule.type===o.DataValidationType.LIST_MULTIPLE||n.rule.type===o.DataValidationType.LIST)&&(r=n.rule)!=null&&r.ranges&&t.push(...n.rule.ranges)}),t.length){const n=this._autoHeightController.getUndoRedoParamsOfAutoHeight(t);o.sequenceExecute(n.redos,this._commandService)}})}};Me=ft([G(0,o.ICommandService),G(1,b.IMenuManagerService),G(2,O.IRenderManagerService),G(3,o.IUniverInstanceService),G(4,o.Inject($.AutoHeightController)),G(5,o.Inject(ge)),G(6,o.Inject(C.SheetDataValidationModel)),G(7,o.Inject(X.DataValidatorRegistryService)),G(8,o.Inject(Y.SheetInterceptorService)),G(9,o.Inject(C.DataValidationCacheService)),G(10,o.Optional($.IEditorBridgeService))],Me);let St=class extends o.RxDisposable{constructor(e,t,n,r,a,i,s){super(),this._commandService=e,this._renderManagerService=t,this._autoHeightController=n,this._dataValidatorRegistryService=r,this._sheetInterceptorService=a,this._sheetDataValidationModel=i,this._dataValidationCacheService=s,this._initViewModelIntercept(),this._initAutoHeight()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(Y.INTERCEPTOR_POINT.CELL_CONTENT,{effect:o.InterceptorEffectEnum.Style,priority:Y.InterceptCellContentPriority.DATA_VALIDATION,handler:(e,t,n)=>{var T,w,y,f,D;const{row:r,col:a,unitId:i,subUnitId:s,workbook:d,worksheet:l}=t,c=this._sheetDataValidationModel.getRuleIdByLocation(i,s,r,a);if(!c)return n(e);const h=this._sheetDataValidationModel.getRuleById(i,s,c);if(!h)return n(e);const g=(T=this._dataValidationCacheService.getValue(i,s,r,a))!=null?T:o.DataValidationStatus.VALID,u=this._dataValidatorRegistryService.getValidatorItem(h.type),S=l.getCellRaw(r,a),v=C.getCellValueOrigin(S),A=`${v!=null?v:""}`;return(!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,...g===o.DataValidationStatus.INVALID?mt:null},e.customRender=[...(w=e==null?void 0:e.customRender)!=null?w:[],...u!=null&&u.canvasRender?[u.canvasRender]:[]],e.fontRenderExtension={...e==null?void 0:e.fontRenderExtension,isSkip:((y=e==null?void 0:e.fontRenderExtension)==null?void 0:y.isSkip)||((f=u==null?void 0:u.skipDefaultFontRender)==null?void 0:f.call(u,h,v,t))},e.interceptorStyle={...e==null?void 0:e.interceptorStyle,...u==null?void 0:u.getExtraStyle(h,A,{get style(){const I=d.getStyles();return(typeof(e==null?void 0:e.s)=="string"?I.get(e==null?void 0:e.s):e==null?void 0:e.s)||{}}},r,a)},e.interceptorAutoHeight=()=>{var j,H,F,B,L,k;const I=(H=(j=this._renderManagerService.getRenderById(i))==null?void 0:j.with($.SheetSkeletonManagerService).getSkeletonParam(s))==null?void 0:H.skeleton;if(!I)return;const m=I.worksheet.getMergedCell(r,a),E={data:e,style:I.getStyles().getStyleByCell(e),primaryWithCoord:I.getCellWithCoordByIndex((F=m==null?void 0:m.startRow)!=null?F:r,(B=m==null?void 0:m.startColumn)!=null?B:a),unitId:i,subUnitId:s,row:r,col:a,workbook:d,worksheet:l};return(k=(L=u==null?void 0:u.canvasRender)==null?void 0:L.calcCellAutoHeight)==null?void 0:k.call(L,E)},e.interceptorAutoWidth=()=>{var j,H,F,B,L,k;const I=(H=(j=this._renderManagerService.getRenderById(i))==null?void 0:j.with($.SheetSkeletonManagerService).getSkeletonParam(s))==null?void 0:H.skeleton;if(!I)return;const m=I.worksheet.getMergedCell(r,a),E={data:e,style:I.getStyles().getStyleByCell(e),primaryWithCoord:I.getCellWithCoordByIndex((F=m==null?void 0:m.startRow)!=null?F:r,(B=m==null?void 0:m.startColumn)!=null?B:a),unitId:i,subUnitId:s,row:r,col:a,workbook:d,worksheet:l};return(k=(L=u==null?void 0:u.canvasRender)==null?void 0:L.calcCellAutoWidth)==null?void 0:k.call(L,E)},e.coverable=((D=e==null?void 0:e.coverable)!=null?D:!0)&&!(h.type===o.DataValidationType.LIST||h.type===o.DataValidationType.LIST_MULTIPLE),n(e)}}))}_initAutoHeight(){this._sheetDataValidationModel.ruleChange$.pipe(ae.filter(e=>e.source==="command"),ae.bufferTime(16)).subscribe(e=>{const t=[];if(e.forEach(n=>{var r;(n.rule.type===o.DataValidationType.LIST_MULTIPLE||n.rule.type===o.DataValidationType.LIST)&&(r=n.rule)!=null&&r.ranges&&t.push(...n.rule.ranges)}),t.length){const n=this._autoHeightController.getUndoRedoParamsOfAutoHeight(t);o.sequenceExecute(n.redos,this._commandService)}})}};St=ft([G(0,o.ICommandService),G(1,O.IRenderManagerService),G(2,o.Inject($.AutoHeightController)),G(3,o.Inject(X.DataValidatorRegistryService)),G(4,o.Inject(Y.SheetInterceptorService)),G(5,o.Inject(C.SheetDataValidationModel)),G(6,o.Inject(C.DataValidationCacheService))],St);var Qt=Object.getOwnPropertyDescriptor,en=(e,t,n,r)=>{for(var a=r>1?void 0:r?Qt(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},_t=(e,t)=>(n,r)=>t(n,r,e);let ke=class extends o.Disposable{constructor(e,t,n){super(),this._context=e,this._sheetDataValidationModel=t,this._sheetSkeletonManagerService=n,this._initSkeletonChange()}_initSkeletonChange(){const e=t=>{var r;if(!t.length)return;const n=new Set;t.forEach(a=>{n.add(a.subUnitId)}),n.forEach(a=>{var i;(i=this._sheetSkeletonManagerService.getSkeletonParam(a))==null||i.skeleton.makeDirty(!0)}),(r=this._context.mainComponent)==null||r.makeForceDirty()};this.disposeWithMe(this._sheetDataValidationModel.validStatusChange$.pipe(o.bufferDebounceTime(16)).subscribe(e))}};ke=en([_t(1,o.Inject(C.SheetDataValidationModel)),_t(2,o.Inject($.SheetSkeletonManagerService))],ke);function Se({ref:e,...t}){const{icon:n,id:r,className:a,extend:i,...s}=t,d=`univerjs-icon univerjs-icon-${r} ${a||""}`.trim(),l=R.useRef(`_${rn()}`);return It(n,`${r}`,{defIds:n.defIds,idSuffix:l.current},{ref:e,className:d,...s},i)}function It(e,t,n,r,a){return R.createElement(e.tag,{key:t,...tn(e,n,a),...r},(nn(e,n).children||[]).map((i,s)=>It(i,`${t}-${e.tag}-${s}`,n,void 0,a)))}function tn(e,t,n){const r={...e.attrs};n!=null&&n.colorChannel1&&r.fill==="colorChannel1"&&(r.fill=n.colorChannel1),e.tag==="mask"&&r.id&&(r.id=r.id+t.idSuffix),Object.entries(r).forEach(([i,s])=>{i==="mask"&&typeof s=="string"&&(r[i]=s.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});const{defIds:a}=t;return!a||a.length===0||(e.tag==="use"&&r["xlink:href"]&&(r["xlink:href"]=r["xlink:href"]+t.idSuffix),Object.entries(r).forEach(([i,s])=>{typeof s=="string"&&(r[i]=s.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))})),r}function nn(e,t){var r;const{defIds:n}=t;return!n||n.length===0?e:e.tag==="defs"&&((r=e.children)!=null&&r.length)?{...e,children:e.children.map(a=>typeof a.attrs.id=="string"&&n&&n.includes(a.attrs.id)?{...a,attrs:{...a.attrs,id:a.attrs.id+t.idSuffix}}:a)}:e}function rn(){return Math.random().toString(36).substring(2,8)}Se.displayName="UniverIcon";const an={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 17 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M1.4917 3.07803C1.4917 2.19437 2.20804 1.47803 3.0917 1.47803H5.6917C6.57536 1.47803 7.2917 2.19437 7.2917 3.07803V5.67803C7.2917 6.56168 6.57535 7.27803 5.6917 7.27803H3.0917C2.20804 7.27803 1.4917 6.56168 1.4917 5.67803V3.07803ZM3.0917 2.67803C2.87078 2.67803 2.6917 2.85711 2.6917 3.07803V5.67803C2.6917 5.89894 2.87079 6.07803 3.0917 6.07803H5.6917C5.91261 6.07803 6.0917 5.89894 6.0917 5.67803V3.07803C6.0917 2.85711 5.91261 2.67803 5.6917 2.67803H3.0917Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M14.6175 2.45279C14.8518 2.68711 14.8518 3.06701 14.6175 3.30132L11.6151 6.30365C11.3957 6.52307 11.0451 6.53897 10.8067 6.34031L8.80915 4.67566C8.55458 4.46352 8.52019 4.08518 8.73233 3.83062C8.94447 3.57605 9.32281 3.54166 9.57737 3.7538L11.154 5.06767L13.769 2.45278C14.0033 2.21847 14.3832 2.21848 14.6175 2.45279Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M14.1175 9.19746C14.3518 9.43178 14.3518 9.81168 14.1175 10.046L12.5418 11.6217L14.1175 13.1975C14.3518 13.4318 14.3518 13.8117 14.1175 14.046C13.8832 14.2803 13.5033 14.2803 13.269 14.046L11.6933 12.4703L10.1175 14.046C9.88321 14.2803 9.50331 14.2803 9.269 14.046C9.03468 13.8117 9.03468 13.4318 9.269 13.1975L10.8447 11.6217L9.269 10.046C9.03468 9.81168 9.03468 9.43178 9.269 9.19746C9.50331 8.96315 9.88321 8.96315 10.1175 9.19746L11.6933 10.7732L13.269 9.19746C13.5033 8.96315 13.8832 8.96315 14.1175 9.19746Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M3.0917 8.72168C2.20804 8.72168 1.4917 9.43802 1.4917 10.3217V12.9217C1.4917 13.8053 2.20804 14.5217 3.0917 14.5217H5.6917C6.57535 14.5217 7.2917 13.8053 7.2917 12.9217V10.3217C7.2917 9.43802 6.57536 8.72168 5.6917 8.72168H3.0917ZM2.6917 10.3217C2.6917 10.1008 2.87078 9.92168 3.0917 9.92168H5.6917C5.91261 9.92168 6.0917 10.1008 6.0917 10.3217V12.9217C6.0917 13.1426 5.91261 13.3217 5.6917 13.3217H3.0917C2.87079 13.3217 2.6917 13.1426 2.6917 12.9217V10.3217Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Ct=R.forwardRef(function(t,n){return R.createElement(Se,Object.assign({},t,{id:"data-validation-icon",ref:n,icon:an}))});Ct.displayName="DataValidationIcon";const on={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.3313 1.4667C5.3313 1.13533 5.59993 0.866699 5.9313 0.866699H10.069C10.4004 0.866699 10.669 1.13533 10.669 1.4667C10.669 1.79807 10.4004 2.0667 10.069 2.0667H5.9313C5.59993 2.0667 5.3313 1.79807 5.3313 1.4667Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.09985 3.64443C1.09985 3.31306 1.36848 3.04443 1.69985 3.04443H14.2999C14.6312 3.04443 14.8999 3.31306 14.8999 3.64443C14.8999 3.9758 14.6312 4.24443 14.2999 4.24443H1.69985C1.36848 4.24443 1.09985 3.9758 1.09985 3.64443Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M6.12398 8.30171C6.35829 8.0674 6.73819 8.0674 6.97251 8.30171L8.00007 9.32928L9.02764 8.30171C9.26195 8.0674 9.64185 8.0674 9.87617 8.30171C10.1105 8.53603 10.1105 8.91593 9.87617 9.15024L8.8486 10.1778L9.87617 11.2054C10.1105 11.4397 10.1105 11.8196 9.87617 12.0539C9.64185 12.2882 9.26195 12.2882 9.02764 12.0539L8.00007 11.0263L6.97251 12.0539C6.73819 12.2882 6.35829 12.2882 6.12398 12.0539C5.88966 11.8196 5.88966 11.4397 6.12398 11.2054L7.15154 10.1778L6.12398 9.15024C5.88966 8.91593 5.88966 8.53603 6.12398 8.30171Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M4.75332 5.22217C3.86966 5.22217 3.15332 5.93851 3.15332 6.82217V12.5331C3.15332 13.9691 4.31738 15.1332 5.75332 15.1332H10.2465C11.6825 15.1332 12.8465 13.9691 12.8465 12.5331V6.82217C12.8465 5.93851 12.1302 5.22217 11.2465 5.22217H4.75332ZM4.35332 6.82217C4.35332 6.60125 4.53241 6.42217 4.75332 6.42217H11.2465C11.4674 6.42217 11.6465 6.60125 11.6465 6.82217V12.5331C11.6465 13.3063 11.0197 13.9332 10.2465 13.9332H5.75332C4.98012 13.9332 4.35332 13.3063 4.35332 12.5331V6.82217Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Qe=R.forwardRef(function(t,n){return R.createElement(Se,Object.assign({},t,{id:"delete-icon",ref:n,icon:on}))});Qe.displayName="DeleteIcon";const sn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.6 1.99991C8.60001 1.66854 8.33138 1.39991 8.00001 1.3999C7.66864 1.3999 7.40001 1.66853 7.4 1.9999L7.39996 7.3999H1.9999C1.66853 7.3999 1.3999 7.66853 1.3999 7.9999C1.3999 8.33127 1.66853 8.5999 1.9999 8.5999H7.39995L7.3999 13.9999C7.3999 14.3313 7.66853 14.5999 7.9999 14.5999C8.33127 14.5999 8.5999 14.3313 8.5999 13.9999L8.59995 8.5999H13.9999C14.3313 8.5999 14.5999 8.33127 14.5999 7.9999C14.5999 7.66853 14.3313 7.3999 13.9999 7.3999H8.59996L8.6 1.99991Z"}}]},yt=R.forwardRef(function(t,n){return R.createElement(Se,Object.assign({},t,{id:"increase-icon",ref:n,icon:sn}))});yt.displayName="IncreaseIcon";const ln={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M11.3536 6.14645C11.5488 6.34171 11.5488 6.65829 11.3536 6.85355L8.35355 9.85355C8.15829 10.0488 7.84171 10.0488 7.64645 9.85355L4.64645 6.85355C4.45118 6.65829 4.45118 6.34171 4.64645 6.14645C4.84171 5.95118 5.15829 5.95118 5.35355 6.14645L8 8.79289L10.6464 6.14645C10.8417 5.95118 11.1583 5.95118 11.3536 6.14645Z",fillRule:"evenodd",clipRule:"evenodd"}}]},et=R.forwardRef(function(t,n){return R.createElement(Se,Object.assign({},t,{id:"more-down-icon",ref:n,icon:ln}))});et.displayName="MoreDownIcon";const dn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M4.64645 9.85355C4.45118 9.65829 4.45118 9.34171 4.64645 9.14645L7.64645 6.14645C7.84171 5.95118 8.15829 5.95118 8.35355 6.14645L11.3536 9.14645C11.5488 9.34171 11.5488 9.65829 11.3536 9.85355C11.1583 10.0488 10.8417 10.0488 10.6464 9.85355L8 7.20711L5.35355 9.85355C5.15829 10.0488 4.84171 10.0488 4.64645 9.85355Z",fillRule:"evenodd",clipRule:"evenodd"}}]},wt=R.forwardRef(function(t,n){return R.createElement(Se,Object.assign({},t,{id:"more-up-icon",ref:n,icon:dn}))});wt.displayName="MoreUpIcon";const cn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M6 5C6.55228 5 7 4.55228 7 4C7 3.44772 6.55228 3 6 3C5.44772 3 5 3.44772 5 4C5 4.55228 5.44772 5 6 5Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M6 9C6.55228 9 7 8.55229 7 8C7 7.44772 6.55228 7 6 7C5.44772 7 5 7.44772 5 8C5 8.55229 5.44772 9 6 9Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M7 12C7 12.5523 6.55228 13 6 13C5.44772 13 5 12.5523 5 12C5 11.4477 5.44772 11 6 11C6.55228 11 7 11.4477 7 12Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M10 5C10.5523 5 11 4.55228 11 4C11 3.44772 10.5523 3 10 3C9.44771 3 9 3.44772 9 4C9 4.55228 9.44771 5 10 5Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M11 8C11 8.55229 10.5523 9 10 9C9.44771 9 9 8.55229 9 8C9 7.44772 9.44771 7 10 7C10.5523 7 11 7.44772 11 8Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M10 13C10.5523 13 11 12.5523 11 12C11 11.4477 10.5523 11 10 11C9.44771 11 9 11.4477 9 12C9 12.5523 9.44771 13 10 13Z"}}]},Dt=R.forwardRef(function(t,n){return R.createElement(Se,Object.assign({},t,{id:"sequence-icon",ref:n,icon:cn}))});Dt.displayName="SequenceIcon";function un(e){var c;const t=b.useDependency(o.LocaleService),n=b.useDependency(b.ComponentManager),{value:r,onChange:a,extraComponent:i}=e,[s,d]=R.useState(!1),l=i?n.get(i):null;return p.jsxs(p.Fragment,{children:[p.jsxs("div",{className:"univer-mb-3 univer-flex univer-cursor-pointer univer-items-center univer-text-sm univer-text-gray-900 dark:!univer-text-white",onClick:()=>d(!s),children:[t.t("dataValidation.panel.options"),s?p.jsx(wt,{className:"univer-ml-1"}):p.jsx(et,{className:"univer-ml-1"})]}),s&&p.jsxs(p.Fragment,{children:[l?p.jsx(l,{value:r,onChange:a}):null,p.jsx(M.FormLayout,{label:t.t("dataValidation.panel.invalid"),children:p.jsxs(M.RadioGroup,{value:`${(c=r.errorStyle)!=null?c:o.DataValidationErrorStyle.WARNING}`,onChange:h=>a({...r,errorStyle:+h}),children:[p.jsx(M.Radio,{value:`${o.DataValidationErrorStyle.WARNING}`,children:t.t("dataValidation.panel.showWarning")}),p.jsx(M.Radio,{value:`${o.DataValidationErrorStyle.STOP}`,children:t.t("dataValidation.panel.rejectInput")})]})}),p.jsx(M.FormLayout,{label:t.t("dataValidation.panel.messageInfo"),children:p.jsx(M.Checkbox,{checked:r.showErrorMessage,onChange:()=>a({...r,showErrorMessage:!r.showErrorMessage}),children:t.t("dataValidation.panel.showInfo")})}),r.showErrorMessage?p.jsx(M.FormLayout,{children:p.jsx(M.Input,{value:r.error,onChange:h=>a({...r,error:h})})}):null]})]})}const hn=e=>o.debounce(async(t,n,r,a)=>{const i=await e.executeCommand(t,n,r);a==null||a(i)},1e3);function pn(e,t,n){var r,a,i,s;return t?((a=(r=e.getUnit(t))==null?void 0:r.getSheetBySheetName(n))==null?void 0:a.getSheetId())||"":((s=(i=e.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET))==null?void 0:i.getSheetBySheetName(n))==null?void 0:s.getSheetId())||""}function vn(){var V,x;const[e,t]=R.useState(0),n=b.useDependency(de),r=b.useObservable(n.activeRule$,n.activeRule),{unitId:a,subUnitId:i,rule:s}=r||{},d=s.uid,l=b.useDependency(X.DataValidatorRegistryService),c=b.useDependency(o.IUniverInstanceService),h=b.useDependency(b.ComponentManager),g=b.useDependency(o.ICommandService),u=b.useDependency(X.DataValidationModel),S=b.useDependency(o.LocaleService),[v,A]=R.useState(s),T=l.getValidatorItem(v.type),[w,y]=R.useState(!1),f=l.getValidatorsByScope(X.DataValidatorRegistryScope.SHEET),[D,I]=R.useState(()=>v.ranges.map(_=>({unitId:"",sheetId:"",range:_}))),m=R.useMemo(()=>hn(g),[g]),[E,j]=R.useState(!1),[H,F]=R.useState(!1),B=R.useRef(null),L=b.useDependency(Y.SheetsSelectionsService);if(R.useEffect(()=>()=>{const _=L.getCurrentLastSelection();_&&L.setSelections([_])},[L]),R.useEffect(()=>{g.onCommandExecuted(_=>{(_.id===o.UndoCommand.id||_.id===o.RedoCommand.id)&&setTimeout(()=>{const N=u.getRuleById(a,i,d);t(z=>z+1),N&&(A(N),I(N.ranges.map(z=>({unitId:"",sheetId:"",range:z}))))},20)})},[g,u,d,i,a]),!T)return null;const k=T.operators,W=T.operatorNames,K=v.operator?X.TWO_FORMULA_OPERATOR_COUNT.includes(v.operator):!1,J=()=>{var _,N,z;(N=(_=B.current)==null?void 0:_.editor)!=null&&N.isFocus()&&ne((z=B.current)==null?void 0:z.getValue()),!(!v.ranges.length||E)&&(T.validatorFormula(v,a,i).success?n.setActiveRule(null):y(!0))},ne=b.useEvent(_=>{const N=_.split(",").filter(Boolean).map(Ye.deserializeRangeWithSheet).map(te=>{const Ot=te.sheetName;if(Ot){const sr=pn(c,te.unitId,Ot);return{...te,sheetId:sr}}return{...te,sheetId:""}});if(o.isUnitRangesEqual(N,D))return;I(N);const z=N.filter(te=>(!te.unitId||te.unitId===a)&&(!te.sheetId||te.sheetId===i)).map(te=>te.range);if(A({...v,ranges:z}),z.length===0)return;const le={unitId:a,subUnitId:i,ruleId:d,ranges:z};m(C.UpdateSheetDataValidationRangeCommand.id,le)}),Z=_=>{if(o.shallowEqual(_,X.getRuleSetting(v)))return;A({...v,..._});const N={unitId:a,subUnitId:i,ruleId:d,setting:_};m(C.UpdateSheetDataValidationSettingCommand.id,N,void 0)},re=async()=>{await g.executeCommand(C.RemoveSheetDataValidationCommand.id,{ruleId:d,unitId:a,subUnitId:i}),n.setActiveRule(null)},ie={type:v.type,operator:v.operator,formula1:v.formula1,formula2:v.formula2,allowBlank:v.allowBlank},he=_=>{const N=l.getValidatorItem(_);if(!N)return;const z=N.operators,le=u.getRuleById(a,i,d),te=_===(le==null?void 0:le.type)||_.includes("list")&&(le!=null&&le.type.includes("list"))?{...le,type:_}:{...v,type:_,operator:z[0],formula1:void 0,formula2:void 0};A(te),g.executeCommand(C.UpdateSheetDataValidationSettingCommand.id,{unitId:a,subUnitId:i,ruleId:v.uid,setting:X.getRuleSetting(te)})},pe=h.get(T.formulaInput),Q=R.useMemo(()=>D.map(_=>Ye.serializeRange(_.range)).join(","),[]),q=X.getRuleOptions(v),ce=_=>{o.shallowEqual(_,X.getRuleOptions(v))||(A({...v,..._}),m(C.UpdateSheetDataValidationOptionsCommand.id,{unitId:a,subUnitId:i,ruleId:d,options:_}))},ee=k.length&&!v.operator;return p.jsxs("div",{"data-u-comp":"data-validation-detail",className:"univer-py-2",children:[p.jsx(M.FormLayout,{label:S.t("dataValidation.panel.range"),error:!v.ranges.length||E?S.t("dataValidation.panel.rangeError"):"",children:p.jsx(Xe.RangeSelector,{selectorRef:B,unitId:a,subUnitId:i,initialValue:Q,onChange:(_,N)=>{var z;!H&&((z=B.current)!=null&&z.verify())&&ne(N)},onFocusChange:(_,N)=>{var z;F(_),!_&&N&&((z=B.current)!=null&&z.verify())&&ne(N)},onVerify:_=>j(!_)})}),p.jsx(M.FormLayout,{label:S.t("dataValidation.panel.type"),children:p.jsx(M.Select,{className:"univer-w-full",value:v.type,options:(V=f==null?void 0:f.sort((_,N)=>_.order-N.order))==null?void 0:V.map(_=>({label:S.t(_.title),value:_.id})),onChange:he})}),k!=null&&k.length?p.jsx(M.FormLayout,{label:S.t("dataValidation.panel.operator"),children:p.jsx(M.Select,{className:"univer-w-full",value:`${v.operator}`,options:[{value:"",label:S.t("dataValidation.operators.legal")},...k.map((_,N)=>({value:`${_}`,label:W[N]}))],onChange:_=>{Z({...ie,operator:_})}})}):null,pe&&!ee?p.jsx(pe,{isTwoFormula:K,value:{formula1:v.formula1,formula2:v.formula2},onChange:_=>{Z({...ie,..._})},showError:w,validResult:T.validatorFormula(v,a,i),unitId:a,subUnitId:i,ruleId:d},e+v.type):null,p.jsx(M.FormLayout,{children:p.jsx(M.Checkbox,{checked:(x=v.allowBlank)!=null?x:!0,onChange:()=>{var _;return Z({...ie,allowBlank:!((_=v.allowBlank)==null||_)})},children:S.t("dataValidation.panel.allowBlank")})}),p.jsx(un,{value:q,onChange:ce,extraComponent:T.optionsInput}),p.jsxs("div",{className:"univer-mt-5 univer-flex univer-flex-row univer-justify-end",children:[p.jsx(M.Button,{className:"univer-ml-3",onClick:re,children:S.t("dataValidation.panel.removeRule")}),p.jsx(M.Button,{className:"univer-ml-3",variant:"primary",onClick:J,children:S.t("dataValidation.panel.done")})]})]})}const gn=e=>{const{rule:t,onClick:n,unitId:r,subUnitId:a,disable:i}=e,s=b.useDependency(X.DataValidatorRegistryService),d=b.useDependency(o.ICommandService),l=b.useDependency($.IMarkSelectionService),c=s.getValidatorItem(t.type),h=R.useRef(void 0),[g,u]=R.useState(!1),S=b.useDependency(o.ThemeService),v=b.useObservable(S.currentTheme$),A=R.useMemo(()=>{var I;const w=S.getColorFromTheme("primary.600"),y=S.getColorFromTheme("loop-color.2"),f=(I=S.getColorFromTheme(y))!=null?I:w,D=new o.ColorKit(f).toRgb();return{fill:`rgba(${D.r}, ${D.g}, ${D.b}, 0.1)`,stroke:f}},[v]),T=w=>{d.executeCommand(C.RemoveSheetDataValidationCommand.id,{ruleId:t.uid,unitId:r,subUnitId:a}),w.stopPropagation()};return R.useEffect(()=>()=>{var w;h.current&&((w=h.current)==null||w.forEach(y=>{y&&l.removeShape(y)}))},[l]),p.jsxs("div",{className:M.clsx(`
14
+ (function(U,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("@univerjs/sheets"),require("@univerjs/sheets-data-validation"),require("@univerjs/data-validation"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/sheets-numfmt"),require("@univerjs/sheets-ui"),require("@univerjs/design"),require("react"),require("react/jsx-runtime"),require("@univerjs/engine-formula"),require("@univerjs/sheets-formula-ui")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-render","@univerjs/sheets","@univerjs/sheets-data-validation","@univerjs/data-validation","@univerjs/ui","rxjs","@univerjs/sheets-numfmt","@univerjs/sheets-ui","@univerjs/design","react","react/jsx-runtime","@univerjs/engine-formula","@univerjs/sheets-formula-ui"],o):(U=typeof globalThis<"u"?globalThis:U||self,o(U.UniverSheetsDataValidationUi={},U.UniverCore,U.UniverEngineRender,U.UniverSheets,U.UniverSheetsDataValidation,U.UniverDataValidation,U.UniverUi,U.rxjs,U.UniverSheetsNumfmt,U.UniverSheetsUi,U.UniverDesign,U.React,U.React,U.UniverEngineFormula,U.UniverSheetsFormulaUi))})(this,(function(U,o,O,Y,C,X,b,ae,At,W,M,R,p,Ye,Xe){"use strict";var lr=Object.defineProperty;var dr=(U,o,O)=>o in U?lr(U,o,{enumerable:!0,configurable:!0,writable:!0,value:O}):U[o]=O;var P=(U,o,O)=>dr(U,typeof o!="symbol"?o+"":o,O);var xe;var Lt=Object.getOwnPropertyDescriptor,Pt=(e,t,n,r)=>{for(var a=r>1?void 0:r?Lt(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},ht=(e,t)=>(n,r)=>t(n,r,e);let de=class extends o.Disposable{constructor(t,n){super();P(this,"_open$",new ae.BehaviorSubject(!1));P(this,"open$",this._open$.pipe(ae.distinctUntilChanged()));P(this,"_activeRule");P(this,"_activeRule$",new ae.BehaviorSubject(void 0));P(this,"activeRule$",this._activeRule$.asObservable());P(this,"_closeDisposable",null);this._univerInstanceService=t,this._sidebarService=n,this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(o.UniverInstanceType.UNIVER_SHEET).pipe(ae.filter(r=>!r)).subscribe(()=>{this.close()})),this.disposeWithMe(this._sidebarService.sidebarOptions$.subscribe(r=>{r.id===Pe&&(r.visible||setTimeout(()=>{this._sidebarService.sidebarOptions$.next({visible:!1})}))}))}get activeRule(){return this._activeRule}get isOpen(){return this._open$.getValue()}dispose(){var t;super.dispose(),this._open$.next(!1),this._open$.complete(),this._activeRule$.complete(),(t=this._closeDisposable)==null||t.dispose()}open(){this._open$.next(!0)}close(){var t;this._open$.next(!1),(t=this._closeDisposable)==null||t.dispose()}setCloseDisposable(t){this._closeDisposable=o.toDisposable(()=>{t.dispose(),this._closeDisposable=null})}setActiveRule(t){this._activeRule=t,this._activeRule$.next(t)}};de=Pt([ht(0,o.IUniverInstanceService),ht(1,b.ISidebarService)],de);const ve="#ECECEC",ze="sheets-data-validation-ui.config",Le={};var Ut=Object.getOwnPropertyDescriptor,Ft=(e,t,n,r)=>{for(var a=r>1?void 0:r?Ut(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},Ie=(e,t)=>(n,r)=>t(n,r,e);let Ce=class extends o.Disposable{constructor(e,t,n,r,a,i){super(),this._sheetInterceptorService=e,this._dataValidationModel=t,this._dataValidatorRegistryService=n,this._dialogService=r,this._localeService=a,this._sheetsDataValidationValidatorService=i,this._initEditorBridgeInterceptor()}_initEditorBridgeInterceptor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(Y.VALIDATE_CELL,{handler:async(e,t,n)=>{const r=await e,{row:a,col:i,unitId:s,subUnitId:d}=t,l=this._dataValidationModel.getRuleIdByLocation(s,d,a,i),c=l?this._dataValidationModel.getRuleById(s,d,l):void 0;if(r===!1)return n(Promise.resolve(!1));if(!c||c.errorStyle!==o.DataValidationErrorStyle.STOP)return n(Promise.resolve(!0));const h=this._dataValidatorRegistryService.getValidatorItem(c.type);return!h||await this._sheetsDataValidationValidatorService.validatorCell(s,d,a,i)===o.DataValidationStatus.VALID?n(Promise.resolve(!0)):(this._dialogService.open({width:368,title:{title:this._localeService.t("dataValidation.alert.title")},id:"reject-input-dialog",children:{title:h.getRuleFinalError(c,{row:a,col:i,unitId:s,subUnitId:d})},footer:{title:R.createElement(M.Button,{variant:"primary",onClick:()=>this._dialogService.close("reject-input-dialog")},this._localeService.t("dataValidation.alert.ok"))},onClose:()=>{this._dialogService.close("reject-input-dialog")}}),n(Promise.resolve(!1)))}}))}showReject(e){this._dialogService.open({width:368,title:{title:this._localeService.t("dataValidation.alert.title")},id:"reject-input-dialog",children:{title:e},footer:{title:R.createElement(M.Button,{variant:"primary",onClick:()=>this._dialogService.close("reject-input-dialog")},this._localeService.t("dataValidation.alert.ok"))},onClose:()=>{this._dialogService.close("reject-input-dialog")}})}};Ce=Ft([Ie(0,o.Inject(Y.SheetInterceptorService)),Ie(1,o.Inject(C.SheetDataValidationModel)),Ie(2,o.Inject(X.DataValidatorRegistryService)),Ie(3,b.IDialogService),Ie(4,o.Inject(o.LocaleService)),Ie(5,o.Inject(C.SheetsDataValidationValidatorService))],Ce);var kt=Object.getOwnPropertyDescriptor,Nt=(e,t,n,r)=>{for(var a=r>1?void 0:r?kt(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},oe=(e,t)=>(n,r)=>t(n,r,e);const Ke=e=>{if(e==null||typeof e=="boolean")return;if(e==="")return o.dayjs();if(typeof e=="number"||!Number.isNaN(+e))return o.dayjs(o.numfmt.format("yyyy-MM-dd HH:mm:ss",Number(e)));const t=o.dayjs(e);if(t.isValid())return t};function jt(e,t){const n=At.getPatternType(t);if(e===n)return t;switch(e){case"datetime":return"yyyy-MM-dd hh:mm:ss";case"date":return"yyyy-MM-dd";case"time":return"HH:mm:ss"}}let ge=class extends o.Disposable{constructor(t,n,r,a,i,s,d,l,c,h,g){super();P(this,"_activeDropdown");P(this,"_activeDropdown$",new ae.Subject);P(this,"_currentPopup",null);P(this,"activeDropdown$",this._activeDropdown$.asObservable());P(this,"_zenVisible",!1);this._univerInstanceService=t,this._dataValidatorRegistryService=n,this._zenZoneService=r,this._dataValidationModel=a,this._sheetsSelectionsService=i,this._cellDropdownManagerService=s,this._sheetDataValidationModel=d,this._commandService=l,this._editorBridgeService=c,this._injector=h,this._configService=g,this._init(),this._initSelectionChange(),this.disposeWithMe(()=>{this._activeDropdown$.complete()})}get activeDropdown(){return this._activeDropdown}_init(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(t=>{this._zenVisible=t,t&&this.hideDropdown()}))}_getDropdownByCell(t,n,r,a){const i=t?this._univerInstanceService.getUnit(t,o.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET);if(!i)return;const s=n?i.getSheetBySheetId(n):i.getActiveSheet();if(!s)return;const d=this._dataValidationModel.getRuleByLocation(i.getUnitId(),s.getSheetId(),r,a);if(!d)return;const l=this._dataValidatorRegistryService.getValidatorItem(d.type);return l==null?void 0:l.dropdownType}_initSelectionChange(){this.disposeWithMe(this._sheetsSelectionsService.selectionMoveEnd$.subscribe(t=>{t&&t.every(n=>!(n.primary&&this._getDropdownByCell(n.primary.unitId,n.primary.sheetId,n.primary.actualRow,n.primary.actualColumn)))&&this.hideDropdown()}))}showDropdown(t){var A,T,w,y;const{location:n}=t,{row:r,col:a,unitId:i,subUnitId:s,workbook:d,worksheet:l}=n;if(this._currentPopup&&this._currentPopup.dispose(),this._zenVisible)return;this._activeDropdown=t,this._activeDropdown$.next(this._activeDropdown);const c=this._sheetDataValidationModel.getRuleByLocation(i,s,r,a);if(!c)return;const h=this._dataValidatorRegistryService.getValidatorItem(c.type);if(!(h!=null&&h.dropdownType))return;let g;const u=async(f,D)=>{var L,k,B;if(!f)return!0;const I=f,m=l.getCell(r,a),E=I.format(D==="date"?"YYYY-MM-DD 00:00:00":"YYYY-MM-DD HH:mm:ss"),j=(L=o.numfmt.parseDate(E))==null?void 0:L.v,$=D==="time"?j%1:j,F=d.getStyles().getStyleByCell(m),H=(B=(k=F==null?void 0:F.n)==null?void 0:k.pattern)!=null?B:"";return c.errorStyle!==o.DataValidationErrorStyle.STOP||await h.validator({value:$,unitId:i,subUnitId:s,row:r,column:a,worksheet:l,workbook:d,interceptValue:E.replace("Z","").replace("T"," "),t:o.CellValueType.NUMBER},c)?(await this._commandService.executeCommand(Y.SetRangeValuesCommand.id,{unitId:i,subUnitId:s,range:{startColumn:a,endColumn:a,startRow:r,endRow:r},value:{v:$,t:2,p:null,f:null,si:null,s:{n:{pattern:jt(D,H)}}}}),await this._commandService.executeCommand(W.SetCellEditVisibleOperation.id,{visible:!1,eventType:O.DeviceInputEventType.Keyboard,unitId:i,keycode:b.KeyCode.ESC}),!0):(this._injector.has(Ce)&&this._injector.get(Ce).showReject(h.getRuleFinalError(c,{row:r,col:a,unitId:i,subUnitId:s})),!1)};let S;switch(h.dropdownType){case X.DataValidatorDropdownType.DATE:{const f=C.getCellValueOrigin(l.getCellRaw(r,a)),D=Ke(f),I=!!((A=c.bizInfo)!=null&&A.showTime);S={location:n,type:"datepicker",props:{showTime:I,onChange:m=>u(m,I?"datetime":"date"),defaultValue:D,patternType:"date"}};break}case X.DataValidatorDropdownType.TIME:{const f=C.getCellValueOrigin(l.getCellRaw(r,a)),D=Ke(f);S={location:n,type:"datepicker",props:{onChange:I=>u(I,"time"),defaultValue:D,patternType:"time"}};break}case X.DataValidatorDropdownType.DATETIME:{const f=C.getCellValueOrigin(l.getCellRaw(r,a)),D=Ke(f);S={location:n,type:"datepicker",props:{onChange:I=>u(I,"datetime"),defaultValue:D,patternType:"datetime"}};break}case X.DataValidatorDropdownType.LIST:case X.DataValidatorDropdownType.MULTIPLE_LIST:{const f=h.dropdownType===X.DataValidatorDropdownType.MULTIPLE_LIST,D=async F=>{const H=C.serializeListOptions(F),L={unitId:i,subUnitId:s,range:{startColumn:a,endColumn:a,startRow:r,endRow:r},value:{v:H,p:null,f:null,si:null}};return this._commandService.executeCommand(Y.SetRangeValuesCommand.id,L),this._editorBridgeService.isVisible().visible&&await this._commandService.executeCommand(W.SetCellEditVisibleOperation.id,{visible:!1,eventType:O.DeviceInputEventType.Keyboard,unitId:i,keycode:b.KeyCode.ESC}),!f},I=(c==null?void 0:c.renderMode)===o.DataValidationRenderMode.CUSTOM||(c==null?void 0:c.renderMode)===void 0,m=h.getListWithColor(c,i,s),E=C.getDataValidationCellValue(l.getCellRaw(r,a)),j=()=>{this._commandService.executeCommand(fe.id,{ruleId:c.uid}),g==null||g.dispose()},$=m.map(F=>({label:F.label,value:F.label,color:I||F.color?F.color||ve:"transparent"}));S={location:n,type:"list",props:{onChange:F=>D(F),options:$,onEdit:j,defaultValue:E,multiple:f,showEdit:(w=(T=this._configService.getConfig(ze))==null?void 0:T.showEditOnDropdown)!=null?w:!0}};break}case X.DataValidatorDropdownType.CASCADE:{S={type:"cascader",props:{onChange:D=>{const I={unitId:i,subUnitId:s,range:{startColumn:a,endColumn:a,startRow:r,endRow:r},value:{v:D.join("/"),p:null,f:null,si:null}};return this._commandService.syncExecuteCommand(Y.SetRangeValuesCommand.id,I),this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(W.SetCellEditVisibleOperation.id,{visible:!1,eventType:O.DeviceInputEventType.Keyboard,unitId:i,keycode:b.KeyCode.ESC}),!0},defaultValue:C.getDataValidationCellValue(l.getCellRaw(r,a)).split("/"),options:JSON.parse((y=c.formula1)!=null?y:"[]")},location:n};break}case X.DataValidatorDropdownType.COLOR:{S={type:"color",props:{onChange:D=>{const I={unitId:i,subUnitId:s,range:{startColumn:a,endColumn:a,startRow:r,endRow:r},value:{v:D,p:null,f:null,si:null}};return this._commandService.syncExecuteCommand(Y.SetRangeValuesCommand.id,I),this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(W.SetCellEditVisibleOperation.id,{visible:!1,eventType:O.DeviceInputEventType.Keyboard,unitId:i,keycode:b.KeyCode.ESC}),!0},defaultValue:C.getDataValidationCellValue(l.getCellRaw(r,a))},location:n};break}default:throw new Error("[DataValidationDropdownManagerService]: unknown type!")}if(g=this._cellDropdownManagerService.showDropdown({...S,onHide:()=>{this._activeDropdown=null,this._activeDropdown$.next(null)}}),!g)throw new Error("[DataValidationDropdownManagerService]: cannot show dropdown!");const v=new o.DisposableCollection;v.add(g),v.add({dispose:()=>{var f,D;(D=(f=this._activeDropdown)==null?void 0:f.onHide)==null||D.call(f)}}),this._currentPopup=v}hideDropdown(){this._activeDropdown&&(this._currentPopup&&this._currentPopup.dispose(),this._currentPopup=null,this._activeDropdown=null,this._activeDropdown$.next(null))}showDataValidationDropdown(t,n,r,a,i){const s=this._univerInstanceService.getUnit(t,o.UniverInstanceType.UNIVER_SHEET);if(!s)return;const d=s.getSheetBySheetId(n);if(!d)return;const l=this._dataValidationModel.getRuleByLocation(s.getUnitId(),d.getSheetId(),r,a);if(!l)return;const c=this._dataValidatorRegistryService.getValidatorItem(l.type);if(!c||!c.dropdownType){this.hideDropdown();return}this.showDropdown({location:{workbook:s,worksheet:d,row:r,col:a,unitId:t,subUnitId:n},onHide:i})}};ge=Nt([oe(0,o.IUniverInstanceService),oe(1,o.Inject(X.DataValidatorRegistryService)),oe(2,b.IZenZoneService),oe(3,o.Inject(C.SheetDataValidationModel)),oe(4,o.Inject(Y.SheetsSelectionsService)),oe(5,o.Inject(W.ISheetCellDropdownManagerService)),oe(6,o.Inject(C.SheetDataValidationModel)),oe(7,o.ICommandService),oe(8,W.IEditorBridgeService),oe(9,o.Inject(o.Injector)),oe(10,o.IConfigService)],ge);const Pe="DataValidationPanel",fe={id:"data-validation.operation.open-validation-panel",type:o.CommandType.OPERATION,handler(e,t){if(!t)return!1;const{ruleId:n,isAdd:r}=t,a=e.get(de),i=e.get(X.DataValidationModel),s=e.get(o.IUniverInstanceService),d=e.get(b.ISidebarService),l=Y.getSheetCommandTarget(s);if(!l)return!1;const{unitId:c,subUnitId:h}=l,g=n?i.getRuleById(c,h,n):void 0;a.open(),a.setActiveRule(g&&{unitId:c,subUnitId:h,rule:g});const u=d.open({id:Pe,header:{title:r?"dataValidation.panel.addTitle":"dataValidation.panel.title"},children:{label:Pe},width:312,onClose:()=>a.close()});return a.setCloseDisposable(u),!0}},Ze={id:"data-validation.operation.close-validation-panel",type:o.CommandType.OPERATION,handler(e){return e.get(de).close(),!0}},pt={id:"data-validation.operation.toggle-validation-panel",type:o.CommandType.OPERATION,handler(e){const t=e.get(o.ICommandService),n=e.get(de);return n.open(),n.isOpen?t.executeCommand(Ze.id):t.executeCommand(fe.id),!0}},Ue={type:o.CommandType.OPERATION,id:"sheet.operation.show-data-validation-dropdown",handler(e,t){if(!t)return!1;const n=e.get(ge),{unitId:r,subUnitId:a,row:i,column:s}=t,d=n.activeDropdown,l=d==null?void 0:d.location;return l&&l.unitId===r&&l.subUnitId===a&&l.row===i&&l.col===s||n.showDataValidationDropdown(r,a,i,s),!0}},vt={type:o.CommandType.OPERATION,id:"sheet.operation.hide-data-validation-dropdown",handler(e,t){return t?(e.get(ge).hideDropdown(),!0):!1}},Fe={type:o.CommandType.COMMAND,id:"data-validation.command.addRuleAndOpen",handler(e){const t=e.get(o.IUniverInstanceService),n=Y.getSheetCommandTarget(t);if(!n)return!1;const{workbook:r,worksheet:a}=n,i=C.createDefaultNewRule(e),s=e.get(o.ICommandService),d=r.getUnitId(),l=a.getSheetId(),c={rule:i,unitId:d,subUnitId:l};return s.syncExecuteCommand(C.AddSheetDataValidationCommand.id,c)?(s.syncExecuteCommand(fe.id,{ruleId:i.uid,isAdd:!0}),!0):!1}};var Bt=Object.getOwnPropertyDescriptor,Wt=(e,t,n,r)=>{for(var a=r>1?void 0:r?Bt(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},ye=(e,t)=>(n,r)=>t(n,r,e);const me="SHEET_DATA_VALIDATION_ALERT";let Oe=class extends o.Disposable{constructor(e,t,n,r,a,i){super(),this._hoverManagerService=e,this._cellAlertManagerService=t,this._univerInstanceService=n,this._localeService=r,this._zenZoneService=a,this._dataValidationModel=i,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(ae.debounceTime(100)).subscribe(e=>{var t;if(e){const n=this._univerInstanceService.getUnit(e.location.unitId,o.UniverInstanceType.UNIVER_SHEET),r=n.getSheetBySheetId(e.location.subUnitId);if(!r)return;const a=this._dataValidationModel.getRuleByLocation(e.location.unitId,e.location.subUnitId,e.location.row,e.location.col);if(!a){this._cellAlertManagerService.removeAlert(me);return}if(this._dataValidationModel.validator(a,{...e.location,workbook:n,worksheet:r})===o.DataValidationStatus.INVALID){const s=this._cellAlertManagerService.currentAlert.get(me),d=(t=s==null?void 0:s.alert)==null?void 0:t.location;if(d&&d.row===e.location.row&&d.col===e.location.col&&d.subUnitId===e.location.subUnitId&&d.unitId===e.location.unitId){this._cellAlertManagerService.removeAlert(me);return}const l=this._dataValidationModel.getValidator(a.type);if(!l){this._cellAlertManagerService.removeAlert(me);return}this._cellAlertManagerService.showAlert({type:W.CellAlertType.ERROR,title:this._localeService.t("dataValidation.error.title"),message:l==null?void 0:l.getRuleFinalError(a,e.location),location:e.location,width:200,height:74,key:me});return}}this._cellAlertManagerService.removeAlert(me)}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._cellAlertManagerService.removeAlert(me)}))}};Oe=Wt([ye(0,o.Inject(W.HoverManagerService)),ye(1,o.Inject(W.CellAlertManagerService)),ye(2,o.IUniverInstanceService),ye(3,o.Inject(o.LocaleService)),ye(4,b.IZenZoneService),ye(5,o.Inject(C.SheetDataValidationModel))],Oe);var $t=Object.getOwnPropertyDescriptor,Ht=(e,t,n,r)=>{for(var a=r>1?void 0:r?$t(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},Ge=(e,t)=>(n,r)=>t(n,r,e);let we=class extends o.Disposable{constructor(e,t,n){super(),this._autoFillService=e,this._sheetDataValidationModel=t,this._injector=n,this._initAutoFill()}_initAutoFill(){const e=()=>({redos:[],undos:[]}),t=(r,a)=>{const{source:i,target:s,unitId:d,subUnitId:l}=r,c=this._sheetDataValidationModel.getRuleObjectMatrix(d,l).clone(),h=W.virtualizeDiscreteRanges([i,s]),[g,u]=h.ranges,{mapFunc:S}=h,v={row:g.startRow,col:g.startColumn},A=W.getAutoFillRepeatRange(g,u),T=new o.ObjectMatrix,w=new Set;A.forEach(m=>{const E=m.repeatStartCell,j=m.relativeRange,$={startRow:v.row,startColumn:v.col,endColumn:v.col,endRow:v.row},F={startRow:E.row,startColumn:E.col,endColumn:E.col,endRow:E.row};o.Range.foreach(j,(H,L)=>{const k=o.Rectangle.getPositionRange({startRow:H,startColumn:L,endColumn:L,endRow:H},$),{row:B,col:K}=S(k.startRow,k.startColumn),J=this._sheetDataValidationModel.getRuleIdByLocation(d,l,B,K)||"",ne=o.Rectangle.getPositionRange({startRow:H,startColumn:L,endColumn:L,endRow:H},F),{row:Z,col:re}=S(ne.startRow,ne.startColumn);T.setValue(Z,re,J),w.add(J)})});const y=Array.from(w).map(m=>({id:m,ranges:o.queryObjectMatrix(T,E=>E===m)}));c.addRangeRules(y);const f=c.diff(this._sheetDataValidationModel.getRules(d,l)),{redoMutations:D,undoMutations:I}=C.getDataValidationDiffMutations(d,l,f,this._injector,"patched",a===W.APPLY_TYPE.ONLY_FORMAT);return{undos:I,redos:D}},n={id:C.DATA_VALIDATION_PLUGIN_NAME,onBeforeFillData:r=>{const{source:a,unitId:i,subUnitId:s}=r;for(const d of a.rows)for(const l of a.cols){const c=this._sheetDataValidationModel.getRuleByLocation(i,s,d,l);if(c&&c.type===o.DataValidationType.CHECKBOX){this._autoFillService.setDisableApplyType(W.APPLY_TYPE.SERIES,!0);return}}},onFillData:(r,a,i)=>i===W.APPLY_TYPE.COPY||i===W.APPLY_TYPE.ONLY_FORMAT||i===W.APPLY_TYPE.SERIES?t(r,i):e(),onAfterFillData:()=>{}};this.disposeWithMe(this._autoFillService.addHook(n))}};we=Ht([Ge(0,W.IAutoFillService),Ge(1,o.Inject(C.SheetDataValidationModel)),Ge(2,o.Inject(o.Injector))],we);var xt=Object.getOwnPropertyDescriptor,Yt=(e,t,n,r)=>{for(var a=r>1?void 0:r?xt(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},qe=(e,t)=>(n,r)=>t(n,r,e);let De=class extends o.Disposable{constructor(t,n,r){super();P(this,"_copyInfo");this._sheetClipboardService=t,this._sheetDataValidationModel=n,this._injector=r,this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:C.DATA_VALIDATION_PLUGIN_NAME,onBeforeCopy:(t,n,r)=>this._collect(t,n,r),onPasteCells:(t,n,r,a)=>{const{copyType:i=W.COPY_TYPE.COPY,pasteType:s}=a,{range:d}=t||{},{range:l,unitId:c,subUnitId:h}=n;return this._generateMutations(l,{copyType:i,pasteType:s,copyRange:d,unitId:c,subUnitId:h})}})}_collect(t,n,r){const a=new o.ObjectMatrix;this._copyInfo={unitId:t,subUnitId:n,matrix:a};const i=this._injector.invoke(l=>Y.rangeToDiscreteRange(r,l,t,n));if(!i)return;const{rows:s,cols:d}=i;s.forEach((l,c)=>{d.forEach((h,g)=>{const u=this._sheetDataValidationModel.getRuleIdByLocation(t,n,l,h);a.setValue(c,g,u!=null?u:"")})})}_generateMutations(t,n){if(!this._copyInfo)return{redos:[],undos:[]};if(n.copyType===W.COPY_TYPE.CUT)return this._copyInfo=null,{redos:[],undos:[]};if(!this._copyInfo||!this._copyInfo.matrix.getSizeOf()||!n.copyRange)return{redos:[],undos:[]};if([W.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,W.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,W.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,W.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA].includes(n.pasteType))return{redos:[],undos:[]};const{unitId:a,subUnitId:i}=this._copyInfo;if(n.unitId!==a||i!==n.subUnitId){const s=this._sheetDataValidationModel.getRuleObjectMatrix(n.unitId,n.subUnitId).clone(),d=new o.ObjectMatrix,l=new Set,{ranges:[c,h],mapFunc:g}=W.virtualizeDiscreteRanges([n.copyRange,t]),u=W.getRepeatRange(c,h,!0),S=new Map;u.forEach(({startRange:w})=>{var y;(y=this._copyInfo)==null||y.matrix.forValue((f,D,I)=>{const m=o.Rectangle.getPositionRange({startRow:f,endRow:f,startColumn:D,endColumn:D},w),E=`${i}-${I}`,j=this._sheetDataValidationModel.getRuleById(a,i,I);!this._sheetDataValidationModel.getRuleById(n.unitId,n.subUnitId,E)&&j&&S.set(E,{...j,uid:E});const{row:$,col:F}=g(m.startRow,m.startColumn);l.add(E),d.setValue($,F,E)})});const v=Array.from(l).map(w=>({id:w,ranges:o.queryObjectMatrix(d,y=>y===w)}));s.addRangeRules(v);const{redoMutations:A,undoMutations:T}=C.getDataValidationDiffMutations(n.unitId,n.subUnitId,s.diffWithAddition(this._sheetDataValidationModel.getRules(n.unitId,n.subUnitId),S.values()),this._injector,"patched",!1);return{redos:A,undos:T}}else{const s=this._sheetDataValidationModel.getRuleObjectMatrix(a,i).clone(),d=new o.ObjectMatrix,l=new Set,{ranges:[c,h],mapFunc:g}=W.virtualizeDiscreteRanges([n.copyRange,t]);W.getRepeatRange(c,h,!0).forEach(({startRange:T})=>{var w;(w=this._copyInfo)==null||w.matrix.forValue((y,f,D)=>{const I=o.Rectangle.getPositionRange({startRow:y,endRow:y,startColumn:f,endColumn:f},T),{row:m,col:E}=g(I.startRow,I.startColumn);d.setValue(m,E,D),l.add(D)})});const S=Array.from(l).map(T=>({id:T,ranges:o.queryObjectMatrix(d,w=>w===T)}));s.addRangeRules(S);const{redoMutations:v,undoMutations:A}=C.getDataValidationDiffMutations(a,i,s.diff(this._sheetDataValidationModel.getRules(a,i)),this._injector,"patched",!1);return{redos:v,undos:A}}}};De=Yt([qe(0,W.ISheetClipboardService),qe(1,o.Inject(C.SheetDataValidationModel)),qe(2,o.Inject(o.Injector))],De);var Xt=Object.getOwnPropertyDescriptor,zt=(e,t,n,r)=>{for(var a=r>1?void 0:r?Xt(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},Je=(e,t)=>(n,r)=>t(n,r,e);let Ee=class extends o.Disposable{constructor(e,t,n){super(),this._localeService=e,this._commandService=t,this._sheetPermissionCheckController=n,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===C.AddSheetDataValidationCommand.id){const{unitId:t,subUnitId:n,rule:{ranges:r}}=e.params;this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[Y.WorkbookEditablePermission],rangeTypes:[Y.RangeProtectionPermissionEditPoint],worksheetTypes:[Y.WorksheetEditPermission,Y.WorksheetSetCellStylePermission]},r,t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("permission.dialog.setStyleErr"))}if(e.id===C.UpdateSheetDataValidationRangeCommand.id){const{unitId:t,subUnitId:n,ranges:r}=e.params;this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[Y.WorkbookEditablePermission],rangeTypes:[Y.RangeProtectionPermissionEditPoint],worksheetTypes:[Y.WorksheetEditPermission,Y.WorksheetSetCellStylePermission]},r,t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("permission.dialog.setStyleErr"))}}))}};Ee=zt([Je(0,o.Inject(o.LocaleService)),Je(1,o.ICommandService),Je(2,o.Inject(Y.SheetPermissionCheckController))],Ee);const gt="sheet.menu.data-validation";function Kt(e){return{id:gt,type:b.MenuItemType.SUBITEMS,icon:"DataValidationIcon",tooltip:"dataValidation.title",hidden$:b.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_SHEET),disabled$:W.getCurrentRangeDisable$(e,{workbookTypes:[Y.WorkbookEditablePermission],worksheetTypes:[Y.WorksheetSetCellStylePermission,Y.WorksheetEditPermission],rangeTypes:[Y.RangeProtectionPermissionEditPoint]})}}function Zt(e){return{id:fe.id,title:"dataValidation.panel.title",type:b.MenuItemType.BUTTON}}function Gt(e){return{id:Fe.id,title:"dataValidation.panel.add",type:b.MenuItemType.BUTTON}}const qt={[b.RibbonDataGroup.RULES]:{[gt]:{order:0,menuItemFactory:Kt,[fe.id]:{order:0,menuItemFactory:Zt},[Fe.id]:{order:1,menuItemFactory:Gt}}}};var Jt=Object.getOwnPropertyDescriptor,ft=(e,t,n,r)=>{for(var a=r>1?void 0:r?Jt(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},G=(e,t)=>(n,r)=>t(n,r,e);const mt={tr:{size:6,color:"#fe4b4b"}};let Me=class extends o.RxDisposable{constructor(e,t,n,r,a,i,s,d,l,c,h){super(),this._commandService=e,this._menuManagerService=t,this._renderManagerService=n,this._univerInstanceService=r,this._autoHeightController=a,this._dropdownManagerService=i,this._sheetDataValidationModel=s,this._dataValidatorRegistryService=d,this._sheetInterceptorService=l,this._dataValidationCacheService=c,this._editorBridgeService=h,this._initMenu(),this._initDropdown(),this._initViewModelIntercept(),this._initAutoHeight()}_initMenu(){this._menuManagerService.mergeMenu(qt)}_initDropdown(){this._editorBridgeService&&this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{var n;if(!e.visible){((n=this._dropdownManagerService.activeDropdown)==null?void 0:n.trigger)==="editor-bridge"&&this._dropdownManagerService.hideDropdown();return}const t=this._editorBridgeService.getEditCellState();if(t){const{unitId:r,sheetId:a,row:i,column:s}=t,d=this._univerInstanceService.getUniverSheetInstance(r);if(!d)return;const l=this._sheetDataValidationModel.getRuleByLocation(r,a,i,s);if(!l)return;const c=this._dataValidatorRegistryService.getValidatorItem(l.type);if(!(c!=null&&c.dropdownType))return;const h=d.getActiveSheet();if(!h)return;const g=this._dropdownManagerService.activeDropdown,u=g==null?void 0:g.location;if(u&&u.unitId===r&&u.subUnitId===a&&u.row===i&&u.col===s)return;this._dropdownManagerService.showDropdown({location:{unitId:r,subUnitId:a,row:i,col:s,workbook:d,worksheet:h},trigger:"editor-bridge",closeOnOutSide:!1})}}))}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(Y.INTERCEPTOR_POINT.CELL_CONTENT,{effect:o.InterceptorEffectEnum.Style,priority:Y.InterceptCellContentPriority.DATA_VALIDATION,handler:(e,t,n)=>{var w,y,f,D,I;const{row:r,col:a,unitId:i,subUnitId:s,workbook:d,worksheet:l}=t,c=this._sheetDataValidationModel.getRuleIdByLocation(i,s,r,a);if(!c)return n(e);const h=this._sheetDataValidationModel.getRuleById(i,s,c);if(!h)return n(e);const g=(w=this._dataValidationCacheService.getValue(i,s,r,a))!=null?w:o.DataValidationStatus.VALID,u=this._dataValidatorRegistryService.getValidatorItem(h.type),S=t.rawData;let v;const A={get value(){var m;return v!==void 0||(v=(m=C.getCellValueOrigin(S))!=null?m:null),v}},T={get value(){var m;return`${(m=A.value)!=null?m:""}`}};return(!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,...g===o.DataValidationStatus.INVALID?mt:null},e.customRender=[...(y=e==null?void 0:e.customRender)!=null?y:[],...u!=null&&u.canvasRender?[u.canvasRender]:[]],e.fontRenderExtension={...e==null?void 0:e.fontRenderExtension,isSkip:((f=e==null?void 0:e.fontRenderExtension)==null?void 0:f.isSkip)||((D=u==null?void 0:u.skipDefaultFontRender)==null?void 0:D.call(u,h,A.value,t))},e.interceptorStyle={...e==null?void 0:e.interceptorStyle,...u==null?void 0:u.getExtraStyle(h,T.value,{get style(){const m=d.getStyles();return(typeof(e==null?void 0:e.s)=="string"?m.get(e==null?void 0:e.s):e==null?void 0:e.s)||{}}},r,a)},e.interceptorAutoHeight=()=>{var $,F,H,L,k,B;const m=(F=($=this._renderManagerService.getRenderById(i))==null?void 0:$.with(W.SheetSkeletonManagerService).getSkeletonParam(s))==null?void 0:F.skeleton;if(!m)return;const E=m.worksheet.getMergedCell(r,a),j={data:e,style:m.getStyles().getStyleByCell(e),primaryWithCoord:m.getCellWithCoordByIndex((H=E==null?void 0:E.startRow)!=null?H:r,(L=E==null?void 0:E.startColumn)!=null?L:a),unitId:i,subUnitId:s,row:r,col:a,workbook:d,worksheet:l};return(B=(k=u==null?void 0:u.canvasRender)==null?void 0:k.calcCellAutoHeight)==null?void 0:B.call(k,j)},e.interceptorAutoWidth=()=>{var $,F,H,L,k,B;const m=(F=($=this._renderManagerService.getRenderById(i))==null?void 0:$.with(W.SheetSkeletonManagerService).getSkeletonParam(s))==null?void 0:F.skeleton;if(!m)return;const E=m.worksheet.getMergedCell(r,a),j={data:e,style:m.getStyles().getStyleByCell(e),primaryWithCoord:m.getCellWithCoordByIndex((H=E==null?void 0:E.startRow)!=null?H:r,(L=E==null?void 0:E.startColumn)!=null?L:a),unitId:i,subUnitId:s,row:r,col:a,workbook:d,worksheet:l};return(B=(k=u==null?void 0:u.canvasRender)==null?void 0:k.calcCellAutoWidth)==null?void 0:B.call(k,j)},e.coverable=((I=e==null?void 0:e.coverable)!=null?I:!0)&&!(h.type===o.DataValidationType.LIST||h.type===o.DataValidationType.LIST_MULTIPLE),n(e)}}))}_initAutoHeight(){this._sheetDataValidationModel.ruleChange$.pipe(ae.filter(e=>e.source==="command"),ae.bufferTime(100)).subscribe(e=>{if(e.length===0)return;const t=[];if(e.forEach(n=>{var r;(n.rule.type===o.DataValidationType.LIST_MULTIPLE||n.rule.type===o.DataValidationType.LIST)&&(r=n.rule)!=null&&r.ranges&&t.push(...n.rule.ranges)}),t.length){const n=this._autoHeightController.getUndoRedoParamsOfAutoHeight(t);o.sequenceExecute(n.redos,this._commandService)}})}};Me=ft([G(0,o.ICommandService),G(1,b.IMenuManagerService),G(2,O.IRenderManagerService),G(3,o.IUniverInstanceService),G(4,o.Inject(W.AutoHeightController)),G(5,o.Inject(ge)),G(6,o.Inject(C.SheetDataValidationModel)),G(7,o.Inject(X.DataValidatorRegistryService)),G(8,o.Inject(Y.SheetInterceptorService)),G(9,o.Inject(C.DataValidationCacheService)),G(10,o.Optional(W.IEditorBridgeService))],Me);let St=class extends o.RxDisposable{constructor(e,t,n,r,a,i,s){super(),this._commandService=e,this._renderManagerService=t,this._autoHeightController=n,this._dataValidatorRegistryService=r,this._sheetInterceptorService=a,this._sheetDataValidationModel=i,this._dataValidationCacheService=s,this._initViewModelIntercept(),this._initAutoHeight()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(Y.INTERCEPTOR_POINT.CELL_CONTENT,{effect:o.InterceptorEffectEnum.Style,priority:Y.InterceptCellContentPriority.DATA_VALIDATION,handler:(e,t,n)=>{var T,w,y,f,D;const{row:r,col:a,unitId:i,subUnitId:s,workbook:d,worksheet:l}=t,c=this._sheetDataValidationModel.getRuleIdByLocation(i,s,r,a);if(!c)return n(e);const h=this._sheetDataValidationModel.getRuleById(i,s,c);if(!h)return n(e);const g=(T=this._dataValidationCacheService.getValue(i,s,r,a))!=null?T:o.DataValidationStatus.VALID,u=this._dataValidatorRegistryService.getValidatorItem(h.type),S=l.getCellRaw(r,a),v=C.getCellValueOrigin(S),A=`${v!=null?v:""}`;return(!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,...g===o.DataValidationStatus.INVALID?mt:null},e.customRender=[...(w=e==null?void 0:e.customRender)!=null?w:[],...u!=null&&u.canvasRender?[u.canvasRender]:[]],e.fontRenderExtension={...e==null?void 0:e.fontRenderExtension,isSkip:((y=e==null?void 0:e.fontRenderExtension)==null?void 0:y.isSkip)||((f=u==null?void 0:u.skipDefaultFontRender)==null?void 0:f.call(u,h,v,t))},e.interceptorStyle={...e==null?void 0:e.interceptorStyle,...u==null?void 0:u.getExtraStyle(h,A,{get style(){const I=d.getStyles();return(typeof(e==null?void 0:e.s)=="string"?I.get(e==null?void 0:e.s):e==null?void 0:e.s)||{}}},r,a)},e.interceptorAutoHeight=()=>{var j,$,F,H,L,k;const I=($=(j=this._renderManagerService.getRenderById(i))==null?void 0:j.with(W.SheetSkeletonManagerService).getSkeletonParam(s))==null?void 0:$.skeleton;if(!I)return;const m=I.worksheet.getMergedCell(r,a),E={data:e,style:I.getStyles().getStyleByCell(e),primaryWithCoord:I.getCellWithCoordByIndex((F=m==null?void 0:m.startRow)!=null?F:r,(H=m==null?void 0:m.startColumn)!=null?H:a),unitId:i,subUnitId:s,row:r,col:a,workbook:d,worksheet:l};return(k=(L=u==null?void 0:u.canvasRender)==null?void 0:L.calcCellAutoHeight)==null?void 0:k.call(L,E)},e.interceptorAutoWidth=()=>{var j,$,F,H,L,k;const I=($=(j=this._renderManagerService.getRenderById(i))==null?void 0:j.with(W.SheetSkeletonManagerService).getSkeletonParam(s))==null?void 0:$.skeleton;if(!I)return;const m=I.worksheet.getMergedCell(r,a),E={data:e,style:I.getStyles().getStyleByCell(e),primaryWithCoord:I.getCellWithCoordByIndex((F=m==null?void 0:m.startRow)!=null?F:r,(H=m==null?void 0:m.startColumn)!=null?H:a),unitId:i,subUnitId:s,row:r,col:a,workbook:d,worksheet:l};return(k=(L=u==null?void 0:u.canvasRender)==null?void 0:L.calcCellAutoWidth)==null?void 0:k.call(L,E)},e.coverable=((D=e==null?void 0:e.coverable)!=null?D:!0)&&!(h.type===o.DataValidationType.LIST||h.type===o.DataValidationType.LIST_MULTIPLE),n(e)}}))}_initAutoHeight(){this._sheetDataValidationModel.ruleChange$.pipe(ae.filter(e=>e.source==="command"),ae.bufferTime(16)).subscribe(e=>{const t=[];if(e.forEach(n=>{var r;(n.rule.type===o.DataValidationType.LIST_MULTIPLE||n.rule.type===o.DataValidationType.LIST)&&(r=n.rule)!=null&&r.ranges&&t.push(...n.rule.ranges)}),t.length){const n=this._autoHeightController.getUndoRedoParamsOfAutoHeight(t);o.sequenceExecute(n.redos,this._commandService)}})}};St=ft([G(0,o.ICommandService),G(1,O.IRenderManagerService),G(2,o.Inject(W.AutoHeightController)),G(3,o.Inject(X.DataValidatorRegistryService)),G(4,o.Inject(Y.SheetInterceptorService)),G(5,o.Inject(C.SheetDataValidationModel)),G(6,o.Inject(C.DataValidationCacheService))],St);var Qt=Object.getOwnPropertyDescriptor,en=(e,t,n,r)=>{for(var a=r>1?void 0:r?Qt(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},_t=(e,t)=>(n,r)=>t(n,r,e);let ke=class extends o.Disposable{constructor(e,t,n){super(),this._context=e,this._sheetDataValidationModel=t,this._sheetSkeletonManagerService=n,this._initSkeletonChange()}_initSkeletonChange(){const e=t=>{var r;if(!t.length)return;const n=new Set;t.forEach(a=>{n.add(a.subUnitId)}),n.forEach(a=>{var i;(i=this._sheetSkeletonManagerService.getSkeletonParam(a))==null||i.skeleton.makeDirty(!0)}),(r=this._context.mainComponent)==null||r.makeForceDirty()};this.disposeWithMe(this._sheetDataValidationModel.validStatusChange$.pipe(o.bufferDebounceTime(16)).subscribe(e))}};ke=en([_t(1,o.Inject(C.SheetDataValidationModel)),_t(2,o.Inject(W.SheetSkeletonManagerService))],ke);function Se({ref:e,...t}){const{icon:n,id:r,className:a,extend:i,...s}=t,d=`univerjs-icon univerjs-icon-${r} ${a||""}`.trim(),l=R.useRef(`_${rn()}`);return It(n,`${r}`,{defIds:n.defIds,idSuffix:l.current},{ref:e,className:d,...s},i)}function It(e,t,n,r,a){return R.createElement(e.tag,{key:t,...tn(e,n,a),...r},(nn(e,n).children||[]).map((i,s)=>It(i,`${t}-${e.tag}-${s}`,n,void 0,a)))}function tn(e,t,n){const r={...e.attrs};n!=null&&n.colorChannel1&&r.fill==="colorChannel1"&&(r.fill=n.colorChannel1),e.tag==="mask"&&r.id&&(r.id=r.id+t.idSuffix),Object.entries(r).forEach(([i,s])=>{i==="mask"&&typeof s=="string"&&(r[i]=s.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});const{defIds:a}=t;return!a||a.length===0||(e.tag==="use"&&r["xlink:href"]&&(r["xlink:href"]=r["xlink:href"]+t.idSuffix),Object.entries(r).forEach(([i,s])=>{typeof s=="string"&&(r[i]=s.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))})),r}function nn(e,t){var r;const{defIds:n}=t;return!n||n.length===0?e:e.tag==="defs"&&((r=e.children)!=null&&r.length)?{...e,children:e.children.map(a=>typeof a.attrs.id=="string"&&n&&n.includes(a.attrs.id)?{...a,attrs:{...a.attrs,id:a.attrs.id+t.idSuffix}}:a)}:e}function rn(){return Math.random().toString(36).substring(2,8)}Se.displayName="UniverIcon";const an={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 17 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M1.4917 3.07803C1.4917 2.19437 2.20804 1.47803 3.0917 1.47803H5.6917C6.57536 1.47803 7.2917 2.19437 7.2917 3.07803V5.67803C7.2917 6.56168 6.57535 7.27803 5.6917 7.27803H3.0917C2.20804 7.27803 1.4917 6.56168 1.4917 5.67803V3.07803ZM3.0917 2.67803C2.87078 2.67803 2.6917 2.85711 2.6917 3.07803V5.67803C2.6917 5.89894 2.87079 6.07803 3.0917 6.07803H5.6917C5.91261 6.07803 6.0917 5.89894 6.0917 5.67803V3.07803C6.0917 2.85711 5.91261 2.67803 5.6917 2.67803H3.0917Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M14.6175 2.45279C14.8518 2.68711 14.8518 3.06701 14.6175 3.30132L11.6151 6.30365C11.3957 6.52307 11.0451 6.53897 10.8067 6.34031L8.80915 4.67566C8.55458 4.46352 8.52019 4.08518 8.73233 3.83062C8.94447 3.57605 9.32281 3.54166 9.57737 3.7538L11.154 5.06767L13.769 2.45278C14.0033 2.21847 14.3832 2.21848 14.6175 2.45279Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M14.1175 9.19746C14.3518 9.43178 14.3518 9.81168 14.1175 10.046L12.5418 11.6217L14.1175 13.1975C14.3518 13.4318 14.3518 13.8117 14.1175 14.046C13.8832 14.2803 13.5033 14.2803 13.269 14.046L11.6933 12.4703L10.1175 14.046C9.88321 14.2803 9.50331 14.2803 9.269 14.046C9.03468 13.8117 9.03468 13.4318 9.269 13.1975L10.8447 11.6217L9.269 10.046C9.03468 9.81168 9.03468 9.43178 9.269 9.19746C9.50331 8.96315 9.88321 8.96315 10.1175 9.19746L11.6933 10.7732L13.269 9.19746C13.5033 8.96315 13.8832 8.96315 14.1175 9.19746Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M3.0917 8.72168C2.20804 8.72168 1.4917 9.43802 1.4917 10.3217V12.9217C1.4917 13.8053 2.20804 14.5217 3.0917 14.5217H5.6917C6.57535 14.5217 7.2917 13.8053 7.2917 12.9217V10.3217C7.2917 9.43802 6.57536 8.72168 5.6917 8.72168H3.0917ZM2.6917 10.3217C2.6917 10.1008 2.87078 9.92168 3.0917 9.92168H5.6917C5.91261 9.92168 6.0917 10.1008 6.0917 10.3217V12.9217C6.0917 13.1426 5.91261 13.3217 5.6917 13.3217H3.0917C2.87079 13.3217 2.6917 13.1426 2.6917 12.9217V10.3217Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Ct=R.forwardRef(function(t,n){return R.createElement(Se,Object.assign({},t,{id:"data-validation-icon",ref:n,icon:an}))});Ct.displayName="DataValidationIcon";const on={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.3313 1.4667C5.3313 1.13533 5.59993 0.866699 5.9313 0.866699H10.069C10.4004 0.866699 10.669 1.13533 10.669 1.4667C10.669 1.79807 10.4004 2.0667 10.069 2.0667H5.9313C5.59993 2.0667 5.3313 1.79807 5.3313 1.4667Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.09985 3.64443C1.09985 3.31306 1.36848 3.04443 1.69985 3.04443H14.2999C14.6312 3.04443 14.8999 3.31306 14.8999 3.64443C14.8999 3.9758 14.6312 4.24443 14.2999 4.24443H1.69985C1.36848 4.24443 1.09985 3.9758 1.09985 3.64443Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M6.12398 8.30171C6.35829 8.0674 6.73819 8.0674 6.97251 8.30171L8.00007 9.32928L9.02764 8.30171C9.26195 8.0674 9.64185 8.0674 9.87617 8.30171C10.1105 8.53603 10.1105 8.91593 9.87617 9.15024L8.8486 10.1778L9.87617 11.2054C10.1105 11.4397 10.1105 11.8196 9.87617 12.0539C9.64185 12.2882 9.26195 12.2882 9.02764 12.0539L8.00007 11.0263L6.97251 12.0539C6.73819 12.2882 6.35829 12.2882 6.12398 12.0539C5.88966 11.8196 5.88966 11.4397 6.12398 11.2054L7.15154 10.1778L6.12398 9.15024C5.88966 8.91593 5.88966 8.53603 6.12398 8.30171Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M4.75332 5.22217C3.86966 5.22217 3.15332 5.93851 3.15332 6.82217V12.5331C3.15332 13.9691 4.31738 15.1332 5.75332 15.1332H10.2465C11.6825 15.1332 12.8465 13.9691 12.8465 12.5331V6.82217C12.8465 5.93851 12.1302 5.22217 11.2465 5.22217H4.75332ZM4.35332 6.82217C4.35332 6.60125 4.53241 6.42217 4.75332 6.42217H11.2465C11.4674 6.42217 11.6465 6.60125 11.6465 6.82217V12.5331C11.6465 13.3063 11.0197 13.9332 10.2465 13.9332H5.75332C4.98012 13.9332 4.35332 13.3063 4.35332 12.5331V6.82217Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Qe=R.forwardRef(function(t,n){return R.createElement(Se,Object.assign({},t,{id:"delete-icon",ref:n,icon:on}))});Qe.displayName="DeleteIcon";const sn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.6 1.99991C8.60001 1.66854 8.33138 1.39991 8.00001 1.3999C7.66864 1.3999 7.40001 1.66853 7.4 1.9999L7.39996 7.3999H1.9999C1.66853 7.3999 1.3999 7.66853 1.3999 7.9999C1.3999 8.33127 1.66853 8.5999 1.9999 8.5999H7.39995L7.3999 13.9999C7.3999 14.3313 7.66853 14.5999 7.9999 14.5999C8.33127 14.5999 8.5999 14.3313 8.5999 13.9999L8.59995 8.5999H13.9999C14.3313 8.5999 14.5999 8.33127 14.5999 7.9999C14.5999 7.66853 14.3313 7.3999 13.9999 7.3999H8.59996L8.6 1.99991Z"}}]},yt=R.forwardRef(function(t,n){return R.createElement(Se,Object.assign({},t,{id:"increase-icon",ref:n,icon:sn}))});yt.displayName="IncreaseIcon";const ln={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M11.3536 6.14645C11.5488 6.34171 11.5488 6.65829 11.3536 6.85355L8.35355 9.85355C8.15829 10.0488 7.84171 10.0488 7.64645 9.85355L4.64645 6.85355C4.45118 6.65829 4.45118 6.34171 4.64645 6.14645C4.84171 5.95118 5.15829 5.95118 5.35355 6.14645L8 8.79289L10.6464 6.14645C10.8417 5.95118 11.1583 5.95118 11.3536 6.14645Z",fillRule:"evenodd",clipRule:"evenodd"}}]},et=R.forwardRef(function(t,n){return R.createElement(Se,Object.assign({},t,{id:"more-down-icon",ref:n,icon:ln}))});et.displayName="MoreDownIcon";const dn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M4.64645 9.85355C4.45118 9.65829 4.45118 9.34171 4.64645 9.14645L7.64645 6.14645C7.84171 5.95118 8.15829 5.95118 8.35355 6.14645L11.3536 9.14645C11.5488 9.34171 11.5488 9.65829 11.3536 9.85355C11.1583 10.0488 10.8417 10.0488 10.6464 9.85355L8 7.20711L5.35355 9.85355C5.15829 10.0488 4.84171 10.0488 4.64645 9.85355Z",fillRule:"evenodd",clipRule:"evenodd"}}]},wt=R.forwardRef(function(t,n){return R.createElement(Se,Object.assign({},t,{id:"more-up-icon",ref:n,icon:dn}))});wt.displayName="MoreUpIcon";const cn={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M6 5C6.55228 5 7 4.55228 7 4C7 3.44772 6.55228 3 6 3C5.44772 3 5 3.44772 5 4C5 4.55228 5.44772 5 6 5Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M6 9C6.55228 9 7 8.55229 7 8C7 7.44772 6.55228 7 6 7C5.44772 7 5 7.44772 5 8C5 8.55229 5.44772 9 6 9Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M7 12C7 12.5523 6.55228 13 6 13C5.44772 13 5 12.5523 5 12C5 11.4477 5.44772 11 6 11C6.55228 11 7 11.4477 7 12Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M10 5C10.5523 5 11 4.55228 11 4C11 3.44772 10.5523 3 10 3C9.44771 3 9 3.44772 9 4C9 4.55228 9.44771 5 10 5Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M11 8C11 8.55229 10.5523 9 10 9C9.44771 9 9 8.55229 9 8C9 7.44772 9.44771 7 10 7C10.5523 7 11 7.44772 11 8Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M10 13C10.5523 13 11 12.5523 11 12C11 11.4477 10.5523 11 10 11C9.44771 11 9 11.4477 9 12C9 12.5523 9.44771 13 10 13Z"}}]},Dt=R.forwardRef(function(t,n){return R.createElement(Se,Object.assign({},t,{id:"sequence-icon",ref:n,icon:cn}))});Dt.displayName="SequenceIcon";function un(e){var c;const t=b.useDependency(o.LocaleService),n=b.useDependency(b.ComponentManager),{value:r,onChange:a,extraComponent:i}=e,[s,d]=R.useState(!1),l=i?n.get(i):null;return p.jsxs(p.Fragment,{children:[p.jsxs("div",{className:"univer-mb-3 univer-flex univer-cursor-pointer univer-items-center univer-text-sm univer-text-gray-900 dark:!univer-text-white",onClick:()=>d(!s),children:[t.t("dataValidation.panel.options"),s?p.jsx(wt,{className:"univer-ml-1"}):p.jsx(et,{className:"univer-ml-1"})]}),s&&p.jsxs(p.Fragment,{children:[l?p.jsx(l,{value:r,onChange:a}):null,p.jsx(M.FormLayout,{label:t.t("dataValidation.panel.invalid"),children:p.jsxs(M.RadioGroup,{value:`${(c=r.errorStyle)!=null?c:o.DataValidationErrorStyle.WARNING}`,onChange:h=>a({...r,errorStyle:+h}),children:[p.jsx(M.Radio,{value:`${o.DataValidationErrorStyle.WARNING}`,children:t.t("dataValidation.panel.showWarning")}),p.jsx(M.Radio,{value:`${o.DataValidationErrorStyle.STOP}`,children:t.t("dataValidation.panel.rejectInput")})]})}),p.jsx(M.FormLayout,{label:t.t("dataValidation.panel.messageInfo"),children:p.jsx(M.Checkbox,{checked:r.showErrorMessage,onChange:()=>a({...r,showErrorMessage:!r.showErrorMessage}),children:t.t("dataValidation.panel.showInfo")})}),r.showErrorMessage?p.jsx(M.FormLayout,{children:p.jsx(M.Input,{value:r.error,onChange:h=>a({...r,error:h})})}):null]})]})}const hn=e=>o.debounce(async(t,n,r,a)=>{const i=await e.executeCommand(t,n,r);a==null||a(i)},1e3);function pn(e,t,n){var r,a,i,s;return t?((a=(r=e.getUnit(t))==null?void 0:r.getSheetBySheetName(n))==null?void 0:a.getSheetId())||"":((s=(i=e.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET))==null?void 0:i.getSheetBySheetName(n))==null?void 0:s.getSheetId())||""}function vn(){var V,x;const[e,t]=R.useState(0),n=b.useDependency(de),r=b.useObservable(n.activeRule$,n.activeRule),{unitId:a,subUnitId:i,rule:s}=r||{},d=s.uid,l=b.useDependency(X.DataValidatorRegistryService),c=b.useDependency(o.IUniverInstanceService),h=b.useDependency(b.ComponentManager),g=b.useDependency(o.ICommandService),u=b.useDependency(X.DataValidationModel),S=b.useDependency(o.LocaleService),[v,A]=R.useState(s),T=l.getValidatorItem(v.type),[w,y]=R.useState(!1),f=l.getValidatorsByScope(X.DataValidatorRegistryScope.SHEET),[D,I]=R.useState(()=>v.ranges.map(_=>({unitId:"",sheetId:"",range:_}))),m=R.useMemo(()=>hn(g),[g]),[E,j]=R.useState(!1),[$,F]=R.useState(!1),H=R.useRef(null),L=b.useDependency(Y.SheetsSelectionsService);if(R.useEffect(()=>()=>{const _=L.getCurrentLastSelection();_&&L.setSelections([_])},[L]),R.useEffect(()=>{g.onCommandExecuted(_=>{(_.id===o.UndoCommand.id||_.id===o.RedoCommand.id)&&setTimeout(()=>{const N=u.getRuleById(a,i,d);t(z=>z+1),N&&(A(N),I(N.ranges.map(z=>({unitId:"",sheetId:"",range:z}))))},20)})},[g,u,d,i,a]),!T)return null;const k=T.operators,B=T.operatorNames,K=v.operator?X.TWO_FORMULA_OPERATOR_COUNT.includes(v.operator):!1,J=()=>{var _,N,z;(N=(_=H.current)==null?void 0:_.editor)!=null&&N.isFocus()&&ne((z=H.current)==null?void 0:z.getValue()),!(!v.ranges.length||E)&&(T.validatorFormula(v,a,i).success?n.setActiveRule(null):y(!0))},ne=b.useEvent(_=>{const N=_.split(",").filter(Boolean).map(Ye.deserializeRangeWithSheet).map(te=>{const Ot=te.sheetName;if(Ot){const sr=pn(c,te.unitId,Ot);return{...te,sheetId:sr}}return{...te,sheetId:""}});if(o.isUnitRangesEqual(N,D))return;I(N);const z=N.filter(te=>(!te.unitId||te.unitId===a)&&(!te.sheetId||te.sheetId===i)).map(te=>te.range);if(A({...v,ranges:z}),z.length===0)return;const le={unitId:a,subUnitId:i,ruleId:d,ranges:z};m(C.UpdateSheetDataValidationRangeCommand.id,le)}),Z=_=>{if(o.shallowEqual(_,X.getRuleSetting(v)))return;A({...v,..._});const N={unitId:a,subUnitId:i,ruleId:d,setting:_};m(C.UpdateSheetDataValidationSettingCommand.id,N,void 0)},re=async()=>{await g.executeCommand(C.RemoveSheetDataValidationCommand.id,{ruleId:d,unitId:a,subUnitId:i}),n.setActiveRule(null)},ie={type:v.type,operator:v.operator,formula1:v.formula1,formula2:v.formula2,allowBlank:v.allowBlank},he=_=>{const N=l.getValidatorItem(_);if(!N)return;const z=N.operators,le=u.getRuleById(a,i,d),te=_===(le==null?void 0:le.type)||_.includes("list")&&(le!=null&&le.type.includes("list"))?{...le,type:_}:{...v,type:_,operator:z[0],formula1:void 0,formula2:void 0};A(te),g.executeCommand(C.UpdateSheetDataValidationSettingCommand.id,{unitId:a,subUnitId:i,ruleId:v.uid,setting:X.getRuleSetting(te)})},pe=h.get(T.formulaInput),ee=R.useMemo(()=>D.map(_=>Ye.serializeRange(_.range)).join(","),[]),q=X.getRuleOptions(v),ce=_=>{o.shallowEqual(_,X.getRuleOptions(v))||(A({...v,..._}),m(C.UpdateSheetDataValidationOptionsCommand.id,{unitId:a,subUnitId:i,ruleId:d,options:_}))},Q=k.length&&!v.operator;return p.jsxs("div",{"data-u-comp":"data-validation-detail",className:"univer-py-2",children:[p.jsx(M.FormLayout,{label:S.t("dataValidation.panel.range"),error:!v.ranges.length||E?S.t("dataValidation.panel.rangeError"):"",children:p.jsx(Xe.RangeSelector,{selectorRef:H,unitId:a,subUnitId:i,initialValue:ee,onChange:(_,N)=>{var z;!$&&((z=H.current)!=null&&z.verify())&&ne(N)},onFocusChange:(_,N)=>{var z;F(_),!_&&N&&((z=H.current)!=null&&z.verify())&&ne(N)},onVerify:_=>j(!_)})}),p.jsx(M.FormLayout,{label:S.t("dataValidation.panel.type"),children:p.jsx(M.Select,{className:"univer-w-full",value:v.type,options:(V=f==null?void 0:f.sort((_,N)=>_.order-N.order))==null?void 0:V.map(_=>({label:S.t(_.title),value:_.id})),onChange:he})}),k!=null&&k.length?p.jsx(M.FormLayout,{label:S.t("dataValidation.panel.operator"),children:p.jsx(M.Select,{className:"univer-w-full",value:`${v.operator}`,options:[{value:"",label:S.t("dataValidation.operators.legal")},...k.map((_,N)=>({value:`${_}`,label:B[N]}))],onChange:_=>{Z({...ie,operator:_})}})}):null,pe&&!Q?p.jsx(pe,{isTwoFormula:K,value:{formula1:v.formula1,formula2:v.formula2},onChange:_=>{Z({...ie,..._})},showError:w,validResult:T.validatorFormula(v,a,i),unitId:a,subUnitId:i,ruleId:d},e+v.type):null,p.jsx(M.FormLayout,{children:p.jsx(M.Checkbox,{checked:(x=v.allowBlank)!=null?x:!0,onChange:()=>{var _;return Z({...ie,allowBlank:!((_=v.allowBlank)==null||_)})},children:S.t("dataValidation.panel.allowBlank")})}),p.jsx(un,{value:q,onChange:ce,extraComponent:T.optionsInput}),p.jsxs("div",{className:"univer-mt-5 univer-flex univer-flex-row univer-justify-end",children:[p.jsx(M.Button,{className:"univer-ml-3",onClick:re,children:S.t("dataValidation.panel.removeRule")}),p.jsx(M.Button,{className:"univer-ml-3",variant:"primary",onClick:J,children:S.t("dataValidation.panel.done")})]})]})}const gn=e=>{const{rule:t,onClick:n,unitId:r,subUnitId:a,disable:i}=e,s=b.useDependency(X.DataValidatorRegistryService),d=b.useDependency(o.ICommandService),l=b.useDependency(W.IMarkSelectionService),c=s.getValidatorItem(t.type),h=R.useRef(void 0),[g,u]=R.useState(!1),S=b.useDependency(o.ThemeService),v=b.useObservable(S.currentTheme$),A=R.useMemo(()=>{var I;const w=S.getColorFromTheme("primary.600"),y=S.getColorFromTheme("loop-color.2"),f=(I=S.getColorFromTheme(y))!=null?I:w,D=new o.ColorKit(f).toRgb();return{fill:`rgba(${D.r}, ${D.g}, ${D.b}, 0.1)`,stroke:f}},[v]),T=w=>{d.executeCommand(C.RemoveSheetDataValidationCommand.id,{ruleId:t.uid,unitId:r,subUnitId:a}),w.stopPropagation()};return R.useEffect(()=>()=>{var w;h.current&&((w=h.current)==null||w.forEach(y=>{y&&l.removeShape(y)}))},[l]),p.jsxs("div",{className:M.clsx(`
15
15
  univer-bg-secondary univer-relative univer--ml-2 univer--mr-2 univer-box-border univer-flex
16
16
  univer-w-[287px] univer-cursor-pointer univer-flex-col univer-justify-between univer-overflow-hidden
17
17
  univer-rounded-md univer-p-2 univer-pr-9
18
- `,{"hover:univer-bg-gray-50 dark:hover:!univer-bg-gray-700":!i,"univer-opacity-50":i}),onClick:n,onMouseEnter:()=>{i||(u(!0),h.current=t.ranges.map(w=>l.addShape({range:w,style:A,primary:null})))},onMouseLeave:()=>{var w;u(!1),(w=h.current)==null||w.forEach(y=>{y&&l.removeShape(y)}),h.current=void 0},children:[p.jsx("div",{className:"univer-truncate univer-text-sm univer-font-medium univer-leading-[22px] univer-text-gray-900 dark:!univer-text-white",children:c==null?void 0:c.generateRuleName(t)}),p.jsx("div",{className:"univer-text-secondary univer-truncate univer-text-xs univer-leading-[18px] dark:!univer-text-gray-300",children:t.ranges.map(w=>Ye.serializeRange(w)).join(",")}),g?p.jsx("div",{className:"univer-absolute univer-right-2 univer-top-[19px] univer-flex univer-h-5 univer-w-5 univer-items-center univer-justify-center univer-rounded hover:univer-bg-gray-200 dark:!univer-text-gray-300 dark:hover:!univer-bg-gray-700",onClick:T,children:p.jsx(Qe,{})}):null]})};function fn(e){const t=b.useDependency(C.SheetDataValidationModel),n=b.useDependency(o.IUniverInstanceService),r=b.useDependency(o.ICommandService),a=b.useDependency(o.Injector),i=b.useDependency(de),s=b.useDependency(o.LocaleService),[d,l]=R.useState([]),{workbook:c}=e,h=b.useObservable(c.activeSheet$,void 0,!0),g=c.getUnitId(),u=h==null?void 0:h.getSheetId();R.useEffect(()=>{l(t.getRules(g,u));const y=t.ruleChange$.subscribe(f=>{f.unitId===g&&f.subUnitId===u&&l(t.getRules(g,u))});return()=>{y.unsubscribe()}},[g,u,t]);const S=async()=>{const y=C.createDefaultNewRule(a),f={unitId:g,subUnitId:u,rule:y};await r.executeCommand(C.AddSheetDataValidationCommand.id,f),i.setActiveRule({unitId:g,subUnitId:u,rule:y})},v=()=>{r.executeCommand(C.RemoveSheetAllDataValidationCommand.id,{unitId:g,subUnitId:u})},T=(y=>{const f=n.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET),D=f.getActiveSheet(),I=f.getUnitId(),m=D.getSheetId();return y.map(j=>Y.checkRangesEditablePermission(a,I,m,j.ranges)?{...j}:{...j,disable:!0})})(d),w=T==null?void 0:T.some(y=>y.disable);return p.jsxs("div",{className:"univer-pb-4",children:[T==null?void 0:T.map(y=>{var f;return p.jsx(gn,{unitId:g,subUnitId:u,onClick:()=>{y.disable||i.setActiveRule({unitId:g,subUnitId:u,rule:y})},rule:y,disable:(f=y.disable)!=null?f:!1},y.uid)}),p.jsxs("div",{className:"univer-mt-4 univer-flex univer-flex-row univer-justify-end univer-gap-2",children:[d.length&&!w?p.jsx(M.Button,{onClick:v,children:s.t("dataValidation.panel.removeAll")}):null,p.jsx(M.Button,{variant:"primary",onClick:S,children:s.t("dataValidation.panel.add")})]})]})}const mn=()=>{const e=b.useDependency(de),t=b.useObservable(e.activeRule$,e.activeRule),n=b.useDependency(o.IUniverInstanceService),r=b.useObservable(()=>n.getCurrentTypeOfUnit$(o.UniverInstanceType.UNIVER_SHEET),void 0,void 0,[]),a=b.useObservable(()=>{var i;return(i=r==null?void 0:r.activeSheet$)!=null?i:ae.of(null)},void 0,void 0,[]);return!r||!a?null:t&&t.subUnitId===a.getSheetId()?p.jsx(vn,{},t.rule.uid):p.jsx(fn,{workbook:r})},Sn=e=>{const{isTwoFormula:t=!1,value:n,onChange:r,showError:a,validResult:i}=e,s=b.useDependency(o.LocaleService),d=a?i==null?void 0:i.formula1:"",l=a?i==null?void 0:i.formula2:"";return t?p.jsxs(p.Fragment,{children:[p.jsx(M.FormLayout,{error:d,children:p.jsx(M.Input,{className:"univer-w-full",placeholder:s.t("dataValidation.panel.formulaPlaceholder"),value:n==null?void 0:n.formula1,onChange:c=>{r==null||r({...n,formula1:c})}})}),p.jsx("div",{className:"-univer-mt-2 univer-mb-1 univer-text-sm univer-text-gray-400",children:s.t("dataValidation.panel.formulaAnd")}),p.jsx(M.FormLayout,{error:l,children:p.jsx(M.Input,{className:"univer-w-full",placeholder:s.t("dataValidation.panel.formulaPlaceholder"),value:n==null?void 0:n.formula2,onChange:c=>{r==null||r({...n,formula2:c})}})})]}):p.jsx(M.FormLayout,{error:d,children:p.jsx(M.Input,{className:"univer-w-full",placeholder:s.t("dataValidation.panel.formulaPlaceholder"),value:n==null?void 0:n.formula1,onChange:c=>{r==null||r({formula1:c})}})})};function _n(e){const{value:t,onChange:n,showError:r,validResult:a}=e,i=b.useDependency(o.LocaleService),s=r?a==null?void 0:a.formula1:"",d=r?a==null?void 0:a.formula2:"",[l,c]=R.useState(!((t==null?void 0:t.formula1)===void 0&&(t==null?void 0:t.formula2)===void 0));return p.jsxs(p.Fragment,{children:[p.jsx(M.FormLayout,{children:p.jsx(M.Checkbox,{checked:l,onChange:h=>{h?c(!0):(c(!1),n==null||n({...t,formula1:void 0,formula2:void 0}))},children:i.t("dataValidation.checkbox.tips")})}),l?p.jsx(M.FormLayout,{label:i.t("dataValidation.checkbox.checked"),error:s,children:p.jsx(M.Input,{className:"univer-w-full",placeholder:i.t("dataValidation.panel.valuePlaceholder"),value:t==null?void 0:t.formula1,onChange:h=>{n==null||n({...t,formula1:h||void 0})}})}):null,l?p.jsx(M.FormLayout,{label:i.t("dataValidation.checkbox.unchecked"),error:d,children:p.jsx(M.Input,{className:"univer-w-full",placeholder:i.t("dataValidation.panel.valuePlaceholder"),value:t==null?void 0:t.formula2,onChange:h=>{n==null||n({...t,formula2:h||void 0})}})}):null]})}function In(e){var g;const{unitId:t,subUnitId:n,value:r,onChange:a,showError:i,validResult:s}=e,d=i?s==null?void 0:s.formula1:void 0,l=R.useRef(null),[c,h]=R.useState(!1);return b.useSidebarClick(u=>{var v;((v=l.current)==null?void 0:v.isClickOutSide(u))&&h(!1)}),p.jsx(M.FormLayout,{error:d,children:p.jsx(Xe.FormulaEditor,{ref:l,className:M.clsx("univer-box-border univer-h-8 univer-w-full univer-cursor-pointer univer-items-center univer-rounded-lg univer-bg-white univer-pt-2 univer-transition-colors hover:univer-border-primary-600 dark:!univer-bg-gray-700 dark:!univer-text-white [&>div:first-child]:univer-px-2.5 [&>div]:univer-h-5 [&>div]:univer-ring-transparent",M.borderClassName),initValue:(g=r==null?void 0:r.formula1)!=null?g:"=",unitId:t,subUnitId:n,isFocus:c,isSupportAcrossSheet:!0,onChange:u=>{const S=(u!=null?u:"").trim();S!==(r==null?void 0:r.formula1)&&(a==null||a({...r,formula1:S}))},onFocus:()=>h(!0)})})}const Cn=["#FFFFFF","#FEE7E7","#FEF0E6","#EFFBD0","#E4F4FE","#E8ECFD","#F1EAFA","#FDE8F3","#E5E5E5","#FDCECE","#FDC49B","#DEF6A2","#9FDAFF","#D0D9FB","#E3D5F6","#FBD0E8","#656565","#FE4B4B","#FF8C51","#8BBB11","#0B9EFB","#3A60F7","#9E6DE3","#F248A6"],yn=e=>{const{value:t,onChange:n,disabled:r}=e,[a,i]=R.useState(!1);return p.jsx(M.Dropdown,{align:"start",disabled:r,open:a,onOpenChange:i,overlay:p.jsx("div",{className:"univer-box-border univer-grid univer-w-fit univer-grid-cols-6 univer-flex-wrap univer-gap-2 univer-p-1.5",children:Cn.map(s=>p.jsx("div",{className:M.clsx("univer-box-border univer-size-4 univer-cursor-pointer univer-rounded",M.borderClassName),style:{background:s},onClick:()=>{n(s),i(!1)}},s))}),children:p.jsxs("div",{className:M.clsx("univer-box-border univer-inline-flex univer-h-8 univer-w-16 univer-cursor-pointer univer-items-center univer-justify-between univer-gap-2 univer-rounded-lg univer-bg-white univer-px-2.5 univer-transition-colors univer-duration-200 hover:univer-border-primary-600 dark:!univer-bg-gray-700 dark:!univer-text-white",M.borderClassName),children:[p.jsx("div",{className:"univer-box-border univer-h-4 univer-w-4 univer-rounded univer-text-base",style:{background:t}}),p.jsx(et,{})]})})},Et=e=>{const{item:t,commonProps:n,className:r}=e,{onItemChange:a,onItemDelete:i}=n;return p.jsxs("div",{className:M.clsx("univer-flex univer-items-center univer-gap-2",r),children:[!t.isRef&&p.jsx("div",{className:M.clsx("univer-cursor-move","draggableHandle"),children:p.jsx(Dt,{})}),p.jsx(yn,{value:t.color,onChange:s=>{a(t.id,t.label,s)}}),p.jsx(M.Input,{disabled:t.isRef,value:t.label,onChange:s=>{a(t.id,s,t.color)}}),t.isRef?null:p.jsx("div",{className:"univer-ml-1 univer-cursor-pointer univer-rounded univer-text-base hover:univer-bg-gray-200",children:p.jsx(Qe,{onClick:()=>i(t.id)})})]})};function wn(e){const{value:t,onChange:n=()=>{},unitId:r,subUnitId:a,validResult:i,showError:s,ruleId:d}=e,{formula1:l="",formula2:c=""}=t||{},[h,g]=R.useState(()=>o.isFormulaString(l)?"1":"0"),[u,S]=R.useState(h==="1"?l:"="),[v,A]=R.useState(h==="1"?l:"="),T=b.useDependency(o.LocaleService),w=b.useDependency(X.DataValidatorRegistryService),y=b.useDependency(X.DataValidationModel),f=b.useDependency(C.DataValidationFormulaController),[D,I]=R.useState(()=>c.split(",")),m=w.getValidatorItem(o.DataValidationType.LIST),[E,j]=R.useState([]),[H,F]=R.useState(""),B=s?i==null?void 0:i.formula1:"",L=R.useMemo(()=>y.ruleChange$.pipe(ae.debounceTime(16)),[]),k=b.useObservable(L),W=b.useEvent(n);R.useEffect(()=>{(async()=>{await new Promise(_=>{setTimeout(()=>_(!0),100)});const V=y.getRuleById(r,a,d),x=V==null?void 0:V.formula1;if(o.isFormulaString(x)&&m&&V){const _=await m.getListAsync(V,r,a);j(_)}})()},[y,k,m,d,a,r]),R.useEffect(()=>{o.isFormulaString(l)&&l!==v&&(S(l),A(v))},[v,l]);const[K,J]=R.useState(()=>{const V=h!=="1"?C.deserializeListOptions(l):[],x=c.split(",");return V.map((_,N)=>({label:_,color:x[N]||ve,isRef:!1,id:o.generateRandomId(4)}))}),ne=(V,x,_)=>{const N=K.find(z=>z.id===V);N&&(N.label=x,N.color=_,J([...K]))},Z=V=>{const x=K.findIndex(_=>_.id===V);x!==-1&&(K.splice(x,1),J([...K]))},re=c.split(","),ie=R.useMemo(()=>E.map((V,x)=>({label:V,color:re[x]||ve,id:`${x}`,isRef:!0})),[re,E]),he=(V,x,_)=>{const N=[...D];N[+V]=_,I(N),W({formula1:l,formula2:N.join(",")})},pe=()=>{J([...K,{label:"",color:ve,isRef:!1,id:o.generateRandomId(4)}])};R.useEffect(()=>{if(h==="1")return;const V=new Set,x=[];K.map(_=>({labelList:_.label.split(","),item:_})).forEach(({item:_,labelList:N})=>{N.forEach(z=>{V.has(z)||(V.add(z),x.push({label:z,color:_.color}))})}),W({formula1:C.serializeListOptions(x.map(_=>_.label)),formula2:x.map(_=>_.color===ve?"":_.color).join(",")})},[K,W,h,v,D]);const Q=b.useEvent(async V=>{if(!o.isFormulaString(V)){W==null||W({formula1:"",formula2:c});return}f.getFormulaRefCheck(V)?(W==null||W({formula1:o.isFormulaString(V)?V:"",formula2:c}),F("")):(W==null||W({formula1:"",formula2:c}),S("="),F(T.t("dataValidation.validFail.formulaError")))}),q=R.useRef(null),[ce,ee]=R.useState(!1);return b.useSidebarClick(V=>{var _;((_=q.current)==null?void 0:_.isClickOutSide(V))&&ee(!1)}),p.jsxs(p.Fragment,{children:[p.jsx(M.FormLayout,{label:T.t("dataValidation.list.options"),children:p.jsxs(M.RadioGroup,{value:h,onChange:V=>{g(V),S(v),V==="1"&&W({formula1:v==="="?"":v,formula2:D.join(",")})},children:[p.jsx(M.Radio,{value:"0",children:T.t("dataValidation.list.customOptions")}),p.jsx(M.Radio,{value:"1",children:T.t("dataValidation.list.refOptions")})]})}),h==="1"?p.jsxs(M.FormLayout,{error:B||H||void 0,children:[p.jsx(Xe.FormulaEditor,{ref:q,className:M.clsx("univer-box-border univer-h-8 univer-w-full univer-cursor-pointer univer-items-center univer-rounded-lg univer-bg-white univer-pt-2 univer-transition-colors hover:univer-border-primary-600 dark:!univer-bg-gray-700 dark:!univer-text-white [&>div:first-child]:univer-px-2.5 [&>div]:univer-h-5 [&>div]:univer-ring-transparent",M.borderClassName),initValue:u,unitId:r,subUnitId:a,isFocus:ce,isSupportAcrossSheet:!0,onFocus:()=>ee(!0),onChange:(V="")=>{const x=(V!=null?V:"").trim();A(x),Q(x)}}),ie.length>0&&p.jsx("div",{className:"univer-mt-3",children:ie.map(V=>p.jsx(Et,{className:"univer-mb-3",item:V,commonProps:{onItemChange:he}},V.id))})]}):p.jsx(M.FormLayout,{error:B,children:p.jsxs("div",{className:"-univer-mt-3",children:[p.jsx(M.DraggableList,{list:K,onListChange:J,rowHeight:28,margin:[0,12],draggableHandle:".draggableHandle",itemRender:V=>p.jsx(Et,{item:V,commonProps:{onItemChange:ne,onItemDelete:Z}},V.id),idKey:"id"}),p.jsxs("a",{className:"univer-text-primary univer-flex univer-w-fit univer-cursor-pointer univer-flex-row univer-items-center univer-rounded univer-p-1 univer-px-2 univer-text-sm hover:univer-bg-primary-50 dark:hover:!univer-bg-gray-800",onClick:pe,children:[p.jsx(yt,{className:"univer-mr-1"}),T.t("dataValidation.list.add")]})]})})]})}const Dn=[[C.CUSTOM_FORMULA_INPUT_NAME,In],[C.BASE_FORMULA_INPUT_NAME,Sn],[C.LIST_FORMULA_INPUT_NAME,wn],[C.CHECKBOX_FORMULA_INPUT_NAME,_n]],En="LIST_RENDER_MODE_OPTION_INPUT";function Ne(e){var a;const{value:t,onChange:n}=e,r=b.useDependency(o.LocaleService);return p.jsx(M.FormLayout,{label:r.t("dataValidation.renderMode.label"),children:p.jsxs(M.RadioGroup,{value:`${(a=t.renderMode)!=null?a:o.DataValidationRenderMode.CUSTOM}`,onChange:i=>n({...t,renderMode:+i}),children:[p.jsx(M.Radio,{value:`${o.DataValidationRenderMode.CUSTOM}`,children:r.t("dataValidation.renderMode.chip")}),p.jsx(M.Radio,{value:`${o.DataValidationRenderMode.ARROW}`,children:r.t("dataValidation.renderMode.arrow")}),p.jsx(M.Radio,{value:`${o.DataValidationRenderMode.TEXT}`,children:r.t("dataValidation.renderMode.text")})]})})}Ne.componentKey=En;const Mn="DATE_SHOW_TIME_OPTION";function je(e){var a;const{value:t,onChange:n}=e,r=b.useDependency(o.LocaleService);return p.jsx(M.FormLayout,{children:p.jsx(M.Checkbox,{checked:(a=t.bizInfo)==null?void 0:a.showTime,onChange:i=>{n({...t,bizInfo:{...t.bizInfo,showTime:i}})},children:r.t("dataValidation.showTime.label")})})}je.componentKey=Mn;var bn=Object.getOwnPropertyDescriptor,Tn=(e,t,n,r)=>{for(var a=r>1?void 0:r?bn(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},be=(e,t)=>(n,r)=>t(n,r,e);const Be=6;let tt=class{constructor(e,t,n,r,a,i){this._commandService=e,this._univerInstanceService=t,this._formulaService=n,this._themeService=r,this._renderManagerService=a,this._dataValidationModel=i}_calc(e,t){var c,h,g;const{vt:n,ht:r}=t||{},a=e.endX-e.startX-Be*2,i=e.endY-e.startY,s=((c=t==null?void 0:t.fs)!=null?c:10)*1.6;let d=0,l=0;switch(n){case o.VerticalAlign.TOP:l=0;break;case o.VerticalAlign.BOTTOM:l=0+(i-s);break;default:l=0+(i-s)/2;break}switch(r){case o.HorizontalAlign.LEFT:d=Be;break;case o.HorizontalAlign.RIGHT:d=Be+(a-s);break;default:d=Be+(a-s)/2;break}return{left:e.startX+d,top:e.startY+l,width:((h=t==null?void 0:t.fs)!=null?h:10)*1.6,height:((g=t==null?void 0:t.fs)!=null?g:10)*1.6}}calcCellAutoHeight(e){var n;const{style:t}=e;return((n=t==null?void 0:t.fs)!=null?n:10)*1.6}calcCellAutoWidth(e){var n;const{style:t}=e;return((n=t==null?void 0:t.fs)!=null?n:10)*1.6}async _parseFormula(e,t,n){var c,h,g,u,S,v,A,T,w;const{formula1:r=C.CHECKBOX_FORMULA_1,formula2:a=C.CHECKBOX_FORMULA_2}=e,i=await this._formulaService.getRuleFormulaResult(t,n,e.uid),s=C.getFormulaResult((g=(h=(c=i==null?void 0:i[0])==null?void 0:c.result)==null?void 0:h[0])==null?void 0:g[0]),d=C.getFormulaResult((v=(S=(u=i==null?void 0:i[1])==null?void 0:u.result)==null?void 0:S[0])==null?void 0:v[0]),l=C.isLegalFormulaResult(String(s))&&C.isLegalFormulaResult(String(d));return{formula1:o.isFormulaString(r)?C.getFormulaResult((w=(T=(A=i==null?void 0:i[0])==null?void 0:A.result)==null?void 0:T[0])==null?void 0:w[0]):r,formula2:o.isFormulaString(a)?d:a,isFormulaValid:l}}drawWith(e,t){var B,L,k,W;const{style:n,primaryWithCoord:r,unitId:a,subUnitId:i,worksheet:s,row:d,col:l}=t,c=r.isMergedMainCell?r.mergeInfo:r,h=C.getCellValueOrigin(s.getCellRaw(d,l)),g=this._dataValidationModel.getRuleByLocation(a,i,d,l);if(!g)return;const u=this._dataValidationModel.getValidator(g.type);if(!u||!((B=u.skipDefaultFontRender)!=null&&B.call(u,g,h,{unitId:a,subUnitId:i,row:d,column:l})))return;const S=u.parseFormulaSync(g,a,i),{formula1:v}=S,A=this._calc(c,n),{a:T,d:w}=e.getTransform(),y=O.fixLineWidthByScale(A.left,T),f=O.fixLineWidthByScale(A.top,w),D=O.Transform.create().composeMatrix({left:y,top:f,scaleX:1,scaleY:1,angle:0,skewX:0,skewY:0,flipX:!1,flipY:!1}),I=c.endX-c.startX,m=c.endY-c.startY;e.save(),e.beginPath(),e.rect(c.startX,c.startY,I,m),e.clip();const E=D.getMatrix();e.transform(E[0],E[1],E[2],E[3],E[4],E[5]);const j=((L=n==null?void 0:n.fs)!=null?L:10)*1.6,H=String(h)===String(v),F=this._themeService.getColorFromTheme("primary.600");O.CheckboxShape.drawWith(e,{checked:H,width:j,height:j,fill:(W=(k=n==null?void 0:n.cl)==null?void 0:k.rgb)!=null?W:F}),e.restore()}isHit(e,t){const n=t.primaryWithCoord.isMergedMainCell?t.primaryWithCoord.mergeInfo:t.primaryWithCoord,r=this._calc(n,t.style),a=r.top,i=r.top+r.height,s=r.left,d=r.left+r.width,{x:l,y:c}=e;return l<=d&&l>=s&&c<=i&&c>=a}async onPointerDown(e,t){var v;if(t.button===2)return;const{primaryWithCoord:n,unitId:r,subUnitId:a,worksheet:i,row:s,col:d}=e,l=C.getCellValueOrigin(i.getCellRaw(s,d)),c=this._dataValidationModel.getRuleByLocation(r,a,s,d);if(!c)return;const h=this._dataValidationModel.getValidator(c.type);if(!h||!((v=h.skipDefaultFontRender)!=null&&v.call(h,c,l,{unitId:r,subUnitId:a,row:s,column:d})))return;const{formula1:g,formula2:u}=await this._parseFormula(c,r,a),S={range:{startColumn:n.actualColumn,endColumn:n.actualColumn,startRow:n.actualRow,endRow:n.actualRow},value:{v:String(l)===C.transformCheckboxValue(String(g))?u:g,p:null}};this._commandService.executeCommand(Y.SetRangeValuesCommand.id,S)}onPointerEnter(e,t){var n,r;(r=(n=O.getCurrentTypeOfRenderer(o.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.mainComponent)==null||r.setCursor(O.CURSOR_TYPE.POINTER)}onPointerLeave(e,t){var n,r;(r=(n=O.getCurrentTypeOfRenderer(o.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.mainComponent)==null||r.setCursor(O.CURSOR_TYPE.DEFAULT)}};tt=Tn([be(0,o.ICommandService),be(1,o.IUniverInstanceService),be(2,o.Inject(C.DataValidationFormulaService)),be(3,o.Inject(o.ThemeService)),be(4,o.Inject(O.IRenderManagerService)),be(5,o.Inject(C.SheetDataValidationModel))],tt);var Vn=Object.getOwnPropertyDescriptor,Rn=(e,t,n,r)=>{for(var a=r>1?void 0:r?Vn(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},On=(e,t)=>(n,r)=>t(n,r,e);U.BaseSheetDataValidatorView=class{constructor(t){P(this,"canvasRender",null);P(this,"dropdownType");P(this,"optionsInput");P(this,"formulaInput",C.LIST_FORMULA_INPUT_NAME);this.injector=t}},U.BaseSheetDataValidatorView=Rn([On(0,o.Inject(o.Injector))],U.BaseSheetDataValidatorView);class An extends U.BaseSheetDataValidatorView{constructor(){super(...arguments);P(this,"id",o.DataValidationType.CHECKBOX);P(this,"canvasRender",this.injector.createInstance(tt));P(this,"formulaInput",C.CHECKBOX_FORMULA_INPUT_NAME)}}class Ln extends U.BaseSheetDataValidatorView{constructor(){super(...arguments);P(this,"id",o.DataValidationType.CUSTOM);P(this,"formulaInput",C.CUSTOM_FORMULA_INPUT_NAME)}}const Pn="data-validation.formula-input";class Un extends U.BaseSheetDataValidatorView{constructor(){super(...arguments);P(this,"id",o.DataValidationType.DATE);P(this,"formulaInput",Pn);P(this,"optionsInput",je.componentKey);P(this,"dropdownType",X.DataValidatorDropdownType.DATE)}}class Fn extends U.BaseSheetDataValidatorView{constructor(){super(...arguments);P(this,"id",o.DataValidationType.DECIMAL);P(this,"formulaInput",C.BASE_FORMULA_INPUT_NAME)}}const Mt=4,kn=0,nt=4,bt=4,rt=6,We=6,_e=14;function Nn(e,t){const n=O.FontCache.getTextSize(e,t),r=n.width+Mt*2,{ba:a,bd:i}=n,s=a+i;return{width:r,height:s+kn*2,ba:a}}function at(e,t,n,r){const a=_e+rt*2,i=n-a,s=r-We*2,d=e.map(u=>({layout:Nn(u,t),text:u}));let l;const c=[];d.forEach(u=>{const{layout:S}=u,{width:v,height:A}=S;!l||l.width+v+nt>i?(l={width:v,height:A,items:[{...u,left:0}]},c.push(l)):(l.items.push({...u,left:l.width+nt}),l.width=l.width+v+nt)});let h=0,g=0;return c.forEach((u,S)=>{g=Math.max(g,u.width),S===c.length-1?h+=u.height:h+=u.height+bt}),{lines:c,totalHeight:h,contentWidth:i,contentHeight:s,cellAutoHeight:h+We*2,calcAutoWidth:g+a}}const jn=8;class Bn extends O.Shape{static drawWith(t,n){const{fontString:r,info:a,fill:i,color:s}=n,{layout:d,text:l}=a;t.save(),O.Rect.drawWith(t,{width:d.width,height:d.height,radius:jn,fill:i||ve}),t.translateWithPrecision(Mt,d.ba),t.font=r,t.fillStyle=s,t.fillText(l,0,0),t.restore()}}var Wn=Object.getOwnPropertyDescriptor,$n=(e,t,n,r)=>{for(var a=r>1?void 0:r?Wn(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},$e=(e,t)=>(n,r)=>t(n,r,e);const Hn=new Path2D("M3.32201 4.84556C3.14417 5.05148 2.85583 5.05148 2.67799 4.84556L0.134292 1.90016C-0.152586 1.56798 0.0505937 1 0.456301 1L5.5437 1C5.94941 1 6.15259 1.56798 5.86571 1.90016L3.32201 4.84556Z");let it=class{constructor(e,t,n,r){P(this,"zIndex");P(this,"_dropdownInfoMap",new Map);this._commandService=e,this._univerInstanceService=t,this._renderManagerService=n,this._dataValidationModel=r}_ensureMap(e){let t=this._dropdownInfoMap.get(e);return t||(t=new Map,this._dropdownInfoMap.set(e,t)),t}_generateKey(e,t){return`${e}.${t}`}_drawDownIcon(e,t,n,r,a){const i=n-_e+4;let s=4;switch(a){case o.VerticalAlign.MIDDLE:s=(r-_e)/2+4;break;case o.VerticalAlign.BOTTOM:s=r-_e+4;break}e.save(),e.translateWithPrecision(t.startX+i,t.startY+s),e.fillStyle="#565656",e.fill(Hn),e.restore()}drawWith(e,t,n,r){var ie,he;const{primaryWithCoord:a,row:i,col:s,style:d,data:l,subUnitId:c}=t,h=a.isMergedMainCell?a.mergeInfo:a,g=l==null?void 0:l.fontRenderExtension,{leftOffset:u=0,rightOffset:S=0,topOffset:v=0,downOffset:A=0}=g||{},T=this._ensureMap(c),w=this._generateKey(i,s),y=a.isMergedMainCell?a.mergeInfo.startRow:i,f=a.isMergedMainCell?a.mergeInfo.startColumn:s,D=this._dataValidationModel.getRuleByLocation(t.unitId,t.subUnitId,y,f);if(!D)return;const I=this._dataValidationModel.getValidator(D.type);if(!I)return;const m={startX:h.startX+u,endX:h.endX-S,startY:h.startY+v,endY:h.endY-A},E=m.endX-m.startX,j=m.endY-m.startY,{cl:H}=d||{},F=(ie=typeof H=="object"?H==null?void 0:H.rgb:H)!=null?ie:"#000",B=O.getFontStyleString(d!=null?d:void 0),{vt:L,ht:k}=d||{},W=L!=null?L:o.VerticalAlign.MIDDLE,K=(he=C.getCellValueOrigin(l))!=null?he:"",J=I.parseCellValue(K),ne=I.getListWithColorMap(D),Z=at(J,B,E,j);this._drawDownIcon(e,m,E,j,W),e.save(),e.translateWithPrecision(m.startX,m.startY),e.beginPath(),e.rect(0,0,E-_e,j),e.clip(),e.translateWithPrecision(rt,We);let re=0;switch(W){case o.VerticalAlign.MIDDLE:re=(Z.contentHeight-Z.totalHeight)/2;break;case o.VerticalAlign.BOTTOM:re=Z.contentHeight-Z.totalHeight;break}e.translateWithPrecision(0,re),Z.lines.forEach((pe,Q)=>{e.save();const{width:q,height:ce,items:ee}=pe;let V=0;switch(k){case o.HorizontalAlign.RIGHT:V=Z.contentWidth-q;break;case o.HorizontalAlign.CENTER:V=(Z.contentWidth-q)/2;break}e.translate(V,Q*(ce+bt)),ee.forEach(x=>{e.save(),e.translateWithPrecision(x.left,0),Bn.drawWith(e,{...B,info:x,color:F,fill:ne[x.text]}),e.restore()}),e.restore()}),e.restore(),T.set(w,{left:m.startX,top:m.startY,width:Z.contentWidth+rt+_e,height:Z.contentHeight+We*2})}calcCellAutoHeight(e){var I;const{primaryWithCoord:t,style:n,data:r,row:a,col:i}=e,s=r==null?void 0:r.fontRenderExtension,{leftOffset:d=0,rightOffset:l=0,topOffset:c=0,downOffset:h=0}=s||{},g=t.isMergedMainCell?t.mergeInfo:t,u={startX:g.startX+d,endX:g.endX-l,startY:g.startY+c,endY:g.endY-h},S=this._dataValidationModel.getRuleByLocation(e.unitId,e.subUnitId,a,i);if(!S)return;const v=this._dataValidationModel.getValidator(S.type);if(!v)return;const A=u.endX-u.startX,T=u.endY-u.startY,w=(I=C.getCellValueOrigin(r))!=null?I:"",y=v.parseCellValue(w),f=O.getFontStyleString(n!=null?n:void 0);return at(y,f,A,T).cellAutoHeight}calcCellAutoWidth(e){var I;const{primaryWithCoord:t,style:n,data:r,row:a,col:i}=e,s=r==null?void 0:r.fontRenderExtension,{leftOffset:d=0,rightOffset:l=0,topOffset:c=0,downOffset:h=0}=s||{},g=t.isMergedMainCell?t.mergeInfo:t,u={startX:g.startX+d,endX:g.endX-l,startY:g.startY+c,endY:g.endY-h},S=this._dataValidationModel.getRuleByLocation(e.unitId,e.subUnitId,a,i);if(!S)return;const v=this._dataValidationModel.getValidator(S.type);if(!v)return;const A=u.endX-u.startX,T=u.endY-u.startY,w=(I=C.getCellValueOrigin(r))!=null?I:"",y=v.parseCellValue(w),f=O.getFontStyleString(n!=null?n:void 0);return at(y,f,A,T).calcAutoWidth}isHit(e,t){const{primaryWithCoord:n}=t,r=n.isMergedMainCell?n.mergeInfo:n,{endX:a}=r,{x:i}=e;return i>=a-_e&&i<=a}onPointerDown(e,t){if(t.button===2)return;const{unitId:n,subUnitId:r,row:a,col:i}=e,s={unitId:n,subUnitId:r,row:a,column:i};this._commandService.executeCommand(Ue.id,s)}onPointerEnter(e,t){var n,r;return(r=(n=O.getCurrentTypeOfRenderer(o.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.mainComponent)==null?void 0:r.setCursor(O.CURSOR_TYPE.POINTER)}onPointerLeave(e,t){var n,r;return(r=(n=O.getCurrentTypeOfRenderer(o.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.mainComponent)==null?void 0:r.setCursor(O.CURSOR_TYPE.DEFAULT)}};it=$n([$e(0,o.ICommandService),$e(1,o.IUniverInstanceService),$e(2,o.Inject(O.IRenderManagerService)),$e(3,o.Inject(C.SheetDataValidationModel))],it);class xn extends U.BaseSheetDataValidatorView{constructor(){super(...arguments);P(this,"id",o.DataValidationType.LIST_MULTIPLE);P(this,"canvasRender",this.injector.createInstance(it));P(this,"dropdownType",X.DataValidatorDropdownType.MULTIPLE_LIST)}}var Yn=Object.getOwnPropertyDescriptor,Xn=(e,t,n,r)=>{for(var a=r>1?void 0:r?Yn(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},Ae=(e,t)=>(n,r)=>t(n,r,e);const Te=4,He=4,se=14,ot=1,ue=6,Ve=3,st=8,zn="#565656",Tt=new Path2D("M3.32201 4.84556C3.14417 5.05148 2.85583 5.05148 2.67799 4.84556L0.134292 1.90016C-0.152586 1.56798 0.0505937 1 0.456301 1L5.5437 1C5.94941 1 6.15259 1.56798 5.86571 1.90016L3.32201 4.84556Z");function Vt(e,t,n,r,a,i,s=!0){let d=0;const l=s?Ve:0;switch(a){case o.VerticalAlign.BOTTOM:d=t-r-l;break;case o.VerticalAlign.MIDDLE:d=(t-r)/2;break;default:d=l;break}d=Math.max(Ve,d);let c=0;switch(i){case o.HorizontalAlign.CENTER:c=(e-n)/2;break;case o.HorizontalAlign.RIGHT:c=e-n;break}return c=Math.max(ue,c),{paddingLeft:c,paddingTop:d}}let lt=class{constructor(e,t,n,r,a){P(this,"_dropdownInfoMap",new Map);P(this,"zIndex");this._univerInstanceService=e,this._localeService=t,this._commandService=n,this._renderManagerService=r,this._dataValidationModel=a}_ensureMap(e){let t=this._dropdownInfoMap.get(e);return t||(t=new Map,this._dropdownInfoMap.set(e,t)),t}_generateKey(e,t){return`${e}.${t}`}_drawDownIcon(e,t,n,r,a,i,s){const{t:d=o.DEFAULT_STYLES.pd.t,b:l=o.DEFAULT_STYLES.pd.b}=s,c=n-se;let h;switch(i){case o.VerticalAlign.MIDDLE:h=(r-He)/2;break;case o.VerticalAlign.BOTTOM:h=r-l-a-Ve+(a/2-He/2);break;default:h=d+Ve+(a/2-He/2);break}e.save(),e.translateWithPrecision(t.startX+c,t.startY+h),e.fillStyle="#565656",e.fill(Tt),e.restore()}drawWith(e,t,n){var ne,Z,re,ie,he,pe;const{primaryWithCoord:r,row:a,col:i,style:s,data:d,subUnitId:l}=t,c=r.isMergedMainCell?r.mergeInfo:r,h=r.isMergedMainCell?r.mergeInfo.startRow:a,g=r.isMergedMainCell?r.mergeInfo.startColumn:i,u=this._dataValidationModel.getRuleByLocation(t.unitId,t.subUnitId,h,g);if(!u)return;const S=this._dataValidationModel.getValidator(u.type);if(!S)return;const v=d==null?void 0:d.fontRenderExtension,{leftOffset:A=0,rightOffset:T=0,topOffset:w=0,downOffset:y=0}=v||{};if(!u||!S||!S||S.id.indexOf(o.DataValidationType.LIST)!==0||!S.skipDefaultFontRender(u))return;const f={startX:c.startX+A,endX:c.endX-T,startY:c.startY+w,endY:c.endY-y},D=f.endX-f.startX,I=f.endY-f.startY,m=this._ensureMap(l),E=this._generateKey(a,i),j=S.getListWithColor(u),H=C.getCellValueOrigin(d),F=`${H!=null?H:""}`,B=j.find(Q=>Q.label===F);let{tb:L,vt:k,ht:W,pd:K}=s||{};L=L!=null?L:o.WrapStrategy.WRAP,k=k!=null?k:o.VerticalAlign.BOTTOM,W=W!=null?W:o.DEFAULT_STYLES.ht,K=K!=null?K:o.DEFAULT_STYLES.pd;const J=O.getFontStyleString(s).fontCache;if(u.renderMode===o.DataValidationRenderMode.ARROW){const{l:Q=o.DEFAULT_STYLES.pd.l,t:q=o.DEFAULT_STYLES.pd.t,r:ce=o.DEFAULT_STYLES.pd.r,b:ee=o.DEFAULT_STYLES.pd.b}=K,V=D-Q-ce-se-4,x=new O.DocSimpleSkeleton(F,J,L===o.WrapStrategy.WRAP,V,1/0);x.calculate();const _=x.getTotalWidth(),N=x.getTotalHeight(),{paddingTop:z,paddingLeft:le}=Vt(V,I-q-ee,_,N,k,W,!0);this._drawDownIcon(e,f,D,I,N,k,K),e.save(),e.translateWithPrecision(f.startX+Q,f.startY+q),e.beginPath(),e.rect(0,0,D-Q-ce,I-q-ee),e.clip(),e.translateWithPrecision(0,z),e.save(),e.translateWithPrecision(le,0),e.beginPath(),e.rect(0,0,V,N),e.clip(),O.Text.drawWith(e,{text:F,fontStyle:J,width:V,height:N,color:(ne=s==null?void 0:s.cl)==null?void 0:ne.rgb,strokeLine:!!((Z=s==null?void 0:s.st)!=null&&Z.s),underline:!!((re=s==null?void 0:s.ul)!=null&&re.s),warp:L===o.WrapStrategy.WRAP,hAlign:o.HorizontalAlign.LEFT},x),e.restore(),e.restore(),m.set(E,{left:f.endX-se+n.rowHeaderWidth,top:f.startY+q+n.columnHeaderHeight,width:se,height:I-q-ee})}else{e.save(),e.translateWithPrecision(f.startX,f.startY),e.beginPath(),e.rect(0,0,D,I),e.clip();const Q=D-ue*2-Te-se-4,q=new O.DocSimpleSkeleton(F,J,L===o.WrapStrategy.WRAP,Q,1/0);q.calculate();const ce=q.getTotalWidth(),ee=q.getTotalHeight(),V=ee+ot*2,x=Math.max(D-ue*2,1),{paddingTop:_}=Vt(x,I,ce,V,k,W);e.translateWithPrecision(ue,_),O.Rect.drawWith(e,{width:x,height:V,fill:(B==null?void 0:B.color)||ve,radius:st}),e.save(),e.translateWithPrecision(Te,ot),e.beginPath(),e.rect(0,0,Q,ee),e.clip(),O.Text.drawWith(e,{text:F,fontStyle:J,width:Q,height:ee,color:(ie=s==null?void 0:s.cl)==null?void 0:ie.rgb,strokeLine:!!((he=s==null?void 0:s.st)!=null&&he.s),underline:!!((pe=s==null?void 0:s.ul)!=null&&pe.s),warp:L===o.WrapStrategy.WRAP,hAlign:o.HorizontalAlign.LEFT},q),e.restore(),e.translateWithPrecision(Q+Te+4,(ee-He)/2),e.fillStyle=zn,e.fill(Tt),e.restore(),m.set(E,{left:f.startX+ue+n.rowHeaderWidth,top:f.startY+_+n.columnHeaderHeight,width:x,height:V})}}calcCellAutoHeight(e){const{primaryWithCoord:t,style:n,data:r,row:a,col:i}=e,s=t.isMergedMainCell?t.mergeInfo:t,d=r==null?void 0:r.fontRenderExtension,{leftOffset:l=0,rightOffset:c=0,topOffset:h=0,downOffset:g=0}=d||{},u=this._dataValidationModel.getRuleByLocation(e.unitId,e.subUnitId,a,i);if(!u||u.renderMode===o.DataValidationRenderMode.TEXT)return;const S={startX:s.startX+l,endX:s.endX-c,startY:s.startY+h,endY:s.endY-g},v=S.endX-S.startX,A=C.getCellValueOrigin(r),T=`${A!=null?A:""}`;let{tb:w,pd:y}=n||{};const{t:f=o.DEFAULT_STYLES.pd.t,b:D=o.DEFAULT_STYLES.pd.b}=y!=null?y:{};if(w=w!=null?w:o.WrapStrategy.WRAP,u.renderMode===o.DataValidationRenderMode.ARROW){const{l:I=o.DEFAULT_STYLES.pd.l,r:m=o.DEFAULT_STYLES.pd.r}=y!=null?y:{},E=v-I-m-se-4,j=new O.DocSimpleSkeleton(T,O.getFontStyleString(n).fontCache,w===o.WrapStrategy.WRAP,E,1/0);return j.calculate(),j.getTotalHeight()+f+D+Ve*2}else{const I=Math.max(v-ue*2-Te-se-4,10),m=new O.DocSimpleSkeleton(T,O.getFontStyleString(n).fontCache,w===o.WrapStrategy.WRAP,I,1/0);return m.calculate(),m.getTotalHeight()+Ve*2+ot*2}}calcCellAutoWidth(e){const{primaryWithCoord:t,style:n,data:r,row:a,col:i}=e,s=t.isMergedMainCell?t.mergeInfo:t,d=r==null?void 0:r.fontRenderExtension,{leftOffset:l=0,rightOffset:c=0,topOffset:h=0,downOffset:g=0}=d||{},u=this._dataValidationModel.getRuleByLocation(e.unitId,e.subUnitId,a,i);if(!u||u.renderMode===o.DataValidationRenderMode.TEXT)return;const S={startX:s.startX+l,endX:s.endX-c,startY:s.startY+h,endY:s.endY-g},v=S.endX-S.startX,A=C.getCellValueOrigin(r),T=`${A!=null?A:""}`;let{tb:w,pd:y}=n||{};const{l:f=o.DEFAULT_STYLES.pd.l,r:D=o.DEFAULT_STYLES.pd.r}=y!=null?y:{};w=w!=null?w:o.WrapStrategy.WRAP;let I=ue*2+se;switch(u.renderMode){case o.DataValidationRenderMode.ARROW:I=se+4+D+f;break;case o.DataValidationRenderMode.CUSTOM:I=se+ue*2+Te*2+D+f+st/2+1;break;default:I=se+ue*2+Te*2+D+f+st/2+1}const m=v-I,E=new O.DocSimpleSkeleton(T,O.getFontStyleString(n).fontCache,w===o.WrapStrategy.WRAP,m,1/0);return E.calculate(),E.getTotalWidth()+I}isHit(e,t){const{subUnitId:n,row:r,col:a}=t,s=this._ensureMap(n).get(this._generateKey(r,a)),d=this._dataValidationModel.getRuleByLocation(t.unitId,t.subUnitId,r,a);if(!d||!s||d.renderMode===o.DataValidationRenderMode.TEXT)return!1;const{top:l,left:c,width:h,height:g}=s,{x:u,y:S}=e;return u>=c&&u<=c+h&&S>=l&&S<=l+g}onPointerDown(e,t){if(t.button===2)return;const{unitId:n,subUnitId:r,row:a,col:i}=e,s={unitId:n,subUnitId:r,row:a,column:i};this._commandService.executeCommand(Ue.id,s)}onPointerEnter(e,t){var n,r;(r=(n=O.getCurrentTypeOfRenderer(o.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.mainComponent)==null||r.setCursor(O.CURSOR_TYPE.POINTER)}onPointerLeave(e,t){var n,r;(r=(n=O.getCurrentTypeOfRenderer(o.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.mainComponent)==null||r.setCursor(O.CURSOR_TYPE.DEFAULT)}};lt=Xn([Ae(0,o.IUniverInstanceService),Ae(1,o.Inject(o.LocaleService)),Ae(2,o.ICommandService),Ae(3,o.Inject(O.IRenderManagerService)),Ae(4,o.Inject(C.SheetDataValidationModel))],lt);class Kn extends U.BaseSheetDataValidatorView{constructor(){super(...arguments);P(this,"id",o.DataValidationType.LIST);P(this,"canvasRender",this.injector.createInstance(lt));P(this,"dropdownType",X.DataValidatorDropdownType.LIST);P(this,"optionsInput",Ne.componentKey);P(this,"formulaInput",C.LIST_FORMULA_INPUT_NAME)}}class Zn extends U.BaseSheetDataValidatorView{constructor(){super(...arguments);P(this,"id",o.DataValidationType.TEXT_LENGTH);P(this,"formulaInput",C.BASE_FORMULA_INPUT_NAME)}}class Gn extends U.BaseSheetDataValidatorView{constructor(){super(...arguments);P(this,"id",o.DataValidationType.WHOLE);P(this,"formulaInput",C.BASE_FORMULA_INPUT_NAME)}}var qn=Object.getOwnPropertyDescriptor,Jn=(e,t,n,r)=>{for(var a=r>1?void 0:r?qn(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},dt=(e,t)=>(n,r)=>t(n,r,e);let Re=class extends o.RxDisposable{constructor(e,t,n){super(),this._injector=e,this._componentManger=t,this._dataValidatorRegistryService=n,this._initComponents(),this._registerValidatorViews()}_initComponents(){[["DataValidationIcon",Ct],[Pe,mn],[Ne.componentKey,Ne],[je.componentKey,je],...Dn].forEach(([e,t])=>{this.disposeWithMe(this._componentManger.register(e,t))})}_registerValidatorViews(){[Fn,Gn,Zn,Un,An,Kn,xn,Ln].forEach(e=>{const t=this._injector.createInstance(e),n=this._dataValidatorRegistryService.getValidatorItem(t.id);n&&(n.formulaInput=t.formulaInput,n.canvasRender=t.canvasRender,n.dropdownType=t.dropdownType,n.optionsInput=t.optionsInput)})}};Re=Jn([dt(0,o.Inject(o.Injector)),dt(1,o.Inject(b.ComponentManager)),dt(2,o.Inject(X.DataValidatorRegistryService))],Re);var Qn=Object.getOwnPropertyDescriptor,er=(e,t,n,r)=>{for(var a=r>1?void 0:r?Qn(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},ct=(e,t)=>(n,r)=>t(n,r,e);const tr="SHEET_DATA_VALIDATION_UI_PLUGIN";U.UniverSheetsDataValidationMobileUIPlugin=(xe=class extends o.Plugin{constructor(t=Le,n,r,a){super(),this._config=t,this._injector=n,this._commandService=r,this._configService=a;const{menu:i,...s}=o.merge({},Le,this._config);i&&this._configService.setConfig("menu",i,{merge:!0}),this._configService.setConfig(ze,s)}onStarting(){[[de],[ge],[Oe],[we],[Me],[Ee],[De],[Re]].forEach(t=>{this._injector.add(t)}),[Fe,Ue,vt,Ze,fe,pt].forEach(t=>{this._commandService.registerCommand(t)})}onReady(){this._injector.get(De),this._injector.get(Ee),this._injector.get(O.IRenderManagerService).registerRenderModule(o.UniverInstanceType.UNIVER_SHEET,[ke])}onRendered(){this._injector.get(Re),this._injector.get(Me)}onSteady(){this._injector.get(we)}},P(xe,"pluginName",tr),P(xe,"type",o.UniverInstanceType.UNIVER_SHEET),xe),U.UniverSheetsDataValidationMobileUIPlugin=er([ct(1,o.Inject(o.Injector)),ct(2,o.ICommandService),ct(3,o.IConfigService)],U.UniverSheetsDataValidationMobileUIPlugin);var nr=Object.defineProperty,rr=Object.getOwnPropertyDescriptor,ar=(e,t,n)=>t in e?nr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ir=(e,t,n,r)=>{for(var a=r>1?void 0:r?rr(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},ut=(e,t)=>(n,r)=>t(n,r,e),Rt=(e,t,n)=>ar(e,typeof t!="symbol"?t+"":t,n);const or="SHEET_DATA_VALIDATION_UI_PLUGIN";U.UniverSheetsDataValidationUIPlugin=class extends o.Plugin{constructor(t=Le,n,r,a){super(),this._config=t,this._injector=n,this._commandService=r,this._configService=a;const{menu:i,...s}=o.merge({},Le,this._config);i&&this._configService.setConfig("menu",i,{merge:!0}),this._configService.setConfig(ze,s)}onStarting(){[[de],[ge],[Oe],[we],[Me],[Ee],[De],[Ce],[Re]].forEach(t=>{this._injector.add(t)}),[Fe,Ue,vt,Ze,fe,pt].forEach(t=>{this._commandService.registerCommand(t)})}onReady(){this._injector.get(De),this._injector.get(Ee),this._injector.get(Ce),this._injector.get(Oe),this._injector.get(O.IRenderManagerService).registerRenderModule(o.UniverInstanceType.UNIVER_SHEET,[ke])}onRendered(){this._injector.get(Re),this._injector.get(Me)}onSteady(){this._injector.get(we)}},Rt(U.UniverSheetsDataValidationUIPlugin,"pluginName",or),Rt(U.UniverSheetsDataValidationUIPlugin,"type",o.UniverInstanceType.UNIVER_SHEET),U.UniverSheetsDataValidationUIPlugin=ir([o.DependentOn(C.UniverSheetsDataValidationPlugin),ut(1,o.Inject(o.Injector)),ut(2,o.ICommandService),ut(3,o.IConfigService)],U.UniverSheetsDataValidationUIPlugin),Object.defineProperty(U,Symbol.toStringTag,{value:"Module"})}));
18
+ `,{"hover:univer-bg-gray-50 dark:hover:!univer-bg-gray-700":!i,"univer-opacity-50":i}),onClick:n,onMouseEnter:()=>{i||(u(!0),h.current=t.ranges.map(w=>l.addShape({range:w,style:A,primary:null})))},onMouseLeave:()=>{var w;u(!1),(w=h.current)==null||w.forEach(y=>{y&&l.removeShape(y)}),h.current=void 0},children:[p.jsx("div",{className:"univer-truncate univer-text-sm univer-font-medium univer-leading-[22px] univer-text-gray-900 dark:!univer-text-white",children:c==null?void 0:c.generateRuleName(t)}),p.jsx("div",{className:"univer-text-secondary univer-truncate univer-text-xs univer-leading-[18px] dark:!univer-text-gray-300",children:t.ranges.map(w=>Ye.serializeRange(w)).join(",")}),g?p.jsx("div",{className:"univer-absolute univer-right-2 univer-top-[19px] univer-flex univer-h-5 univer-w-5 univer-items-center univer-justify-center univer-rounded hover:univer-bg-gray-200 dark:!univer-text-gray-300 dark:hover:!univer-bg-gray-700",onClick:T,children:p.jsx(Qe,{})}):null]})};function fn(e){const t=b.useDependency(C.SheetDataValidationModel),n=b.useDependency(o.IUniverInstanceService),r=b.useDependency(o.ICommandService),a=b.useDependency(o.Injector),i=b.useDependency(de),s=b.useDependency(o.LocaleService),[d,l]=R.useState([]),{workbook:c}=e,h=b.useObservable(c.activeSheet$,void 0,!0),g=c.getUnitId(),u=h==null?void 0:h.getSheetId();R.useEffect(()=>{l(t.getRules(g,u));const y=t.ruleChange$.subscribe(f=>{f.unitId===g&&f.subUnitId===u&&l(t.getRules(g,u))});return()=>{y.unsubscribe()}},[g,u,t]);const S=async()=>{const y=C.createDefaultNewRule(a),f={unitId:g,subUnitId:u,rule:y};await r.executeCommand(C.AddSheetDataValidationCommand.id,f),i.setActiveRule({unitId:g,subUnitId:u,rule:y})},v=()=>{r.executeCommand(C.RemoveSheetAllDataValidationCommand.id,{unitId:g,subUnitId:u})},T=(y=>{const f=n.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET),D=f.getActiveSheet(),I=f.getUnitId(),m=D.getSheetId();return y.map(j=>Y.checkRangesEditablePermission(a,I,m,j.ranges)?{...j}:{...j,disable:!0})})(d),w=T==null?void 0:T.some(y=>y.disable);return p.jsxs("div",{className:"univer-pb-4",children:[T==null?void 0:T.map(y=>{var f;return p.jsx(gn,{unitId:g,subUnitId:u,onClick:()=>{y.disable||i.setActiveRule({unitId:g,subUnitId:u,rule:y})},rule:y,disable:(f=y.disable)!=null?f:!1},y.uid)}),p.jsxs("div",{className:"univer-mt-4 univer-flex univer-flex-row univer-justify-end univer-gap-2",children:[d.length&&!w?p.jsx(M.Button,{onClick:v,children:s.t("dataValidation.panel.removeAll")}):null,p.jsx(M.Button,{variant:"primary",onClick:S,children:s.t("dataValidation.panel.add")})]})]})}const mn=()=>{const e=b.useDependency(de),t=b.useObservable(e.activeRule$,e.activeRule),n=b.useDependency(o.IUniverInstanceService),r=b.useObservable(()=>n.getCurrentTypeOfUnit$(o.UniverInstanceType.UNIVER_SHEET),void 0,void 0,[]),a=b.useObservable(()=>{var i;return(i=r==null?void 0:r.activeSheet$)!=null?i:ae.of(null)},void 0,void 0,[]);return!r||!a?null:t&&t.subUnitId===a.getSheetId()?p.jsx(vn,{},t.rule.uid):p.jsx(fn,{workbook:r})},Sn=e=>{const{isTwoFormula:t=!1,value:n,onChange:r,showError:a,validResult:i}=e,s=b.useDependency(o.LocaleService),d=a?i==null?void 0:i.formula1:"",l=a?i==null?void 0:i.formula2:"";return t?p.jsxs(p.Fragment,{children:[p.jsx(M.FormLayout,{error:d,children:p.jsx(M.Input,{className:"univer-w-full",placeholder:s.t("dataValidation.panel.formulaPlaceholder"),value:n==null?void 0:n.formula1,onChange:c=>{r==null||r({...n,formula1:c})}})}),p.jsx("div",{className:"-univer-mt-2 univer-mb-1 univer-text-sm univer-text-gray-400",children:s.t("dataValidation.panel.formulaAnd")}),p.jsx(M.FormLayout,{error:l,children:p.jsx(M.Input,{className:"univer-w-full",placeholder:s.t("dataValidation.panel.formulaPlaceholder"),value:n==null?void 0:n.formula2,onChange:c=>{r==null||r({...n,formula2:c})}})})]}):p.jsx(M.FormLayout,{error:d,children:p.jsx(M.Input,{className:"univer-w-full",placeholder:s.t("dataValidation.panel.formulaPlaceholder"),value:n==null?void 0:n.formula1,onChange:c=>{r==null||r({formula1:c})}})})};function _n(e){const{value:t,onChange:n,showError:r,validResult:a}=e,i=b.useDependency(o.LocaleService),s=r?a==null?void 0:a.formula1:"",d=r?a==null?void 0:a.formula2:"",[l,c]=R.useState(!((t==null?void 0:t.formula1)===void 0&&(t==null?void 0:t.formula2)===void 0));return p.jsxs(p.Fragment,{children:[p.jsx(M.FormLayout,{children:p.jsx(M.Checkbox,{checked:l,onChange:h=>{h?c(!0):(c(!1),n==null||n({...t,formula1:void 0,formula2:void 0}))},children:i.t("dataValidation.checkbox.tips")})}),l?p.jsx(M.FormLayout,{label:i.t("dataValidation.checkbox.checked"),error:s,children:p.jsx(M.Input,{className:"univer-w-full",placeholder:i.t("dataValidation.panel.valuePlaceholder"),value:t==null?void 0:t.formula1,onChange:h=>{n==null||n({...t,formula1:h||void 0})}})}):null,l?p.jsx(M.FormLayout,{label:i.t("dataValidation.checkbox.unchecked"),error:d,children:p.jsx(M.Input,{className:"univer-w-full",placeholder:i.t("dataValidation.panel.valuePlaceholder"),value:t==null?void 0:t.formula2,onChange:h=>{n==null||n({...t,formula2:h||void 0})}})}):null]})}function In(e){var g;const{unitId:t,subUnitId:n,value:r,onChange:a,showError:i,validResult:s}=e,d=i?s==null?void 0:s.formula1:void 0,l=R.useRef(null),[c,h]=R.useState(!1);return b.useSidebarClick(u=>{var v;((v=l.current)==null?void 0:v.isClickOutSide(u))&&h(!1)}),p.jsx(M.FormLayout,{error:d,children:p.jsx(Xe.FormulaEditor,{ref:l,className:M.clsx("univer-box-border univer-h-8 univer-w-full univer-cursor-pointer univer-items-center univer-rounded-lg univer-bg-white univer-pt-2 univer-transition-colors hover:univer-border-primary-600 dark:!univer-bg-gray-700 dark:!univer-text-white [&>div:first-child]:univer-px-2.5 [&>div]:univer-h-5 [&>div]:univer-ring-transparent",M.borderClassName),initValue:(g=r==null?void 0:r.formula1)!=null?g:"=",unitId:t,subUnitId:n,isFocus:c,isSupportAcrossSheet:!0,onChange:u=>{const S=(u!=null?u:"").trim();S!==(r==null?void 0:r.formula1)&&(a==null||a({...r,formula1:S}))},onFocus:()=>h(!0)})})}const Cn=["#FFFFFF","#FEE7E7","#FEF0E6","#EFFBD0","#E4F4FE","#E8ECFD","#F1EAFA","#FDE8F3","#E5E5E5","#FDCECE","#FDC49B","#DEF6A2","#9FDAFF","#D0D9FB","#E3D5F6","#FBD0E8","#656565","#FE4B4B","#FF8C51","#8BBB11","#0B9EFB","#3A60F7","#9E6DE3","#F248A6"],yn=e=>{const{value:t,onChange:n,disabled:r}=e,[a,i]=R.useState(!1);return p.jsx(M.Dropdown,{align:"start",disabled:r,open:a,onOpenChange:i,overlay:p.jsx("div",{className:"univer-box-border univer-grid univer-w-fit univer-grid-cols-6 univer-flex-wrap univer-gap-2 univer-p-1.5",children:Cn.map(s=>p.jsx("div",{className:M.clsx("univer-box-border univer-size-4 univer-cursor-pointer univer-rounded",M.borderClassName),style:{background:s},onClick:()=>{n(s),i(!1)}},s))}),children:p.jsxs("div",{className:M.clsx("univer-box-border univer-inline-flex univer-h-8 univer-w-16 univer-cursor-pointer univer-items-center univer-justify-between univer-gap-2 univer-rounded-lg univer-bg-white univer-px-2.5 univer-transition-colors univer-duration-200 hover:univer-border-primary-600 dark:!univer-bg-gray-700 dark:!univer-text-white",M.borderClassName),children:[p.jsx("div",{className:"univer-box-border univer-h-4 univer-w-4 univer-rounded univer-text-base",style:{background:t}}),p.jsx(et,{})]})})},Et=e=>{const{item:t,commonProps:n,className:r}=e,{onItemChange:a,onItemDelete:i}=n;return p.jsxs("div",{className:M.clsx("univer-flex univer-items-center univer-gap-2",r),children:[!t.isRef&&p.jsx("div",{className:M.clsx("univer-cursor-move","draggableHandle"),children:p.jsx(Dt,{})}),p.jsx(yn,{value:t.color,onChange:s=>{a(t.id,t.label,s)}}),p.jsx(M.Input,{disabled:t.isRef,value:t.label,onChange:s=>{a(t.id,s,t.color)}}),t.isRef?null:p.jsx("div",{className:"univer-ml-1 univer-cursor-pointer univer-rounded univer-text-base hover:univer-bg-gray-200",children:p.jsx(Qe,{onClick:()=>i(t.id)})})]})};function wn(e){const{value:t,onChange:n=()=>{},unitId:r,subUnitId:a,validResult:i,showError:s,ruleId:d}=e,{formula1:l="",formula2:c=""}=t||{},[h,g]=R.useState(()=>o.isFormulaString(l)?"1":"0"),[u,S]=R.useState(h==="1"?l:"="),[v,A]=R.useState(h==="1"?l:"="),T=b.useDependency(o.LocaleService),w=b.useDependency(X.DataValidatorRegistryService),y=b.useDependency(X.DataValidationModel),f=b.useDependency(C.DataValidationFormulaController),[D,I]=R.useState(()=>c.split(",")),m=w.getValidatorItem(o.DataValidationType.LIST),[E,j]=R.useState([]),[$,F]=R.useState(""),H=s?i==null?void 0:i.formula1:"",L=R.useMemo(()=>y.ruleChange$.pipe(ae.debounceTime(16)),[]),k=b.useObservable(L),B=b.useEvent(n);R.useEffect(()=>{(async()=>{await new Promise(_=>{setTimeout(()=>_(!0),100)});const V=y.getRuleById(r,a,d),x=V==null?void 0:V.formula1;if(o.isFormulaString(x)&&m&&V){const _=await m.getListAsync(V,r,a);j(_)}})()},[y,k,m,d,a,r]),R.useEffect(()=>{o.isFormulaString(l)&&l!==v&&(S(l),A(v))},[v,l]);const[K,J]=R.useState(()=>{const V=h!=="1"?C.deserializeListOptions(l):[],x=c.split(",");return V.map((_,N)=>({label:_,color:x[N]||ve,isRef:!1,id:o.generateRandomId(4)}))}),ne=(V,x,_)=>{const N=K.find(z=>z.id===V);N&&(N.label=x,N.color=_,J([...K]))},Z=V=>{const x=K.findIndex(_=>_.id===V);x!==-1&&(K.splice(x,1),J([...K]))},re=c.split(","),ie=R.useMemo(()=>E.map((V,x)=>({label:V,color:re[x]||ve,id:`${x}`,isRef:!0})),[re,E]),he=(V,x,_)=>{const N=[...D];N[+V]=_,I(N),B({formula1:l,formula2:N.join(",")})},pe=()=>{J([...K,{label:"",color:ve,isRef:!1,id:o.generateRandomId(4)}])};R.useEffect(()=>{if(h==="1")return;const V=new Set,x=[];K.map(_=>({labelList:_.label.split(","),item:_})).forEach(({item:_,labelList:N})=>{N.forEach(z=>{V.has(z)||(V.add(z),x.push({label:z,color:_.color}))})}),B({formula1:C.serializeListOptions(x.map(_=>_.label)),formula2:x.map(_=>_.color===ve?"":_.color).join(",")})},[K,B,h,v,D]);const ee=b.useEvent(async V=>{if(!o.isFormulaString(V)){B==null||B({formula1:"",formula2:c});return}f.getFormulaRefCheck(V)?(B==null||B({formula1:o.isFormulaString(V)?V:"",formula2:c}),F("")):(B==null||B({formula1:"",formula2:c}),S("="),F(T.t("dataValidation.validFail.formulaError")))}),q=R.useRef(null),[ce,Q]=R.useState(!1);return b.useSidebarClick(V=>{var _;((_=q.current)==null?void 0:_.isClickOutSide(V))&&Q(!1)}),p.jsxs(p.Fragment,{children:[p.jsx(M.FormLayout,{label:T.t("dataValidation.list.options"),children:p.jsxs(M.RadioGroup,{value:h,onChange:V=>{g(V),S(v),V==="1"&&B({formula1:v==="="?"":v,formula2:D.join(",")})},children:[p.jsx(M.Radio,{value:"0",children:T.t("dataValidation.list.customOptions")}),p.jsx(M.Radio,{value:"1",children:T.t("dataValidation.list.refOptions")})]})}),h==="1"?p.jsxs(M.FormLayout,{error:H||$||void 0,children:[p.jsx(Xe.FormulaEditor,{ref:q,className:M.clsx("univer-box-border univer-h-8 univer-w-full univer-cursor-pointer univer-items-center univer-rounded-lg univer-bg-white univer-pt-2 univer-transition-colors hover:univer-border-primary-600 dark:!univer-bg-gray-700 dark:!univer-text-white [&>div:first-child]:univer-px-2.5 [&>div]:univer-h-5 [&>div]:univer-ring-transparent",M.borderClassName),initValue:u,unitId:r,subUnitId:a,isFocus:ce,isSupportAcrossSheet:!0,onFocus:()=>Q(!0),onChange:(V="")=>{const x=(V!=null?V:"").trim();A(x),ee(x)}}),ie.length>0&&p.jsx("div",{className:"univer-mt-3",children:ie.map(V=>p.jsx(Et,{className:"univer-mb-3",item:V,commonProps:{onItemChange:he}},V.id))})]}):p.jsx(M.FormLayout,{error:H,children:p.jsxs("div",{className:"-univer-mt-3",children:[p.jsx(M.DraggableList,{list:K,onListChange:J,rowHeight:28,margin:[0,12],draggableHandle:".draggableHandle",itemRender:V=>p.jsx(Et,{item:V,commonProps:{onItemChange:ne,onItemDelete:Z}},V.id),idKey:"id"}),p.jsxs("a",{className:"univer-text-primary univer-flex univer-w-fit univer-cursor-pointer univer-flex-row univer-items-center univer-rounded univer-p-1 univer-px-2 univer-text-sm hover:univer-bg-primary-50 dark:hover:!univer-bg-gray-800",onClick:pe,children:[p.jsx(yt,{className:"univer-mr-1"}),T.t("dataValidation.list.add")]})]})})]})}const Dn=[[C.CUSTOM_FORMULA_INPUT_NAME,In],[C.BASE_FORMULA_INPUT_NAME,Sn],[C.LIST_FORMULA_INPUT_NAME,wn],[C.CHECKBOX_FORMULA_INPUT_NAME,_n]],En="LIST_RENDER_MODE_OPTION_INPUT";function Ne(e){var a;const{value:t,onChange:n}=e,r=b.useDependency(o.LocaleService);return p.jsx(M.FormLayout,{label:r.t("dataValidation.renderMode.label"),children:p.jsxs(M.RadioGroup,{value:`${(a=t.renderMode)!=null?a:o.DataValidationRenderMode.CUSTOM}`,onChange:i=>n({...t,renderMode:+i}),children:[p.jsx(M.Radio,{value:`${o.DataValidationRenderMode.CUSTOM}`,children:r.t("dataValidation.renderMode.chip")}),p.jsx(M.Radio,{value:`${o.DataValidationRenderMode.ARROW}`,children:r.t("dataValidation.renderMode.arrow")}),p.jsx(M.Radio,{value:`${o.DataValidationRenderMode.TEXT}`,children:r.t("dataValidation.renderMode.text")})]})})}Ne.componentKey=En;const Mn="DATE_SHOW_TIME_OPTION";function je(e){var a;const{value:t,onChange:n}=e,r=b.useDependency(o.LocaleService);return p.jsx(M.FormLayout,{children:p.jsx(M.Checkbox,{checked:(a=t.bizInfo)==null?void 0:a.showTime,onChange:i=>{n({...t,bizInfo:{...t.bizInfo,showTime:i}})},children:r.t("dataValidation.showTime.label")})})}je.componentKey=Mn;var bn=Object.getOwnPropertyDescriptor,Tn=(e,t,n,r)=>{for(var a=r>1?void 0:r?bn(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},be=(e,t)=>(n,r)=>t(n,r,e);const Be=6;let tt=class{constructor(e,t,n,r,a,i){this._commandService=e,this._univerInstanceService=t,this._formulaService=n,this._themeService=r,this._renderManagerService=a,this._dataValidationModel=i}_calc(e,t){var c,h,g;const{vt:n,ht:r}=t||{},a=e.endX-e.startX-Be*2,i=e.endY-e.startY,s=((c=t==null?void 0:t.fs)!=null?c:10)*1.6;let d=0,l=0;switch(n){case o.VerticalAlign.TOP:l=0;break;case o.VerticalAlign.BOTTOM:l=0+(i-s);break;default:l=0+(i-s)/2;break}switch(r){case o.HorizontalAlign.LEFT:d=Be;break;case o.HorizontalAlign.RIGHT:d=Be+(a-s);break;default:d=Be+(a-s)/2;break}return{left:e.startX+d,top:e.startY+l,width:((h=t==null?void 0:t.fs)!=null?h:10)*1.6,height:((g=t==null?void 0:t.fs)!=null?g:10)*1.6}}calcCellAutoHeight(e){var n;const{style:t}=e;return((n=t==null?void 0:t.fs)!=null?n:10)*1.6}calcCellAutoWidth(e){var n;const{style:t}=e;return((n=t==null?void 0:t.fs)!=null?n:10)*1.6}async _parseFormula(e,t,n){var c,h,g,u,S,v,A,T,w;const{formula1:r=C.CHECKBOX_FORMULA_1,formula2:a=C.CHECKBOX_FORMULA_2}=e,i=await this._formulaService.getRuleFormulaResult(t,n,e.uid),s=C.getFormulaResult((g=(h=(c=i==null?void 0:i[0])==null?void 0:c.result)==null?void 0:h[0])==null?void 0:g[0]),d=C.getFormulaResult((v=(S=(u=i==null?void 0:i[1])==null?void 0:u.result)==null?void 0:S[0])==null?void 0:v[0]),l=C.isLegalFormulaResult(String(s))&&C.isLegalFormulaResult(String(d));return{formula1:o.isFormulaString(r)?C.getFormulaResult((w=(T=(A=i==null?void 0:i[0])==null?void 0:A.result)==null?void 0:T[0])==null?void 0:w[0]):r,formula2:o.isFormulaString(a)?d:a,isFormulaValid:l}}drawWith(e,t){var H,L,k,B;const{style:n,primaryWithCoord:r,unitId:a,subUnitId:i,worksheet:s,row:d,col:l}=t,c=r.isMergedMainCell?r.mergeInfo:r,h=C.getCellValueOrigin(s.getCellRaw(d,l)),g=this._dataValidationModel.getRuleByLocation(a,i,d,l);if(!g)return;const u=this._dataValidationModel.getValidator(g.type);if(!u||!((H=u.skipDefaultFontRender)!=null&&H.call(u,g,h,{unitId:a,subUnitId:i,row:d,column:l})))return;const S=u.parseFormulaSync(g,a,i),{formula1:v}=S,A=this._calc(c,n),{a:T,d:w}=e.getTransform(),y=O.fixLineWidthByScale(A.left,T),f=O.fixLineWidthByScale(A.top,w),D=O.Transform.create().composeMatrix({left:y,top:f,scaleX:1,scaleY:1,angle:0,skewX:0,skewY:0,flipX:!1,flipY:!1}),I=c.endX-c.startX,m=c.endY-c.startY;e.save(),e.beginPath(),e.rect(c.startX,c.startY,I,m),e.clip();const E=D.getMatrix();e.transform(E[0],E[1],E[2],E[3],E[4],E[5]);const j=((L=n==null?void 0:n.fs)!=null?L:10)*1.6,$=String(h)===String(v),F=this._themeService.getColorFromTheme("primary.600");O.CheckboxShape.drawWith(e,{checked:$,width:j,height:j,fill:(B=(k=n==null?void 0:n.cl)==null?void 0:k.rgb)!=null?B:F}),e.restore()}isHit(e,t){const n=t.primaryWithCoord.isMergedMainCell?t.primaryWithCoord.mergeInfo:t.primaryWithCoord,r=this._calc(n,t.style),a=r.top,i=r.top+r.height,s=r.left,d=r.left+r.width,{x:l,y:c}=e;return l<=d&&l>=s&&c<=i&&c>=a}async onPointerDown(e,t){var v;if(t.button===2)return;const{primaryWithCoord:n,unitId:r,subUnitId:a,worksheet:i,row:s,col:d}=e,l=C.getCellValueOrigin(i.getCellRaw(s,d)),c=this._dataValidationModel.getRuleByLocation(r,a,s,d);if(!c)return;const h=this._dataValidationModel.getValidator(c.type);if(!h||!((v=h.skipDefaultFontRender)!=null&&v.call(h,c,l,{unitId:r,subUnitId:a,row:s,column:d})))return;const{formula1:g,formula2:u}=await this._parseFormula(c,r,a),S={range:{startColumn:n.actualColumn,endColumn:n.actualColumn,startRow:n.actualRow,endRow:n.actualRow},value:{v:String(l)===C.transformCheckboxValue(String(g))?u:g,p:null}};this._commandService.executeCommand(Y.SetRangeValuesCommand.id,S)}onPointerEnter(e,t){var n,r;(r=(n=O.getCurrentTypeOfRenderer(o.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.mainComponent)==null||r.setCursor(O.CURSOR_TYPE.POINTER)}onPointerLeave(e,t){var n,r;(r=(n=O.getCurrentTypeOfRenderer(o.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.mainComponent)==null||r.setCursor(O.CURSOR_TYPE.DEFAULT)}};tt=Tn([be(0,o.ICommandService),be(1,o.IUniverInstanceService),be(2,o.Inject(C.DataValidationFormulaService)),be(3,o.Inject(o.ThemeService)),be(4,o.Inject(O.IRenderManagerService)),be(5,o.Inject(C.SheetDataValidationModel))],tt);var Vn=Object.getOwnPropertyDescriptor,Rn=(e,t,n,r)=>{for(var a=r>1?void 0:r?Vn(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},On=(e,t)=>(n,r)=>t(n,r,e);U.BaseSheetDataValidatorView=class{constructor(t){P(this,"canvasRender",null);P(this,"dropdownType");P(this,"optionsInput");P(this,"formulaInput",C.LIST_FORMULA_INPUT_NAME);this.injector=t}},U.BaseSheetDataValidatorView=Rn([On(0,o.Inject(o.Injector))],U.BaseSheetDataValidatorView);class An extends U.BaseSheetDataValidatorView{constructor(){super(...arguments);P(this,"id",o.DataValidationType.CHECKBOX);P(this,"canvasRender",this.injector.createInstance(tt));P(this,"formulaInput",C.CHECKBOX_FORMULA_INPUT_NAME)}}class Ln extends U.BaseSheetDataValidatorView{constructor(){super(...arguments);P(this,"id",o.DataValidationType.CUSTOM);P(this,"formulaInput",C.CUSTOM_FORMULA_INPUT_NAME)}}const Pn="data-validation.formula-input";class Un extends U.BaseSheetDataValidatorView{constructor(){super(...arguments);P(this,"id",o.DataValidationType.DATE);P(this,"formulaInput",Pn);P(this,"optionsInput",je.componentKey);P(this,"dropdownType",X.DataValidatorDropdownType.DATE)}}class Fn extends U.BaseSheetDataValidatorView{constructor(){super(...arguments);P(this,"id",o.DataValidationType.DECIMAL);P(this,"formulaInput",C.BASE_FORMULA_INPUT_NAME)}}const Mt=4,kn=0,nt=4,bt=4,rt=6,We=6,_e=14;function Nn(e,t){const n=O.FontCache.getTextSize(e,t),r=n.width+Mt*2,{ba:a,bd:i}=n,s=a+i;return{width:r,height:s+kn*2,ba:a}}function at(e,t,n,r){const a=_e+rt*2,i=n-a,s=r-We*2,d=e.map(u=>({layout:Nn(u,t),text:u}));let l;const c=[];d.forEach(u=>{const{layout:S}=u,{width:v,height:A}=S;!l||l.width+v+nt>i?(l={width:v,height:A,items:[{...u,left:0}]},c.push(l)):(l.items.push({...u,left:l.width+nt}),l.width=l.width+v+nt)});let h=0,g=0;return c.forEach((u,S)=>{g=Math.max(g,u.width),S===c.length-1?h+=u.height:h+=u.height+bt}),{lines:c,totalHeight:h,contentWidth:i,contentHeight:s,cellAutoHeight:h+We*2,calcAutoWidth:g+a}}const jn=8;class Bn extends O.Shape{static drawWith(t,n){const{fontString:r,info:a,fill:i,color:s}=n,{layout:d,text:l}=a;t.save(),O.Rect.drawWith(t,{width:d.width,height:d.height,radius:jn,fill:i||ve}),t.translateWithPrecision(Mt,d.ba),t.font=r,t.fillStyle=s,t.fillText(l,0,0),t.restore()}}var Wn=Object.getOwnPropertyDescriptor,$n=(e,t,n,r)=>{for(var a=r>1?void 0:r?Wn(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},$e=(e,t)=>(n,r)=>t(n,r,e);const Hn=new Path2D("M3.32201 4.84556C3.14417 5.05148 2.85583 5.05148 2.67799 4.84556L0.134292 1.90016C-0.152586 1.56798 0.0505937 1 0.456301 1L5.5437 1C5.94941 1 6.15259 1.56798 5.86571 1.90016L3.32201 4.84556Z");let it=class{constructor(e,t,n,r){P(this,"zIndex");P(this,"_dropdownInfoMap",new Map);this._commandService=e,this._univerInstanceService=t,this._renderManagerService=n,this._dataValidationModel=r}_ensureMap(e){let t=this._dropdownInfoMap.get(e);return t||(t=new Map,this._dropdownInfoMap.set(e,t)),t}_generateKey(e,t){return`${e}.${t}`}_drawDownIcon(e,t,n,r,a){const i=n-_e+4;let s=4;switch(a){case o.VerticalAlign.MIDDLE:s=(r-_e)/2+4;break;case o.VerticalAlign.BOTTOM:s=r-_e+4;break}e.save(),e.translateWithPrecision(t.startX+i,t.startY+s),e.fillStyle="#565656",e.fill(Hn),e.restore()}drawWith(e,t,n,r){var ie,he;const{primaryWithCoord:a,row:i,col:s,style:d,data:l,subUnitId:c}=t,h=a.isMergedMainCell?a.mergeInfo:a,g=l==null?void 0:l.fontRenderExtension,{leftOffset:u=0,rightOffset:S=0,topOffset:v=0,downOffset:A=0}=g||{},T=this._ensureMap(c),w=this._generateKey(i,s),y=a.isMergedMainCell?a.mergeInfo.startRow:i,f=a.isMergedMainCell?a.mergeInfo.startColumn:s,D=this._dataValidationModel.getRuleByLocation(t.unitId,t.subUnitId,y,f);if(!D)return;const I=this._dataValidationModel.getValidator(D.type);if(!I)return;const m={startX:h.startX+u,endX:h.endX-S,startY:h.startY+v,endY:h.endY-A},E=m.endX-m.startX,j=m.endY-m.startY,{cl:$}=d||{},F=(ie=typeof $=="object"?$==null?void 0:$.rgb:$)!=null?ie:"#000",H=O.getFontStyleString(d!=null?d:void 0),{vt:L,ht:k}=d||{},B=L!=null?L:o.VerticalAlign.MIDDLE,K=(he=C.getCellValueOrigin(l))!=null?he:"",J=I.parseCellValue(K),ne=I.getListWithColorMap(D),Z=at(J,H,E,j);this._drawDownIcon(e,m,E,j,B),e.save(),e.translateWithPrecision(m.startX,m.startY),e.beginPath(),e.rect(0,0,E-_e,j),e.clip(),e.translateWithPrecision(rt,We);let re=0;switch(B){case o.VerticalAlign.MIDDLE:re=(Z.contentHeight-Z.totalHeight)/2;break;case o.VerticalAlign.BOTTOM:re=Z.contentHeight-Z.totalHeight;break}e.translateWithPrecision(0,re),Z.lines.forEach((pe,ee)=>{e.save();const{width:q,height:ce,items:Q}=pe;let V=0;switch(k){case o.HorizontalAlign.RIGHT:V=Z.contentWidth-q;break;case o.HorizontalAlign.CENTER:V=(Z.contentWidth-q)/2;break}e.translate(V,ee*(ce+bt)),Q.forEach(x=>{e.save(),e.translateWithPrecision(x.left,0),Bn.drawWith(e,{...H,info:x,color:F,fill:ne[x.text]}),e.restore()}),e.restore()}),e.restore(),T.set(w,{left:m.startX,top:m.startY,width:Z.contentWidth+rt+_e,height:Z.contentHeight+We*2})}calcCellAutoHeight(e){var I;const{primaryWithCoord:t,style:n,data:r,row:a,col:i}=e,s=r==null?void 0:r.fontRenderExtension,{leftOffset:d=0,rightOffset:l=0,topOffset:c=0,downOffset:h=0}=s||{},g=t.isMergedMainCell?t.mergeInfo:t,u={startX:g.startX+d,endX:g.endX-l,startY:g.startY+c,endY:g.endY-h},S=this._dataValidationModel.getRuleByLocation(e.unitId,e.subUnitId,a,i);if(!S)return;const v=this._dataValidationModel.getValidator(S.type);if(!v)return;const A=u.endX-u.startX,T=u.endY-u.startY,w=(I=C.getCellValueOrigin(r))!=null?I:"",y=v.parseCellValue(w),f=O.getFontStyleString(n!=null?n:void 0);return at(y,f,A,T).cellAutoHeight}calcCellAutoWidth(e){var I;const{primaryWithCoord:t,style:n,data:r,row:a,col:i}=e,s=r==null?void 0:r.fontRenderExtension,{leftOffset:d=0,rightOffset:l=0,topOffset:c=0,downOffset:h=0}=s||{},g=t.isMergedMainCell?t.mergeInfo:t,u={startX:g.startX+d,endX:g.endX-l,startY:g.startY+c,endY:g.endY-h},S=this._dataValidationModel.getRuleByLocation(e.unitId,e.subUnitId,a,i);if(!S)return;const v=this._dataValidationModel.getValidator(S.type);if(!v)return;const A=u.endX-u.startX,T=u.endY-u.startY,w=(I=C.getCellValueOrigin(r))!=null?I:"",y=v.parseCellValue(w),f=O.getFontStyleString(n!=null?n:void 0);return at(y,f,A,T).calcAutoWidth}isHit(e,t){const{primaryWithCoord:n}=t,r=n.isMergedMainCell?n.mergeInfo:n,{endX:a}=r,{x:i}=e;return i>=a-_e&&i<=a}onPointerDown(e,t){if(t.button===2)return;const{unitId:n,subUnitId:r,row:a,col:i}=e,s={unitId:n,subUnitId:r,row:a,column:i};this._commandService.executeCommand(Ue.id,s)}onPointerEnter(e,t){var n,r;return(r=(n=O.getCurrentTypeOfRenderer(o.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.mainComponent)==null?void 0:r.setCursor(O.CURSOR_TYPE.POINTER)}onPointerLeave(e,t){var n,r;return(r=(n=O.getCurrentTypeOfRenderer(o.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.mainComponent)==null?void 0:r.setCursor(O.CURSOR_TYPE.DEFAULT)}};it=$n([$e(0,o.ICommandService),$e(1,o.IUniverInstanceService),$e(2,o.Inject(O.IRenderManagerService)),$e(3,o.Inject(C.SheetDataValidationModel))],it);class xn extends U.BaseSheetDataValidatorView{constructor(){super(...arguments);P(this,"id",o.DataValidationType.LIST_MULTIPLE);P(this,"canvasRender",this.injector.createInstance(it));P(this,"dropdownType",X.DataValidatorDropdownType.MULTIPLE_LIST)}}var Yn=Object.getOwnPropertyDescriptor,Xn=(e,t,n,r)=>{for(var a=r>1?void 0:r?Yn(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},Ae=(e,t)=>(n,r)=>t(n,r,e);const Te=4,He=4,se=14,ot=1,ue=6,Ve=3,st=8,zn="#565656",Tt=new Path2D("M3.32201 4.84556C3.14417 5.05148 2.85583 5.05148 2.67799 4.84556L0.134292 1.90016C-0.152586 1.56798 0.0505937 1 0.456301 1L5.5437 1C5.94941 1 6.15259 1.56798 5.86571 1.90016L3.32201 4.84556Z");function Vt(e,t,n,r,a,i,s=!0){let d=0;const l=s?Ve:0;switch(a){case o.VerticalAlign.BOTTOM:d=t-r-l;break;case o.VerticalAlign.MIDDLE:d=(t-r)/2;break;default:d=l;break}d=Math.max(Ve,d);let c=0;switch(i){case o.HorizontalAlign.CENTER:c=(e-n)/2;break;case o.HorizontalAlign.RIGHT:c=e-n;break}return c=Math.max(ue,c),{paddingLeft:c,paddingTop:d}}let lt=class{constructor(e,t,n,r,a){P(this,"_dropdownInfoMap",new Map);P(this,"zIndex");this._univerInstanceService=e,this._localeService=t,this._commandService=n,this._renderManagerService=r,this._dataValidationModel=a}_ensureMap(e){let t=this._dropdownInfoMap.get(e);return t||(t=new Map,this._dropdownInfoMap.set(e,t)),t}_generateKey(e,t){return`${e}.${t}`}_drawDownIcon(e,t,n,r,a,i,s){const{t:d=o.DEFAULT_STYLES.pd.t,b:l=o.DEFAULT_STYLES.pd.b}=s,c=n-se;let h;switch(i){case o.VerticalAlign.MIDDLE:h=(r-He)/2;break;case o.VerticalAlign.BOTTOM:h=r-l-a-Ve+(a/2-He/2);break;default:h=d+Ve+(a/2-He/2);break}e.save(),e.translateWithPrecision(t.startX+c,t.startY+h),e.fillStyle="#565656",e.fill(Tt),e.restore()}drawWith(e,t,n){var ne,Z,re,ie,he,pe;const{primaryWithCoord:r,row:a,col:i,style:s,data:d,subUnitId:l}=t,c=r.isMergedMainCell?r.mergeInfo:r,h=r.isMergedMainCell?r.mergeInfo.startRow:a,g=r.isMergedMainCell?r.mergeInfo.startColumn:i,u=this._dataValidationModel.getRuleByLocation(t.unitId,t.subUnitId,h,g);if(!u)return;const S=this._dataValidationModel.getValidator(u.type);if(!S)return;const v=d==null?void 0:d.fontRenderExtension,{leftOffset:A=0,rightOffset:T=0,topOffset:w=0,downOffset:y=0}=v||{};if(!u||!S||!S||S.id.indexOf(o.DataValidationType.LIST)!==0||!S.skipDefaultFontRender(u))return;const f={startX:c.startX+A,endX:c.endX-T,startY:c.startY+w,endY:c.endY-y},D=f.endX-f.startX,I=f.endY-f.startY,m=this._ensureMap(l),E=this._generateKey(a,i),j=S.getListWithColorMap(u),$=C.getCellValueOrigin(d),F=`${$!=null?$:""}`,H=j[F];let{tb:L,vt:k,ht:B,pd:K}=s||{};L=L!=null?L:o.WrapStrategy.WRAP,k=k!=null?k:o.VerticalAlign.BOTTOM,B=B!=null?B:o.DEFAULT_STYLES.ht,K=K!=null?K:o.DEFAULT_STYLES.pd;const J=O.getFontStyleString(s).fontCache;if(u.renderMode===o.DataValidationRenderMode.ARROW){const{l:ee=o.DEFAULT_STYLES.pd.l,t:q=o.DEFAULT_STYLES.pd.t,r:ce=o.DEFAULT_STYLES.pd.r,b:Q=o.DEFAULT_STYLES.pd.b}=K,V=D-ee-ce-se-4,x=new O.DocSimpleSkeleton(F,J,L===o.WrapStrategy.WRAP,V,1/0);x.calculate();const _=x.getTotalWidth(),N=x.getTotalHeight(),{paddingTop:z,paddingLeft:le}=Vt(V,I-q-Q,_,N,k,B,!0);this._drawDownIcon(e,f,D,I,N,k,K),e.save(),e.translateWithPrecision(f.startX+ee,f.startY+q),e.beginPath(),e.rect(0,0,D-ee-ce,I-q-Q),e.clip(),e.translateWithPrecision(0,z),e.save(),e.translateWithPrecision(le,0),e.beginPath(),e.rect(0,0,V,N),e.clip(),O.Text.drawWith(e,{text:F,fontStyle:J,width:V,height:N,color:(ne=s==null?void 0:s.cl)==null?void 0:ne.rgb,strokeLine:!!((Z=s==null?void 0:s.st)!=null&&Z.s),underline:!!((re=s==null?void 0:s.ul)!=null&&re.s),warp:L===o.WrapStrategy.WRAP,hAlign:o.HorizontalAlign.LEFT},x),e.restore(),e.restore(),m.set(E,{left:f.endX-se+n.rowHeaderWidth,top:f.startY+q+n.columnHeaderHeight,width:se,height:I-q-Q})}else{e.save(),e.translateWithPrecision(f.startX,f.startY),e.beginPath(),e.rect(0,0,D,I),e.clip();const ee=D-ue*2-Te-se-4,q=new O.DocSimpleSkeleton(F,J,L===o.WrapStrategy.WRAP,ee,1/0);q.calculate();const ce=q.getTotalWidth(),Q=q.getTotalHeight(),V=Q+ot*2,x=Math.max(D-ue*2,1),{paddingTop:_}=Vt(x,I,ce,V,k,B);e.translateWithPrecision(ue,_),O.Rect.drawWith(e,{width:x,height:V,fill:H||ve,radius:st}),e.save(),e.translateWithPrecision(Te,ot),e.beginPath(),e.rect(0,0,ee,Q),e.clip(),O.Text.drawWith(e,{text:F,fontStyle:J,width:ee,height:Q,color:(ie=s==null?void 0:s.cl)==null?void 0:ie.rgb,strokeLine:!!((he=s==null?void 0:s.st)!=null&&he.s),underline:!!((pe=s==null?void 0:s.ul)!=null&&pe.s),warp:L===o.WrapStrategy.WRAP,hAlign:o.HorizontalAlign.LEFT},q),e.restore(),e.translateWithPrecision(ee+Te+4,(Q-He)/2),e.fillStyle=zn,e.fill(Tt),e.restore(),m.set(E,{left:f.startX+ue+n.rowHeaderWidth,top:f.startY+_+n.columnHeaderHeight,width:x,height:V})}}calcCellAutoHeight(e){const{primaryWithCoord:t,style:n,data:r,row:a,col:i}=e,s=t.isMergedMainCell?t.mergeInfo:t,d=r==null?void 0:r.fontRenderExtension,{leftOffset:l=0,rightOffset:c=0,topOffset:h=0,downOffset:g=0}=d||{},u=this._dataValidationModel.getRuleByLocation(e.unitId,e.subUnitId,a,i);if(!u||u.renderMode===o.DataValidationRenderMode.TEXT)return;const S={startX:s.startX+l,endX:s.endX-c,startY:s.startY+h,endY:s.endY-g},v=S.endX-S.startX,A=C.getCellValueOrigin(r),T=`${A!=null?A:""}`;let{tb:w,pd:y}=n||{};const{t:f=o.DEFAULT_STYLES.pd.t,b:D=o.DEFAULT_STYLES.pd.b}=y!=null?y:{};if(w=w!=null?w:o.WrapStrategy.WRAP,u.renderMode===o.DataValidationRenderMode.ARROW){const{l:I=o.DEFAULT_STYLES.pd.l,r:m=o.DEFAULT_STYLES.pd.r}=y!=null?y:{},E=v-I-m-se-4,j=new O.DocSimpleSkeleton(T,O.getFontStyleString(n).fontCache,w===o.WrapStrategy.WRAP,E,1/0);return j.calculate(),j.getTotalHeight()+f+D+Ve*2}else{const I=Math.max(v-ue*2-Te-se-4,10),m=new O.DocSimpleSkeleton(T,O.getFontStyleString(n).fontCache,w===o.WrapStrategy.WRAP,I,1/0);return m.calculate(),m.getTotalHeight()+Ve*2+ot*2}}calcCellAutoWidth(e){const{primaryWithCoord:t,style:n,data:r,row:a,col:i}=e,s=t.isMergedMainCell?t.mergeInfo:t,d=r==null?void 0:r.fontRenderExtension,{leftOffset:l=0,rightOffset:c=0,topOffset:h=0,downOffset:g=0}=d||{},u=this._dataValidationModel.getRuleByLocation(e.unitId,e.subUnitId,a,i);if(!u||u.renderMode===o.DataValidationRenderMode.TEXT)return;const S={startX:s.startX+l,endX:s.endX-c,startY:s.startY+h,endY:s.endY-g},v=S.endX-S.startX,A=C.getCellValueOrigin(r),T=`${A!=null?A:""}`;let{tb:w,pd:y}=n||{};const{l:f=o.DEFAULT_STYLES.pd.l,r:D=o.DEFAULT_STYLES.pd.r}=y!=null?y:{};w=w!=null?w:o.WrapStrategy.WRAP;let I=ue*2+se;switch(u.renderMode){case o.DataValidationRenderMode.ARROW:I=se+4+D+f;break;case o.DataValidationRenderMode.CUSTOM:I=se+ue*2+Te*2+D+f+st/2+1;break;default:I=se+ue*2+Te*2+D+f+st/2+1}const m=v-I,E=new O.DocSimpleSkeleton(T,O.getFontStyleString(n).fontCache,w===o.WrapStrategy.WRAP,m,1/0);return E.calculate(),E.getTotalWidth()+I}isHit(e,t){const{subUnitId:n,row:r,col:a}=t,s=this._ensureMap(n).get(this._generateKey(r,a)),d=this._dataValidationModel.getRuleByLocation(t.unitId,t.subUnitId,r,a);if(!d||!s||d.renderMode===o.DataValidationRenderMode.TEXT)return!1;const{top:l,left:c,width:h,height:g}=s,{x:u,y:S}=e;return u>=c&&u<=c+h&&S>=l&&S<=l+g}onPointerDown(e,t){if(t.button===2)return;const{unitId:n,subUnitId:r,row:a,col:i}=e,s={unitId:n,subUnitId:r,row:a,column:i};this._commandService.executeCommand(Ue.id,s)}onPointerEnter(e,t){var n,r;(r=(n=O.getCurrentTypeOfRenderer(o.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.mainComponent)==null||r.setCursor(O.CURSOR_TYPE.POINTER)}onPointerLeave(e,t){var n,r;(r=(n=O.getCurrentTypeOfRenderer(o.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.mainComponent)==null||r.setCursor(O.CURSOR_TYPE.DEFAULT)}};lt=Xn([Ae(0,o.IUniverInstanceService),Ae(1,o.Inject(o.LocaleService)),Ae(2,o.ICommandService),Ae(3,o.Inject(O.IRenderManagerService)),Ae(4,o.Inject(C.SheetDataValidationModel))],lt);class Kn extends U.BaseSheetDataValidatorView{constructor(){super(...arguments);P(this,"id",o.DataValidationType.LIST);P(this,"canvasRender",this.injector.createInstance(lt));P(this,"dropdownType",X.DataValidatorDropdownType.LIST);P(this,"optionsInput",Ne.componentKey);P(this,"formulaInput",C.LIST_FORMULA_INPUT_NAME)}}class Zn extends U.BaseSheetDataValidatorView{constructor(){super(...arguments);P(this,"id",o.DataValidationType.TEXT_LENGTH);P(this,"formulaInput",C.BASE_FORMULA_INPUT_NAME)}}class Gn extends U.BaseSheetDataValidatorView{constructor(){super(...arguments);P(this,"id",o.DataValidationType.WHOLE);P(this,"formulaInput",C.BASE_FORMULA_INPUT_NAME)}}var qn=Object.getOwnPropertyDescriptor,Jn=(e,t,n,r)=>{for(var a=r>1?void 0:r?qn(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},dt=(e,t)=>(n,r)=>t(n,r,e);let Re=class extends o.RxDisposable{constructor(e,t,n){super(),this._injector=e,this._componentManger=t,this._dataValidatorRegistryService=n,this._initComponents(),this._registerValidatorViews()}_initComponents(){[["DataValidationIcon",Ct],[Pe,mn],[Ne.componentKey,Ne],[je.componentKey,je],...Dn].forEach(([e,t])=>{this.disposeWithMe(this._componentManger.register(e,t))})}_registerValidatorViews(){[Fn,Gn,Zn,Un,An,Kn,xn,Ln].forEach(e=>{const t=this._injector.createInstance(e),n=this._dataValidatorRegistryService.getValidatorItem(t.id);n&&(n.formulaInput=t.formulaInput,n.canvasRender=t.canvasRender,n.dropdownType=t.dropdownType,n.optionsInput=t.optionsInput)})}};Re=Jn([dt(0,o.Inject(o.Injector)),dt(1,o.Inject(b.ComponentManager)),dt(2,o.Inject(X.DataValidatorRegistryService))],Re);var Qn=Object.getOwnPropertyDescriptor,er=(e,t,n,r)=>{for(var a=r>1?void 0:r?Qn(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},ct=(e,t)=>(n,r)=>t(n,r,e);const tr="SHEET_DATA_VALIDATION_UI_PLUGIN";U.UniverSheetsDataValidationMobileUIPlugin=(xe=class extends o.Plugin{constructor(t=Le,n,r,a){super(),this._config=t,this._injector=n,this._commandService=r,this._configService=a;const{menu:i,...s}=o.merge({},Le,this._config);i&&this._configService.setConfig("menu",i,{merge:!0}),this._configService.setConfig(ze,s)}onStarting(){[[de],[ge],[Oe],[we],[Me],[Ee],[De],[Re]].forEach(t=>{this._injector.add(t)}),[Fe,Ue,vt,Ze,fe,pt].forEach(t=>{this._commandService.registerCommand(t)})}onReady(){this._injector.get(De),this._injector.get(Ee),this._injector.get(O.IRenderManagerService).registerRenderModule(o.UniverInstanceType.UNIVER_SHEET,[ke])}onRendered(){this._injector.get(Re),this._injector.get(Me)}onSteady(){this._injector.get(we)}},P(xe,"pluginName",tr),P(xe,"type",o.UniverInstanceType.UNIVER_SHEET),xe),U.UniverSheetsDataValidationMobileUIPlugin=er([ct(1,o.Inject(o.Injector)),ct(2,o.ICommandService),ct(3,o.IConfigService)],U.UniverSheetsDataValidationMobileUIPlugin);var nr=Object.defineProperty,rr=Object.getOwnPropertyDescriptor,ar=(e,t,n)=>t in e?nr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ir=(e,t,n,r)=>{for(var a=r>1?void 0:r?rr(t,n):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(a=s(a)||a);return a},ut=(e,t)=>(n,r)=>t(n,r,e),Rt=(e,t,n)=>ar(e,typeof t!="symbol"?t+"":t,n);const or="SHEET_DATA_VALIDATION_UI_PLUGIN";U.UniverSheetsDataValidationUIPlugin=class extends o.Plugin{constructor(t=Le,n,r,a){super(),this._config=t,this._injector=n,this._commandService=r,this._configService=a;const{menu:i,...s}=o.merge({},Le,this._config);i&&this._configService.setConfig("menu",i,{merge:!0}),this._configService.setConfig(ze,s)}onStarting(){[[de],[ge],[Oe],[we],[Me],[Ee],[De],[Ce],[Re]].forEach(t=>{this._injector.add(t)}),[Fe,Ue,vt,Ze,fe,pt].forEach(t=>{this._commandService.registerCommand(t)})}onReady(){this._injector.get(De),this._injector.get(Ee),this._injector.get(Ce),this._injector.get(Oe),this._injector.get(O.IRenderManagerService).registerRenderModule(o.UniverInstanceType.UNIVER_SHEET,[ke])}onRendered(){this._injector.get(Re),this._injector.get(Me)}onSteady(){this._injector.get(we)}},Rt(U.UniverSheetsDataValidationUIPlugin,"pluginName",or),Rt(U.UniverSheetsDataValidationUIPlugin,"type",o.UniverInstanceType.UNIVER_SHEET),U.UniverSheetsDataValidationUIPlugin=ir([o.DependentOn(C.UniverSheetsDataValidationPlugin),ut(1,o.Inject(o.Injector)),ut(2,o.ICommandService),ut(3,o.IConfigService)],U.UniverSheetsDataValidationUIPlugin),Object.defineProperty(U,Symbol.toStringTag,{value:"Module"})}));
19
19
 
20
20
 
21
21
  // index
@@ -1,5 +1,5 @@
1
1
  // @univerjs/sheets-data-validation-ui/locale/zh-TW
2
- (function(e,a){typeof exports=="object"&&typeof module<"u"?module.exports=a():typeof define=="function"&&define.amd?define(a):(e=typeof globalThis<"u"?globalThis:e||self,e.UniverSheetsDataValidationUiZhTW=a())})(this,(function(){"use strict";return{dataValidation:{title:"資料驗證",validFail:{value:"請輸入一個合法值",common:"請輸入數值或公式",number:"請輸入合法的數字或公式",formula:"請輸入合法的公式",integer:"請輸入合法的整數或公式",date:"請輸入合法的日期或公式",list:"請輸入至少一個合法選項",listInvalid:"清單來源必須是分隔清單或單行或列的參考。 ",checkboxEqual:"為勾選和未勾選的儲存格內容輸入不同的值。 ",formulaError:"引用範圍內包含不可見的數據,請重新調整範圍",listIntersects:"所選範圍不能和規則範圍相交",primitive:"自訂勾選和未勾選值不允許使用公式。 "},panel:{title:"管理資料驗證",addTitle:"新資料驗證",removeAll:"全部刪除",add:"新建規則",range:"應用範圍",rangeError:"應用範圍不合法",type:"條件型別",options:"進階設定",operator:"資料",removeRule:"刪除規則",done:"確認",formulaPlaceholder:"請輸入數值或公式",valuePlaceholder:"請輸入值",formulaAnd:"與",invalid:"資料無效時",showWarning:"顯示警告",rejectInput:"拒絕輸入",messageInfo:"文字提示",showInfo:"顯示所選單元格的提示文字",allowBlank:"忽略空值"},operators:{between:"介於",greaterThan:"大於",greaterThanOrEqual:"大於或等於",lessThan:"小於",lessThanOrEqual:"小於或等於",equal:"等於",notEqual:"不等於",notBetween:"未介於",legal:"是合法類型"},ruleName:{between:"介於 {FORMULA1} 和 {FORMULA2} 之間",greaterThan:"大於 {FORMULA1}",greaterThanOrEqual:"大於或等於 {FORMULA1}",lessThan:"小於 {FORMULA1}",lessThanOrEqual:"小於或等於 {FORMULA1}",equal:"等於 {FORMULA1}",notEqual:"不等於 {FORMULA1}",notBetween:"在 {FORMULA1} 和 {FORMULA2} 範圍之外",legal:"是一個合法的 {TYPE}"},errorMsg:{between:"值必須介於 {FORMULA1} 和 {FORMULA2} 之間",greaterThan:"值必須大於 {FORMULA1}",greaterThanOrEqual:"值必須大於或等於 {FORMULA1}",lessThan:"值必須小於 {FORMULA1}",lessThanOrEqual:"值必須小於或等於 {FORMULA1}",equal:"值必須等於 {FORMULA1}",notEqual:"值必須不等於 {FORMULA1}",notBetween:"值必須在 {FORMULA1} 和 {FORMULA2} 範圍之外",legal:"值必須是一個合法的 {TYPE}"},any:{title:"任意值",error:"此儲存格的內容違反了驗證規則"},date:{title:"日期",operators:{between:"介於",greaterThan:"晚於",greaterThanOrEqual:"晚於或等於",lessThan:"早於",lessThanOrEqual:"早於或等於",equal:"等於",notEqual:"不等於",notBetween:"未介於",legal:"是合法日期"},ruleName:{between:"介於 {FORMULA1} 和 {FORMULA2} 之間",greaterThan:"晚於 {FORMULA1}",greaterThanOrEqual:"晚於或等於 {FORMULA1}",lessThan:"早於 {FORMULA1}",lessThanOrEqual:"早於或等於 {FORMULA1}",equal:"等於 {FORMULA1}",notEqual:"不等於 {FORMULA1}",notBetween:"在 {FORMULA1} 和 {FORMULA2} 範圍之外",legal:"是一個合法的日期"},errorMsg:{between:"日期必須介於 {FORMULA1} 和 {FORMULA2} 之間",greaterThan:"日期必須晚於 {FORMULA1}",greaterThanOrEqual:"日期必須晚於或等於 {FORMULA1}",lessThan:"日期必須早於 {FORMULA1}",lessThanOrEqual:"早於或等於 {FORMULA1}",equal:"日期必須等於 {FORMULA1}",notEqual:"日期必須不等於 {FORMULA1}",notBetween:"日期必須在 {FORMULA1} 和 {FORMULA2} 範圍之外",legal:"值必須是一個合法的日期"}},list:{title:"下拉選單",name:"值必須是列表中的值",error:"輸入必須在指定的範圍內",emptyError:"請輸入一個值",add:"新增選項",dropdown:"單選",options:"選項來源",customOptions:"自訂",refOptions:"引用資料",formulaError:"列表來源必須是劃定分界後的資料列表,或是對單一行或一列的引用。",edit:"編輯"},listMultiple:{title:"下拉式選單-多選",dropdown:"多選"},textLength:{title:"文本長度",errorMsg:{between:"文本長度必須介於 {FORMULA1} 和 {FORMULA2} 之間",greaterThan:"文本長度必須大於 {FORMULA1}",greaterThanOrEqual:"文本長度必須大於或等於 {FORMULA1}",lessThan:"文字長度必須小於 {FORMULA1}",lessThanOrEqual:"文字長度必須小於或等於 {FORMULA1}",equal:"文本長度必須等於 {FORMULA1}",notEqual:"文字長度必須不等於 {FORMULA1}",notBetween:"文本長度必須在 {FORMULA1} 和 {FORMULA2} 範圍之外"}},decimal:{title:"數字"},whole:{title:"整數"},checkbox:{title:"複選框",error:"此儲存格的內容違反了驗證規則",tips:"在儲存格內使用自訂值",checked:"選取值",unchecked:"未選取值"},custom:{title:"自訂公式",error:"此儲存格的內容違反了驗證規則",validFail:"請輸入合法的公式",ruleName:"自訂公式 {FORMULA1}"},alert:{title:"提示",ok:"確定"},error:{title:"無效:"},renderMode:{arrow:"箭頭",chip:"條狀標籤",text:"純文字",label:"顯示樣式"},showTime:{label:"展示時間選擇"}}}}));
2
+ (function(e,a){typeof exports=="object"&&typeof module<"u"?module.exports=a():typeof define=="function"&&define.amd?define(a):(e=typeof globalThis<"u"?globalThis:e||self,e.UniverSheetsDataValidationUiZhTW=a())})(this,(function(){"use strict";return{dataValidation:{title:"資料驗證",validFail:{value:"請輸入一個合法值",common:"請輸入數值或公式",number:"請輸入合法的數字或公式",formula:"請輸入合法的公式",integer:"請輸入合法的整數或公式",date:"請輸入合法的日期或公式",list:"請輸入至少一個合法選項",listInvalid:"清單來源必須是分隔清單或單列或欄的參考。 ",checkboxEqual:"為勾選和未勾選的儲存格內容輸入不同的值。 ",formulaError:"引用範圍內包含不可見的數據,請重新調整範圍",listIntersects:"所選範圍不能和規則範圍相交",primitive:"自訂勾選和未勾選值不允許使用公式。 "},panel:{title:"管理資料驗證",addTitle:"新資料驗證",removeAll:"全部刪除",add:"新建規則",range:"應用範圍",rangeError:"應用範圍不合法",type:"條件型別",options:"進階設定",operator:"資料",removeRule:"刪除規則",done:"確認",formulaPlaceholder:"請輸入數值或公式",valuePlaceholder:"請輸入值",formulaAnd:"與",invalid:"資料無效時",showWarning:"顯示警告",rejectInput:"拒絕輸入",messageInfo:"文字提示",showInfo:"顯示所選儲存格的提示文字",allowBlank:"忽略空值"},operators:{between:"介於",greaterThan:"大於",greaterThanOrEqual:"大於或等於",lessThan:"小於",lessThanOrEqual:"小於或等於",equal:"等於",notEqual:"不等於",notBetween:"未介於",legal:"是合法類型"},ruleName:{between:"介於 {FORMULA1} 和 {FORMULA2} 之間",greaterThan:"大於 {FORMULA1}",greaterThanOrEqual:"大於或等於 {FORMULA1}",lessThan:"小於 {FORMULA1}",lessThanOrEqual:"小於或等於 {FORMULA1}",equal:"等於 {FORMULA1}",notEqual:"不等於 {FORMULA1}",notBetween:"在 {FORMULA1} 和 {FORMULA2} 範圍之外",legal:"是一個合法的 {TYPE}"},errorMsg:{between:"值必須介於 {FORMULA1} 和 {FORMULA2} 之間",greaterThan:"值必須大於 {FORMULA1}",greaterThanOrEqual:"值必須大於或等於 {FORMULA1}",lessThan:"值必須小於 {FORMULA1}",lessThanOrEqual:"值必須小於或等於 {FORMULA1}",equal:"值必須等於 {FORMULA1}",notEqual:"值必須不等於 {FORMULA1}",notBetween:"值必須在 {FORMULA1} 和 {FORMULA2} 範圍之外",legal:"值必須是一個合法的 {TYPE}"},any:{title:"任意值",error:"此儲存格的內容違反了驗證規則"},date:{title:"日期",operators:{between:"介於",greaterThan:"晚於",greaterThanOrEqual:"晚於或等於",lessThan:"早於",lessThanOrEqual:"早於或等於",equal:"等於",notEqual:"不等於",notBetween:"未介於",legal:"是合法日期"},ruleName:{between:"介於 {FORMULA1} 和 {FORMULA2} 之間",greaterThan:"晚於 {FORMULA1}",greaterThanOrEqual:"晚於或等於 {FORMULA1}",lessThan:"早於 {FORMULA1}",lessThanOrEqual:"早於或等於 {FORMULA1}",equal:"等於 {FORMULA1}",notEqual:"不等於 {FORMULA1}",notBetween:"在 {FORMULA1} 和 {FORMULA2} 範圍之外",legal:"是一個合法的日期"},errorMsg:{between:"日期必須介於 {FORMULA1} 和 {FORMULA2} 之間",greaterThan:"日期必須晚於 {FORMULA1}",greaterThanOrEqual:"日期必須晚於或等於 {FORMULA1}",lessThan:"日期必須早於 {FORMULA1}",lessThanOrEqual:"早於或等於 {FORMULA1}",equal:"日期必須等於 {FORMULA1}",notEqual:"日期必須不等於 {FORMULA1}",notBetween:"日期必須在 {FORMULA1} 和 {FORMULA2} 範圍之外",legal:"值必須是一個合法的日期"}},list:{title:"下拉選單",name:"值必須是列表中的值",error:"輸入必須在指定的範圍內",emptyError:"請輸入一個值",add:"新增選項",dropdown:"單選",options:"選項來源",customOptions:"自訂",refOptions:"引用資料",formulaError:"列表來源必須是劃定分界後的資料列表,或是對單一列或欄的引用。",edit:"編輯"},listMultiple:{title:"下拉式選單-多選",dropdown:"多選"},textLength:{title:"文字長度",errorMsg:{between:"文字長度必須介於 {FORMULA1} 和 {FORMULA2} 之間",greaterThan:"文字長度必須大於 {FORMULA1}",greaterThanOrEqual:"文字長度必須大於或等於 {FORMULA1}",lessThan:"文字長度必須小於 {FORMULA1}",lessThanOrEqual:"文字長度必須小於或等於 {FORMULA1}",equal:"文字長度必須等於 {FORMULA1}",notEqual:"文字長度必須不等於 {FORMULA1}",notBetween:"文字長度必須在 {FORMULA1} 和 {FORMULA2} 範圍之外"}},decimal:{title:"數字"},whole:{title:"整數"},checkbox:{title:"複選框",error:"此儲存格的內容違反了驗證規則",tips:"在儲存格內使用自訂值",checked:"選取值",unchecked:"未選取值"},custom:{title:"自訂公式",error:"此儲存格的內容違反了驗證規則",validFail:"請輸入合法的公式",ruleName:"自訂公式 {FORMULA1}"},alert:{title:"提示",ok:"確定"},error:{title:"無效:"},renderMode:{arrow:"箭頭",chip:"條狀標籤",text:"純文字",label:"顯示樣式"},showTime:{label:"展示時間選擇"}}}}));
3
3
 
4
4
 
5
5
  // locale/zh-TW
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/preset-sheets-data-validation",
3
- "version": "0.12.3",
3
+ "version": "0.12.4-experimental.20251208-c4b8a44",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum Co., Ltd. <developer@univer.ai>",
@@ -58,17 +58,17 @@
58
58
  "rxjs": ">=7.0.0"
59
59
  },
60
60
  "dependencies": {
61
- "@univerjs/data-validation": "0.12.3",
62
- "@univerjs/sheets-data-validation": "0.12.3",
63
- "@univerjs/sheets-data-validation-ui": "0.12.3"
61
+ "@univerjs/data-validation": "0.12.4-experimental.20251208-c4b8a44",
62
+ "@univerjs/sheets-data-validation": "0.12.4-experimental.20251208-c4b8a44",
63
+ "@univerjs/sheets-data-validation-ui": "0.12.4-experimental.20251208-c4b8a44"
64
64
  },
65
65
  "devDependencies": {
66
- "@univerjs/core": "0.12.3",
66
+ "@univerjs/core": "0.12.4-experimental.20251208-c4b8a44",
67
67
  "react": "18.3.1",
68
68
  "react-dom": "18.3.1",
69
69
  "rxjs": "7.8.2",
70
70
  "typescript": "^5.9.3",
71
- "@univerjs-infra/shared": "0.12.3"
71
+ "@univerjs-infra/shared": "0.12.4"
72
72
  },
73
73
  "scripts": {
74
74
  "prebuild:preset": "tsx prepare.ts",